Major back-end changes, with front-end tweaks to keep up. 1) Data frames are now...
[openmx:openmx.git] / src / omxData.h
1 /*
2  *  Copyright 2007-2009 The OpenMx Project
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *       http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *   Unless required by applicable law or agreed to in writing, software
11  *   distributed under the License is distributed on an "AS IS" BASIS,
12  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  */
17
18 /***********************************************************
19  * 
20  *  omxData.h
21  *
22  *  Created: Timothy R. Brick   Date: 2009-07-15
23  *
24  *      Contains header information for the omxData class
25  *   omxData objects keep data objects in whatever form
26  *   they might take.
27  *
28  **********************************************************/
29
30 #ifndef _OMXDATA_H_
31 #define _OMXDATA_H_
32
33 #include "R.h"
34 #include <Rinternals.h> 
35 #include <Rdefines.h>
36 #include <R_ext/Rdynload.h> 
37 #include <R_ext/BLAS.h>
38 #include <R_ext/Lapack.h> 
39
40 typedef struct omxData omxData;
41
42 #include "omxAlgebra.h"
43 #include "omxObjective.h"
44 #include "omxState.h"
45
46 #ifdef DEBUGMX
47 #define OMX_DEBUG 1
48 #else
49 #define OMX_DEBUG 0
50 #endif /* DEBUG */
51
52 struct omxData {                                                // A matrix
53                                                                                 //TODO: Improve encapsulation
54 /* The object itself */
55         SEXP dataObject;                                        // The R object
56         SEXP* columns;                                          // An array of column SEXPs
57         omxMatrix* dataMat;                                     // The data, as an omxMatrix Object
58         omxMatrix* meansMat;                            // The means, as an omxMatrixObject
59         double numObs;                                          // Number of observations
60         char type[250];                                         // The type of data object.
61         
62         int* location;                                          // Which of the following contains the data column
63         double** realData;                                      // The actual data objects if numeric
64         int** intData;                                          // The actual data objects if ordinal
65         
66 /* Useful Members */
67         int rows, cols;                                         // Matrix size 
68
69         omxState* currentState;                         // The Current Optimizer State  // Might not want this.
70 };
71
72 /* Initialize and Destroy */
73         omxData* omxInitData();                                                                                                                 // Set up a data object
74         omxData* omxNewDataFromMxDataPtr(SEXP dataObject, omxState* state);                             // Retrieves a data object from the state
75         omxData* omxNewDataFromMxData(omxData* od, SEXP dataObject, omxState* state);   // Fills the object from a data SEXP
76         void omxFreeData(omxData* od);                                                                                                  // Release any held data.
77
78 /* Getters 'n Setters */
79         double omxDoubleDataElement(omxData *od, int row, int col);                                     // Returns one data object as a double
80         int omxIntDataElement(omxData *od, int row, int col);                                           // Returns one data object as an integer
81         omxMatrix* omxDataMatrix(omxData *od, omxMatrix* om);                                           // Populates a matrix with the data (use for covariance matrices)
82         omxMatrix* omxDataMeans(omxData *od, omxMatrix* colList, omxMatrix* om);        // Populates a matrix with data means
83         omxMatrix* omxDataRow(omxData *od, int row, omxMatrix* colList, omxMatrix* om);// Populates a matrix with a single data row
84         double omxDataNumObs(omxData *od);                                                                                      // Returns number
85         unsigned short int omxDataColumnIsFactor(omxData *od, int col);                         // Does what it says
86         char* omxDataType(omxData *od);                                                                                         // Returns the type field // TODO: Should this be an ENUM?
87
88 /* Function wrappers that switch based on inclusion of algebras */
89         void omxPrintData(omxData *source, char* d);                                                                    // Pretty-print a (hopefully small) data object
90
91 #endif /* _OMXDATA_H_ */