Changeset 756

Show
Ignore:
Timestamp:
12/28/09 17:02:37 (14 years ago)
Author:
mido
Message:

odladen FindMatlab?.cmake
trida UImxConfig smazana a nahrazena statickou funkci UImxArray::create_mxArray(), a podle toho upravene zdrojaky
odstranen abort ze shared pointeru

Files:
1 removed
14 modified

Legend:

Unmodified
Added
Removed
  • applications/bdmtoolbox/mex/config2mxstruct.cpp

    r706 r756  
    1 #include <mex/config2mxstruct.h> 
    21#include <base/user_info.h> 
     2#include <itpp/itmex.h> 
     3#include <mex/mex_parser.h> 
     4 
     5using namespace bdm; 
    36 
    47void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { 
     
    69                string filename = mxArray2string ( input[0] ); 
    710                try { 
    8                         UImxConfig C ( filename.c_str() ); 
    911                        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                        } 
    1116                } catch ( SettingException xcptn ) { 
    1217                        cout<<"Error in:" + string ( xcptn.getPath() ) <<endl; 
  • applications/bdmtoolbox/mex/epdf_mean.cpp

    r728 r756  
    2323        RV::clear_all(); 
    2424        //CONFIG 
    25         if (!mxIsStruct(input[0])) mexErrMsgTxt("Given input is not a struct."); 
    26                  
    2725        UImxArray Cfg(input[0]); 
    2826        Cfg.writeFile("epdf_mean.cfg"); 
    2927 
    30         shared_ptr<epdf> ep=UI::build<epdf>(Cfg.getRoot()); 
     28        shared_ptr<epdf> ep=UI::build<epdf>(Cfg); 
    3129         
    3230         
  • applications/bdmtoolbox/mex/epdf_sample_mat.cpp

    r730 r756  
    2424        RV::clear_all(); 
    2525        //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); 
    2729 
    2830        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]));}        
    3532         
    3633        if ( n_output<1 ) mexErrMsgTxt ( "No output - nothing to do!" ); 
  • applications/bdmtoolbox/mex/estimator.cpp

    r728 r756  
    209209                if ( n_output<1 ) mexErrMsgTxt ( "Wrong number of output variables!" ); 
    210210                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()); 
    215213        } 
    216214#endif 
  • applications/bdmtoolbox/mex/lqg_redesign.cpp

    r733 r756  
    1212#ifdef MEX 
    1313#include <mex/mex_parser.h> 
    14 #include <mex/config2mxstruct.h> 
    1514 
    1615void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { 
     
    7170        mat2mxArray(L, output[0]); 
    7271        if (n_output>1){ 
    73                 Config C;  
    74                 rv.to_setting(C.getRoot()); 
    75                 UImxConfig ui(C.getRoot()); 
    76                 output[1] = ui.mxconfig; 
     72 
     73                UImxArray out; 
     74                UI::save( &rv, out ); 
     75                output[1]= out.create_mxArray(); 
    7776        } 
    7877                 
  • applications/bdmtoolbox/mex/merger.cpp

    r706 r756  
    55#include <mex/mex_logger.h> 
    66#include <mex/mex_parser.h> 
    7 #include <mex/config2mxstruct.h> 
    87#endif 
    98 
  • applications/bdmtoolbox/mex/mixef_init.cpp

    r746 r756  
    2525        //input check 
    2626        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."); 
    2828        if (!mxIsStruct(input[1])) mexErrMsgTxt("Given input #2 is not a struct."); 
    2929        //output check 
     
    5050         
    5151#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(); 
    5655#else 
    5756        UIFile out; 
  • applications/bdmtoolbox/mex/simulator.cpp

    r706 r756  
    9898                fname = argv[1]; 
    9999        } else { 
    100                 fname="estimator.cfg"; 
     100                fname="simulator.cfg"; 
    101101        } 
    102102        UIFile Cfg ( fname ); 
  • applications/bdmtoolbox/tutorial/userguide/arx_selection_example.m

    r754 r756  
    1 % load data created by the MpdfDS_example 
     1% load data created by the pdfDS_example 
    22load pdfds_results 
    33 
  • library/bdm/bdmroot.h

    r737 r756  
    4949        int log_level; 
    5050 
     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 
    5166public: 
    5267        //!default constructor 
     
    7691        } 
    7792 
    78         //! Read instance properties according the data stored in the Setting structure 
    79         virtual void from_setting ( const Setting &set ) { 
    80         } 
    81  
    82         //! Save all the instance properties into the Setting structure 
    83         virtual void to_setting ( Setting &set ) const { 
    84         } 
    85  
    8693        //! Check that all internal structures has been correctly set-up. Called at the end of from_setting. 
    8794        virtual void validate() { 
  • library/bdm/mex/mex_BM.h

    r737 r756  
    11#include <estim/arx.h> 
    22#include <itpp/itmex.h> 
    3 #include <mex/config2mxstruct.h> 
    43#include "mex_parser.h" 
    54 
     
    2524        mexEpdf() {}; 
    2625        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 ); 
    3028                //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str()); 
    3129                //TODO (future...): 
     
    6361        void from_setting ( const Setting &S )  { 
    6462                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 
    6867                //string fname = name+"_new"; 
    6968                //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str()); 
  • library/bdm/mex/mex_parser.h

    r737 r756  
    2222                        mexErrMsgTxt ( "Given mxArray is not a struct." ); 
    2323                }; 
     24 
    2425                //mexCallMATLAB(0, NULL, 1, (mxArray **) &mxarray, "dump"); 
    2526                fillGroup ( setting, mxarray ); 
     
    4142                fillGroup ( child, mxarray ); 
    4243        } 
    43         //! Operator for more convenient access to this Confic 
     44        //! Operator for more convenient access to this Config 
    4445        operator Setting&() { 
    4546                return getRoot(); 
    4647        } 
     48 
    4749private: 
    4850        void storeNumeric ( Setting &setting, const mxArray *value, string key = "" ) { 
     
    135137                } 
    136138        } 
     139 
     140public: 
     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 
     153private: 
     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        } 
    137282}; 
    138283 
  • library/bdm/shared_ptr.h

    r737 r756  
    123123        */ 
    124124        T *operator->() { 
    125                 if ( !payload ) { 
    126                         abort(); 
    127                 };// "dereferencing NULL" ); 
     125                bdm_assert_debug ( payload, "dereferencing NULL shared pointer" ); 
    128126                return payload; 
    129127        } 
     
    133131        //! isn't NULL. 
    134132        T &operator*() { 
    135                 bdm_assert_debug ( payload, "dereferencing NULL" ); 
     133                bdm_assert_debug ( payload, "dereferencing NULL shared pointer" ); 
    136134                return *payload; 
    137135        } 
     
    149147        //! pointer isn't NULL. 
    150148        const T *operator->() const { 
    151                 bdm_assert_debug ( payload, "dereferencing NULL" ); 
     149                bdm_assert_debug ( payload, "dereferencing NULL shared pointer" ); 
    152150                return payload; 
    153151        } 
     
    157155        //! isn't NULL. 
    158156        const T &operator*() const { 
    159                 bdm_assert_debug ( payload, "dereferencing NULL" ); 
     157                bdm_assert_debug ( payload, "dereferencing NULL shared pointer" ); 
    160158                return *payload; 
    161159        } 
  • library/system/FindMatlab.cmake

    r662 r756  
    1717IF(WIN32) 
    1818 
    19   FILE(GLOB _auto_matlab_prefixes "C:/Program Files/MATLAB*/R20*" "D:/Program Files/MATLAB*/R20*" "C:/Devel/MATLAB*/R20*") # used machines Aug 2009 
     19  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 
    2020 
    2121  IF(CMAKE_SIZEOF_VOID_P EQUAL 4)