Changeset 756
- Timestamp:
- 12/28/09 17:02:37 (15 years ago)
- Files:
-
- 1 removed
- 14 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/bdmtoolbox/mex/config2mxstruct.cpp
r706 r756 1 #include <mex/config2mxstruct.h>2 1 #include <base/user_info.h> 2 #include <itpp/itmex.h> 3 #include <mex/mex_parser.h> 4 5 using namespace bdm; 3 6 4 7 void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { … … 6 9 string filename = mxArray2string ( input[0] ); 7 10 try { 8 UImxConfig C ( filename.c_str() );9 11 if ( n_output>0 ) 10 output[0] = mxDuplicateArray ( C.mxconfig ); 12 { 13 UIFile C ( filename.c_str() ); 14 output[0] = UImxArray::create_mxArray( C ); 15 } 11 16 } catch ( SettingException xcptn ) { 12 17 cout<<"Error in:" + string ( xcptn.getPath() ) <<endl; -
applications/bdmtoolbox/mex/epdf_mean.cpp
r728 r756 23 23 RV::clear_all(); 24 24 //CONFIG 25 if (!mxIsStruct(input[0])) mexErrMsgTxt("Given input is not a struct.");26 27 25 UImxArray Cfg(input[0]); 28 26 Cfg.writeFile("epdf_mean.cfg"); 29 27 30 shared_ptr<epdf> ep=UI::build<epdf>(Cfg .getRoot());28 shared_ptr<epdf> ep=UI::build<epdf>(Cfg); 31 29 32 30 -
applications/bdmtoolbox/mex/epdf_sample_mat.cpp
r730 r756 24 24 RV::clear_all(); 25 25 //CONFIG 26 if (!mxIsStruct(input[0])) mexErrMsgTxt("Given input is not a struct."); 26 UImxArray Cfg(input[0]); 27 Cfg.writeFile("epdf_sample_mat.cfg"); 28 shared_ptr<epdf> ep=UI::build<epdf>(Cfg); 27 29 28 30 int nos=10; 29 if (n_input>1) {nos = (int)(*mxGetPr(input[1]));} 30 31 UImxArray Cfg(input[0]); 32 Cfg.writeFile("epdf_sample_mat.cfg"); 33 34 shared_ptr<epdf> ep=UI::build<epdf>(Cfg.getRoot()); 31 if (n_input>1) {nos = (int)(*mxGetPr(input[1]));} 35 32 36 33 if ( n_output<1 ) mexErrMsgTxt ( "No output - nothing to do!" ); -
applications/bdmtoolbox/mex/estimator.cpp
r728 r756 209 209 if ( n_output<1 ) mexErrMsgTxt ( "Wrong number of output variables!" ); 210 210 output[0] = mL->toCell(); 211 if (n_output>1) { 212 UImxConfig UIc(mL->_setting_conf().getRoot()); 213 output[1]=UIc.mxconfig; 214 } 211 if (n_output>1) 212 output[1]= UImxArray::create_mxArray(mL->_setting_conf().getRoot()); 215 213 } 216 214 #endif -
applications/bdmtoolbox/mex/lqg_redesign.cpp
r733 r756 12 12 #ifdef MEX 13 13 #include <mex/mex_parser.h> 14 #include <mex/config2mxstruct.h>15 14 16 15 void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { … … 71 70 mat2mxArray(L, output[0]); 72 71 if (n_output>1){ 73 Config C; 74 rv.to_setting(C.getRoot());75 UI mxConfig ui(C.getRoot());76 output[1] = ui.mxconfig;72 73 UImxArray out; 74 UI::save( &rv, out ); 75 output[1]= out.create_mxArray(); 77 76 } 78 77 -
applications/bdmtoolbox/mex/merger.cpp
r706 r756 5 5 #include <mex/mex_logger.h> 6 6 #include <mex/mex_parser.h> 7 #include <mex/config2mxstruct.h>8 7 #endif 9 8 -
applications/bdmtoolbox/mex/mixef_init.cpp
r746 r756 25 25 //input check 26 26 if (!mxIsNumeric(input[0])) mexErrMsgTxt("Given input #1 is not a data matrix."); 27 if (n_input<2) mexErrMsgTxt("No initial component, dont what type of mixture to fit.");27 if (n_input<2) mexErrMsgTxt("No initial component, dont know what type of mixture to fit."); 28 28 if (!mxIsStruct(input[1])) mexErrMsgTxt("Given input #2 is not a struct."); 29 29 //output check … … 50 50 51 51 #ifdef MEX 52 mxArray* tmp= mxCreateStructMatrix(1,1,0, NULL); 53 UImxArray out(tmp); 54 mix.to_setting(out); 55 output[0]=tmp; 52 UImxArray out; 53 UI::save( &mix, out ); 54 output[0]= out.create_mxArray(); 56 55 #else 57 56 UIFile out; -
applications/bdmtoolbox/mex/simulator.cpp
r706 r756 98 98 fname = argv[1]; 99 99 } else { 100 fname=" estimator.cfg";100 fname="simulator.cfg"; 101 101 } 102 102 UIFile Cfg ( fname ); -
applications/bdmtoolbox/tutorial/userguide/arx_selection_example.m
r754 r756 1 % load data created by the MpdfDS_example1 % load data created by the pdfDS_example 2 2 load pdfds_results 3 3 -
library/bdm/bdmroot.h
r737 r756 49 49 int log_level; 50 50 51 //! It is necessary to allow calling of from_setting and to_setting within the user_info class 52 friend class UI; 53 54 //! Read instance properties according the data stored in the Setting structure 55 //! 56 //! It has to be called only through user_info class, therefore it is protected 57 virtual void from_setting ( const Setting &set ) { 58 } 59 60 //! Save all the instance properties into the Setting structure 61 //! 62 //! It has to be called only through user_info class, therefore it is protected 63 virtual void to_setting ( Setting &set ) const { 64 } 65 51 66 public: 52 67 //!default constructor … … 76 91 } 77 92 78 //! Read instance properties according the data stored in the Setting structure79 virtual void from_setting ( const Setting &set ) {80 }81 82 //! Save all the instance properties into the Setting structure83 virtual void to_setting ( Setting &set ) const {84 }85 86 93 //! Check that all internal structures has been correctly set-up. Called at the end of from_setting. 87 94 virtual void validate() { -
library/bdm/mex/mex_BM.h
r737 r756 1 1 #include <estim/arx.h> 2 2 #include <itpp/itmex.h> 3 #include <mex/config2mxstruct.h>4 3 #include "mex_parser.h" 5 4 … … 25 24 mexEpdf() {}; 26 25 void from_setting ( const Setting &S ) { 27 name = ( const char * ) S["name"]; 28 UImxConfig conf ( S ); 29 data = mxDuplicateArray ( conf.mxconfig ); 26 UIFile conf( ( const char * ) S["name"] ); 27 data = UImxArray::create_mxArray( conf ); 30 28 //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str()); 31 29 //TODO (future...): … … 63 61 void from_setting ( const Setting &S ) { 64 62 BM::from_setting ( S ); 65 name = ( const char * ) S["name"]; 66 UImxConfig conf ( S ); 67 data = mxDuplicateArray ( conf.mxconfig ); 63 64 UIFile conf( ( const char * ) S["name"] ); 65 data = UImxArray::create_mxArray( conf ); 66 68 67 //string fname = name+"_new"; 69 68 //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str()); -
library/bdm/mex/mex_parser.h
r737 r756 22 22 mexErrMsgTxt ( "Given mxArray is not a struct." ); 23 23 }; 24 24 25 //mexCallMATLAB(0, NULL, 1, (mxArray **) &mxarray, "dump"); 25 26 fillGroup ( setting, mxarray ); … … 41 42 fillGroup ( child, mxarray ); 42 43 } 43 //! Operator for more convenient access to this Confi c44 //! Operator for more convenient access to this Config 44 45 operator Setting&() { 45 46 return getRoot(); 46 47 } 48 47 49 private: 48 50 void storeNumeric ( Setting &setting, const mxArray *value, string key = "" ) { … … 135 137 } 136 138 } 139 140 public: 141 //! Convert existing Setting to Matlab arrays 142 static mxArray * create_mxArray( const Setting &setting ) 143 { 144 return group2mxstruct ( setting ); 145 } 146 147 //! Convert existing Setting to Matlab arrays 148 mxArray * create_mxArray( ) 149 { 150 return group2mxstruct ( *this ); 151 } 152 153 private: 154 //! Convert libconfig's array to Matlab vector 155 static mxArray* array2mxvector ( const Setting &setting ) { 156 if ( !setting.isArray() ) mexErrMsgTxt ( "Given setting is not an array" ); 157 mxArray *result = mxCreateDoubleMatrix ( 1, setting.getLength(), mxREAL ); 158 double *elements = mxGetPr ( result ); 159 for ( int i = 0; i < setting.getLength(); i++ ) { 160 if ( setting.getType() == Setting::TypeInt ) { //TODO: tady je chyba -- zaporna cisla nejsou TypeInt 161 elements[i] = ( int ) setting[i]; 162 } else { 163 elements[i] = setting[i]; 164 } 165 } 166 return result; 167 } 168 169 //! Convert libconfig's array to Matlab matrix 170 static mxArray* list2mxmatrix ( const Setting &setting ) { 171 if ( !setting.isList() || ( strcmp ( "matrix", setting[0] ) != 0 ) ) 172 mexErrMsgTxt ( "Given setting is not a matrix" ); 173 int rows = setting[1]; 174 int cols = setting[2]; 175 if ( setting[3].getLength() != rows*cols ) 176 mexErrMsgTxt ( "Matrix elements do not fit to rows*cols" ); 177 double *elements = new double[rows*cols]; 178 for ( int i = 0; i < rows*cols; i++ ) { 179 elements[i] = setting[3][i]; 180 } 181 mat &m = * ( new mat ( elements, rows, cols ) ); 182 mxArray *result = mxCreateDoubleMatrix ( rows, cols, mxREAL ); 183 mat2mxArray ( m, result ); 184 delete &m; 185 delete [] elements; 186 return result; 187 } 188 189 //! Convert libconfig's gourp to Matlab structure 190 static mxArray* group2mxstruct ( const Setting &setting ) { 191 if ( !setting.isGroup() ) mexErrMsgTxt ( "Given setting is not a group." ); 192 const char ** keys = new const char*[setting.getLength() ]; 193 for ( int i = 0; i < setting.getLength(); i++ ) { 194 keys[i] = setting[i].getName(); 195 } 196 mxArray *result = mxCreateStructMatrix ( 1, 1, setting.getLength(), keys ); 197 delete keys; 198 for ( int i = 0; i < setting.getLength(); i++ ) { 199 Setting &value = setting[i]; 200 mxArray *old = mxGetFieldByNumber ( result, 0, i ); 201 if ( old ) mxDestroyArray ( old ); 202 switch ( value.getType() ) { 203 case Setting::TypeString: 204 mxSetFieldByNumber ( result, 0, i, mxCreateString ( value ) ); 205 break; 206 case Setting::TypeBoolean: 207 mxSetFieldByNumber ( result, 0, i, mxCreateLogicalScalar ( value ) ); 208 break; 209 case Setting::TypeGroup: 210 mxSetFieldByNumber ( result, 0, i, group2mxstruct ( value ) ); 211 break; 212 case Setting::TypeList: 213 mxSetFieldByNumber ( result, 0, i, list2mxcell ( value ) ); 214 break; 215 case Setting::TypeArray: 216 mxSetFieldByNumber ( result, 0, i, array2mxvector ( value ) ); 217 break; 218 case Setting::TypeInt: 219 case Setting::TypeInt64: 220 mxSetFieldByNumber ( result, 0, i, mxCreateDoubleScalar ( ( int ) value ) ); 221 break; 222 case Setting::TypeFloat: 223 mxSetFieldByNumber ( result, 0, i, mxCreateDoubleScalar ( value ) ); 224 break; 225 default: 226 //this should never happen 227 mexErrMsgTxt ( "Unknown type of a setting." ); 228 } 229 } 230 return result; 231 232 } 233 //! Convert libconfig's list to Matlab cell 234 static mxArray* list2mxcell ( const Setting &setting ) { 235 if ( !setting.isList() ) mexErrMsgTxt ( "Given setting is not a list." ); 236 if ( setting.getLength() == 0 ) { 237 mxArray *result = mxCreateCellMatrix ( 1, 0 ); 238 return result; 239 } 240 241 if ( ( setting[0].getType() == Setting::TypeString ) ) { 242 string s = ( setting[0] ); 243 if ( s == "matrix" ) { 244 return list2mxmatrix ( setting ); 245 } 246 } 247 mxArray *result = mxCreateCellMatrix ( 1, setting.getLength() ); 248 for ( int i = 0; i < setting.getLength(); i++ ) { 249 Setting &value = setting[i]; 250 mxArray *old = mxGetCell ( result, i ); 251 if ( old ) mxDestroyArray ( old ); 252 switch ( value.getType() ) { 253 case Setting::TypeString: 254 mxSetCell ( result, i, mxCreateString ( value ) ); 255 break; 256 case Setting::TypeBoolean: 257 mxSetCell ( result, i, mxCreateLogicalScalar ( value ) ); 258 break; 259 case Setting::TypeGroup: 260 mxSetCell ( result, i, group2mxstruct ( value ) ); 261 break; 262 case Setting::TypeList: 263 mxSetCell ( result, i, list2mxcell ( value ) ); 264 break; 265 case Setting::TypeArray: 266 mxSetCell ( result, i, array2mxvector ( value ) ); 267 break; 268 case Setting::TypeInt: 269 case Setting::TypeInt64: 270 mxSetCell ( result, i, mxCreateDoubleScalar ( ( int ) value ) ); 271 break; 272 case Setting::TypeFloat: 273 mxSetCell ( result, i, mxCreateDoubleScalar ( value ) ); 274 break; 275 default: 276 //this should never happen 277 mexErrMsgTxt ( "Unknown type of a setting." ); 278 } 279 } 280 return result; 281 } 137 282 }; 138 283 -
library/bdm/shared_ptr.h
r737 r756 123 123 */ 124 124 T *operator->() { 125 if ( !payload ) { 126 abort(); 127 };// "dereferencing NULL" ); 125 bdm_assert_debug ( payload, "dereferencing NULL shared pointer" ); 128 126 return payload; 129 127 } … … 133 131 //! isn't NULL. 134 132 T &operator*() { 135 bdm_assert_debug ( payload, "dereferencing NULL " );133 bdm_assert_debug ( payload, "dereferencing NULL shared pointer" ); 136 134 return *payload; 137 135 } … … 149 147 //! pointer isn't NULL. 150 148 const T *operator->() const { 151 bdm_assert_debug ( payload, "dereferencing NULL " );149 bdm_assert_debug ( payload, "dereferencing NULL shared pointer" ); 152 150 return payload; 153 151 } … … 157 155 //! isn't NULL. 158 156 const T &operator*() const { 159 bdm_assert_debug ( payload, "dereferencing NULL " );157 bdm_assert_debug ( payload, "dereferencing NULL shared pointer" ); 160 158 return *payload; 161 159 } -
library/system/FindMatlab.cmake
r662 r756 17 17 IF(WIN32) 18 18 19 FILE(GLOB _auto_matlab_prefixes "C:/Program Files/MATLAB* /R20*" "D:/Program Files/MATLAB*/R20*" "C:/Devel/MATLAB*/R20*") # used machines Aug 200919 FILE(GLOB _auto_matlab_prefixes "C:/Program Files/MATLAB*" "C:/Program Files/MATLAB*/R20*" "D:/Program Files/MATLAB*/R20*" "C:/Devel/MATLAB*/R20*") # used machines Aug 2009 20 20 21 21 IF(CMAKE_SIZEOF_VOID_P EQUAL 4)