Changeset 374 for library/mex
- Timestamp:
- 06/11/09 17:15:06 (16 years ago)
- Location:
- library/mex
- Files:
-
- 2 added
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
library/mex/buildmex.sh
r341 r374 1 1 #!/bin/sh 2 2 3 #MATLAB_PATH=/usr/local/matlab7/4 #BDM_PATH=../../bdm3 MATLAB_PATH=/usr/local/matlab7/ 4 BDM_PATH=../../bdm 5 5 6 MATLAB_PATH=/home/smidl/soft/matlab/matlab/7 BDM_PATH=/home/smidl/work/git/mixpp/bdm6 #MATLAB_PATH=/home/smidl/soft/matlab/matlab/ 7 #BDM_PATH=/home/smidl/work/git/mixpp/bdm 8 8 9 #mex -g -l itpp -l bdm -I$MATLAB_PATH/extern/include -I$BDM_PATH -L ../../bdm/ -L ../../linux/libs/ $110 mex -l itpp -l bdm -Wfatal-errors-I$MATLAB_PATH/extern/include -I$BDM_PATH -L ../../bdm/ -L ../../linux/libs/ $19 mex -g -l itpp -l bdm -I$MATLAB_PATH/extern/include -I$BDM_PATH -L ../../bdm/ -L ../../linux/libs/ $1 10 #mex -l itpp -l bdm -I$MATLAB_PATH/extern/include -I$BDM_PATH -L ../../bdm/ -L ../../linux/libs/ $1 11 11 #mxestimator.cpp 12 12 #mex -l bdm -I ../../bdm/ -I /home/smidl/soft/matlab/matlab/extern/include -L ../../bdm/ linefit2.cpp -
library/mex/config2mxstruct.h
r371 r374 16 16 mxconfig = group2mxstruct(config.getRoot()); 17 17 } 18 /*UImxConfig(const Setting &setting) {18 UImxConfig(const Setting &setting) { 19 19 mxconfig = group2mxstruct(setting); 20 } */20 } 21 21 22 22 private: 23 23 24 mxArray* array2mxvector( Setting &setting) {24 mxArray* array2mxvector(const Setting &setting) { 25 25 if (!setting.isArray()) mexErrMsgTxt("Given setting is not an array"); 26 26 double *elements = new double[setting.getLength()]; … … 36 36 } 37 37 38 mxArray* list2mxmatrix( Setting &setting) {38 mxArray* list2mxmatrix(const Setting &setting) { 39 39 if (!setting.isList() || ("matrix" != setting[0])) 40 40 mexErrMsgTxt("Given setting is not a matrix"); … … 55 55 } 56 56 57 mxArray* group2mxstruct( Setting &setting) {57 mxArray* group2mxstruct(const Setting &setting) { 58 58 if (!setting.isGroup()) mexErrMsgTxt("Given setting is not a group."); 59 59 const char ** keys = new const char*[setting.getLength()]; … … 85 85 case Setting::TypeInt: 86 86 case Setting::TypeInt64: 87 mxSetFieldByNumber(result, 0, i, mxCreateDoubleScalar((int) value)); 88 break; 87 89 case Setting::TypeFloat: 88 90 mxSetFieldByNumber(result, 0, i, mxCreateDoubleScalar(value)); … … 97 99 } 98 100 99 mxArray* list2mxcell( Setting &setting) {101 mxArray* list2mxcell(const Setting &setting) { 100 102 if (!setting.isList()) mexErrMsgTxt("Given setting is not a list."); 101 103 if ((setting[0].getType() == Setting::TypeString) && ("matrix" == setting[0])) { … … 125 127 case Setting::TypeInt: 126 128 case Setting::TypeInt64: 129 mxSetCell(result, i, mxCreateDoubleScalar((int) value)); 130 break; 127 131 case Setting::TypeFloat: 128 132 mxSetCell(result, i, mxCreateDoubleScalar(value)); -
library/mex/mexBM.cpp
r371 r374 1 1 #include <itpp/itmex.h> 2 2 #include <estim/arx.h> 3 #include "config2mxstruct.h" 3 4 4 5 using namespace bdm; … … 12 13 void from_setting(const Setting &S) { 13 14 name = (const char *) S["name"]; 14 string fname = name+"_new"; 15 mexCallMATLAB(1, &data, 0, 0, fname.c_str()); 15 UImxConfig conf(S); 16 data = mxDuplicateArray(conf.mxconfig); 17 //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str()); 16 18 //TODO (future...): 17 19 //mxArray * init_data = setting2mxarray S["init_data"]; … … 35 37 mexBM() {} 36 38 39 mxArray *get_data() { 40 //mexCallMATLAB(0, NULL, 1, &data, "dump"); 41 return mxDuplicateArray(data); 42 } 43 37 44 void from_setting(const Setting &S) { 38 45 name = (const char *) S["name"]; 39 string fname = name+"_new"; 40 mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str()); 46 UImxConfig conf(S); 47 data = mxDuplicateArray(conf.mxconfig); 48 //string fname = name+"_new"; 49 //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str()); 41 50 //the following works as long as the posterior is the 42 51 //only member object there could be a structure of … … 48 57 void bayes(const vec &dt) { 49 58 //void bayes() { 50 string fname = name+"_bayes"; 51 mexCallMATLAB(1, &data, 1, &data, fname.c_str()); 59 mxArray *tmp, *old; 60 mxArray *in[2]; 61 in[0] = data; 62 in[1] = mxCreateDoubleMatrix(dt.size(), 1, mxREAL); 63 vec2mxArray(dt, in[1]); 64 mexCallMATLAB(1, &tmp, 2, in, (name+"_bayes").c_str()); 65 old = data; 66 data = mxDuplicateArray(tmp); 67 if (old) mxDestroyArray(old); 68 if (tmp) mxDestroyArray(tmp); 69 //mexCallMATLAB(0, NULL, 1, &data, "dump"); 52 70 } 53 71 const mexEpdf& posterior() const { … … 72 90 config.readFile(filename.c_str()); 73 91 mexBM mb; 74 mb.from_setting(config.getRoot()); 75 vec a = "1.0 2.0 3.0"; 76 mb.bayes(a); 92 Setting &root = config.getRoot(); 93 mb.from_setting(root); 94 vec dt = "18.0"; 95 mb.bayes(dt); 96 if(n_output>0) output[0] = mb.get_data(); 77 97 78 98 … … 80 100 81 101 // Create output vectors 82 output[0] = mxCreateDoubleMatrix(1,1, mxREAL);102 //output[0] = mxCreateDoubleMatrix(1,1, mxREAL); 83 103 84 104 // Convert the IT++ format to Matlab format for output