Changeset 737 for library/bdm/mex

Show
Ignore:
Timestamp:
11/25/09 12:14:38 (15 years ago)
Author:
mido
Message:

ASTYLER RUN OVER THE WHOLE LIBRARY, JUPEE

Location:
library/bdm/mex
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/mex/config2mxstruct.h

    r728 r737  
    3232                if ( !setting.isArray() ) mexErrMsgTxt ( "Given setting is not an array" ); 
    3333                mxArray *result = mxCreateDoubleMatrix ( 1, setting.getLength(), mxREAL ); 
    34                 double *elements = mxGetPr(result); 
     34                double *elements = mxGetPr ( result ); 
    3535                for ( int i = 0; i < setting.getLength(); i++ ) { 
    3636                        if ( setting.getType() == Setting::TypeInt ) { //TODO: tady je chyba -- zaporna cisla nejsou TypeInt 
    37                                 elements[i] = (int) setting[i]; 
     37                                elements[i] = ( int ) setting[i]; 
    3838                        } else { 
    3939                                elements[i] =  setting[i]; 
     
    4545        //! Convert libconfig's array to Matlab matrix 
    4646        mxArray* list2mxmatrix ( const Setting &setting )  { 
    47                 if ( !setting.isList() || ( strcmp("matrix", setting[0])!=0 ) ) 
     47                if ( !setting.isList() || ( strcmp ( "matrix", setting[0] ) != 0 ) ) 
    4848                        mexErrMsgTxt ( "Given setting is not a matrix" ); 
    4949                int rows = setting[1]; 
     
    6262                return result; 
    6363        } 
    64          
     64 
    6565        //! Convert libconfig's gourp to Matlab structure 
    6666        mxArray* group2mxstruct ( const Setting &setting ) { 
     
    114114                        return result; 
    115115                } 
    116                  
    117                 if ( ( setting[0].getType() == Setting::TypeString )){ 
    118                         string s=(setting[0]); 
    119                         if (s=="matrix") { 
     116 
     117                if ( ( setting[0].getType() == Setting::TypeString ) ) { 
     118                        string s = ( setting[0] ); 
     119                        if ( s == "matrix" ) { 
    120120                                return list2mxmatrix ( setting ); 
    121121                        } 
  • library/bdm/mex/mex_BM.h

    r706 r737  
    66namespace bdm { 
    77/*! 
    8 * \brief Wrapper of BM mapping BM's methods to matlab functions  
     8* \brief Wrapper of BM mapping BM's methods to matlab functions 
    99 
    1010The data are stored in an internal matrix \c Data . Each column of Data corresponds to one discrete time observation \f$t\f$. Access to this matrix is via indices \c rowid and \c delays. 
     
    1616 
    1717//! epdf with functions implemented in matlab 
    18 class mexEpdf: public epdf{ 
    19         protected: 
    20                 //! prefix of matlab functions 
    21                 string name; 
    22                 //! pointer to storage structure 
    23                 mxArray *data; 
    24         public: 
    25                 mexEpdf() {}; 
    26                 void from_setting(const Setting &S)  { 
    27                         name = (const char *) S["name"]; 
    28                         UImxConfig conf(S); 
    29                         data = mxDuplicateArray(conf.mxconfig); 
    30                         //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str()); 
    31                         //TODO (future...): 
    32                         //mxArray * init_data = setting2mxarray S["init_data"]; 
    33                         //mexCallMATLAB(1, &data, 1, &init_data, name+"_from_setting"); 
    34                         //delete init_data; 
    35                 }  
    36                 vec mean() const { 
    37                         mxArray *tmp; 
    38                         string fname = name+"_mean"; 
    39                         mexCallMATLAB(1, &tmp, 1, (mxArray **) &data, fname.c_str()); 
    40                         return mxArray2vec(tmp); 
    41                 }  
     18class mexEpdf: public epdf { 
     19protected: 
     20        //! prefix of matlab functions 
     21        string name; 
     22        //! pointer to storage structure 
     23        mxArray *data; 
     24public: 
     25        mexEpdf() {}; 
     26        void from_setting ( const Setting &S )  { 
     27                name = ( const char * ) S["name"]; 
     28                UImxConfig conf ( S ); 
     29                data = mxDuplicateArray ( conf.mxconfig ); 
     30                //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str()); 
     31                //TODO (future...): 
     32                //mxArray * init_data = setting2mxarray S["init_data"]; 
     33                //mexCallMATLAB(1, &data, 1, &init_data, name+"_from_setting"); 
     34                //delete init_data; 
     35        } 
     36        vec mean() const { 
     37                mxArray *tmp; 
     38                string fname = name + "_mean"; 
     39                mexCallMATLAB ( 1, &tmp, 1, ( mxArray ** ) &data, fname.c_str() ); 
     40                return mxArray2vec ( tmp ); 
     41        } 
    4242}; 
    43 UIREGISTER(mexEpdf); 
     43UIREGISTER ( mexEpdf ); 
    4444 
    4545//! BM with functions implemented in matlab 
    46 class mexBM: public BM{ 
    47         protected : 
    48                 //! prefix of matlab functions 
    49                 string name; 
    50                 //! internal estimator 
    51                 mexEpdf est; 
    52                 //! mxArray with attributes of this object 
    53                 mxArray *data; 
    54         public: 
    55                 mexBM() {} 
     46class mexBM: public BM { 
     47protected : 
     48        //! prefix of matlab functions 
     49        string name; 
     50        //! internal estimator 
     51        mexEpdf est; 
     52        //! mxArray with attributes of this object 
     53        mxArray *data; 
     54public: 
     55        mexBM() {} 
    5656 
    57                 //! duplicate internal data pointer? 
    58                 mxArray *get_data() { 
    59                         //mexCallMATLAB(0, NULL, 1, &data, "dump"); 
    60                         return mxDuplicateArray(data); 
    61                 } 
     57        //! duplicate internal data pointer? 
     58        mxArray *get_data() { 
     59                //mexCallMATLAB(0, NULL, 1, &data, "dump"); 
     60                return mxDuplicateArray ( data ); 
     61        } 
    6262 
    63                 void from_setting(const Setting &S)  { 
    64                         BM::from_setting(S); 
    65                         name = (const char *) S["name"]; 
    66                         UImxConfig conf(S); 
    67                         data = mxDuplicateArray(conf.mxconfig); 
    68                         //string fname = name+"_new"; 
    69                         //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str()); 
    70                         //the following works as long as the posterior is the 
    71                         //only member object there could be a structure of  
    72                         //member objects in the setting and a for cycle over 
    73                         //all of them right here in the code 
    74                         Setting &posterior = S["posterior"];  
    75                         est.from_setting(posterior); 
    76                 } 
    77                 void bayes(const vec &yt, const vec &cond)  { 
     63        void from_setting ( const Setting &S )  { 
     64                BM::from_setting ( S ); 
     65                name = ( const char * ) S["name"]; 
     66                UImxConfig conf ( S ); 
     67                data = mxDuplicateArray ( conf.mxconfig ); 
     68                //string fname = name+"_new"; 
     69                //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str()); 
     70                //the following works as long as the posterior is the 
     71                //only member object there could be a structure of 
     72                //member objects in the setting and a for cycle over 
     73                //all of them right here in the code 
     74                Setting &posterior = S["posterior"]; 
     75                est.from_setting ( posterior ); 
     76        } 
     77        void bayes ( const vec &yt, const vec &cond )  { 
    7878                //void bayes()  { 
    79                         mxArray *tmp, *old; 
    80                         mxArray *in[2]; 
    81                         in[0] = data; 
    82                         in[1] = mxCreateDoubleMatrix(yt.size(), 1, mxREAL); 
    83                         vec2mxArray(yt, in[1]); 
    84                         mexCallMATLAB(1, &tmp, 2, in, (name+"_bayes").c_str()); 
    85                         old = data; 
    86                         data = mxDuplicateArray(tmp); 
    87                         if (old) mxDestroyArray(old); 
    88                         if (tmp) mxDestroyArray(tmp); 
    89                         //mexCallMATLAB(0, NULL, 1, &data, "dump"); 
    90                 }  
    91                 //! return correctly typed posterior (covariant return) 
    92                 const mexEpdf& posterior() const  { 
    93                         return est; 
    94                 } //tohle by melo zustat!! 
     79                mxArray *tmp, *old; 
     80                mxArray *in[2]; 
     81                in[0] = data; 
     82                in[1] = mxCreateDoubleMatrix ( yt.size(), 1, mxREAL ); 
     83                vec2mxArray ( yt, in[1] ); 
     84                mexCallMATLAB ( 1, &tmp, 2, in, ( name + "_bayes" ).c_str() ); 
     85                old = data; 
     86                data = mxDuplicateArray ( tmp ); 
     87                if ( old ) mxDestroyArray ( old ); 
     88                if ( tmp ) mxDestroyArray ( tmp ); 
     89                //mexCallMATLAB(0, NULL, 1, &data, "dump"); 
     90        } 
     91        //! return correctly typed posterior (covariant return) 
     92        const mexEpdf& posterior() const  { 
     93                return est; 
     94        } //tohle by melo zustat!! 
    9595}; 
    96 UIREGISTER(mexBM); 
     96UIREGISTER ( mexBM ); 
    9797 
    9898} 
  • library/bdm/mex/mex_datasource.h

    r706 r737  
    1616*/ 
    1717class mxArrayDS : public MemDS { 
    18         public: 
     18public: 
    1919        //!Default constructor 
    20         mxArrayDS ():MemDS() {}; 
     20        mxArrayDS () : MemDS() {}; 
    2121 
    2222        /*! \brief Create memory data source from mxArray 
     
    2626                type="mexDS"; 
    2727                varname="";                // name of workspace variable 
    28                 row_rv = {class='RV',...}  // definition of  
     28                row_rv = {class='RV',...}  // definition of 
    2929                }; 
    3030        \endcode 
     
    3535        void from_setting ( const Setting &set ) { 
    3636                Data = mxArray2mat ( mexGetVariable ( "base", set["varname"] ) ); 
    37 /*              UI::get ( rowid, set, "rids" , UI::compulsory ); 
    38                 bdm_assert_debug ( max ( rowid ) <= Data.rows(), "MemDS rowid is too high for given Dat." ); 
     37                /*              UI::get ( rowid, set, "rids" , UI::compulsory ); 
     38                                bdm_assert_debug ( max ( rowid ) <= Data.rows(), "MemDS rowid is too high for given Dat." ); 
    3939 
    40                 UI::get ( delays, set, "tds", UI::compulsory ); 
    41                 time = max ( delays ); 
    42                 bdm_assert_debug ( time < Data.cols(), "MemDS delays are too high." ); 
    43 */ 
     40                                UI::get ( delays, set, "tds", UI::compulsory ); 
     41                                time = max ( delays ); 
     42                                bdm_assert_debug ( time < Data.cols(), "MemDS delays are too high." ); 
     43                */ 
    4444                //set MemDS 
    45                 rowid = linspace(0,Data.rows()-1); 
    46                 dtsize=rowid.length(); 
    47                 ytsize=rowid.length(); 
    48                 utsize=0; 
    49                  
     45                rowid = linspace ( 0, Data.rows() - 1 ); 
     46                dtsize = rowid.length(); 
     47                ytsize = rowid.length(); 
     48                utsize = 0; 
     49 
    5050                shared_ptr<RV> r = UI::build<RV> ( set, "rv", UI::optional ); 
    5151                RV ru = RV(); 
    52                 if (r){ 
     52                if ( r ) { 
    5353                        set_drv ( *r, ru ); 
    5454                } else { 
    55                         RV def((const char*)set["varname"],Data.rows()); 
    56                         set_drv(def, ru); 
     55                        RV def ( ( const char* ) set["varname"], Data.rows() ); 
     56                        set_drv ( def, ru ); 
    5757                } 
    5858        } 
     
    6969 
    7070The identifier of matlab function is stored in attribute \c name. 
    71 This identifier defines:  
     71This identifier defines: 
    7272\li function to call to do a step(): name_step.m 
    7373\li workspace variable to write input to: name_input 
    7474*/ 
    7575class mexDS : public DS { 
    76         protected: 
    77                 //! identifier of matlab function  
    78                 string step_name; 
    79                 //! identifier of matlab input variabel 
    80                 string input_name; 
    81                 //! cache of results from name_step 
    82                 vec dt; 
    83                 //! cache of inputs  
    84                 vec ut; 
    85         public: 
     76protected: 
     77        //! identifier of matlab function 
     78        string step_name; 
     79        //! identifier of matlab input variabel 
     80        string input_name; 
     81        //! cache of results from name_step 
     82        vec dt; 
     83        //! cache of inputs 
     84        vec ut; 
     85public: 
    8686        //!Default constructor 
    87         mexDS ():DS() {}; 
     87        mexDS () : DS() {}; 
    8888 
    8989        /*! \brief Create memory data source from mxArray 
     
    103103        */ 
    104104        void from_setting ( const Setting &set ) { 
    105                 UI::get(step_name, set, "step_name", UI::compulsory); 
    106                 UI::get(input_name, set, "input_name", UI::compulsory); 
    107                  
     105                UI::get ( step_name, set, "step_name", UI::compulsory ); 
     106                UI::get ( input_name, set, "input_name", UI::compulsory ); 
     107 
    108108                shared_ptr<RV> ry = UI::build<RV> ( set, "yrv", UI::compulsory ); 
    109                 shared_ptr<RV> ru = UI::build<RV> ( set, "urv", UI::compulsory); 
     109                shared_ptr<RV> ru = UI::build<RV> ( set, "urv", UI::compulsory ); 
    110110 
    111                 ytsize=ry->_dsize(); 
    112                 utsize=ru->_dsize(); 
    113                 dtsize = ytsize+utsize; 
    114                  
    115                 set_drv(*ry, *ru); 
     111                ytsize = ry->_dsize(); 
     112                utsize = ru->_dsize(); 
     113                dtsize = ytsize + utsize; 
     114 
     115                set_drv ( *ry, *ru ); 
    116116                validate(); 
    117117        } 
    118          
     118 
    119119        void step() { 
    120120                mxArray* tmp; 
    121                 mxArray* dummy=NULL; 
     121                mxArray* dummy = NULL; 
    122122                // write inputs to variable input_name 
    123                 mxArray* mxinp= mexGetVariable ( "global", input_name.c_str()) ; 
    124                 if (mxinp){ 
    125                         if((int)mxGetM(mxinp)!=utsize || (int)mxGetN(mxinp)!=utsize) { 
     123                mxArray* mxinp = mexGetVariable ( "global", input_name.c_str() ) ; 
     124                if ( mxinp ) { 
     125                        if ( ( int ) mxGetM ( mxinp ) != utsize || ( int ) mxGetN ( mxinp ) != utsize ) { 
    126126                                // mxinp is invalid - create new one 
    127                                 mxDestroyArray(mxinp); 
    128                                 mxinp=mxCreateDoubleMatrix(utsize,1,mxREAL); 
     127                                mxDestroyArray ( mxinp ); 
     128                                mxinp = mxCreateDoubleMatrix ( utsize, 1, mxREAL ); 
    129129                        } 
    130                          
     130 
    131131                } else { 
    132                         mxinp=mxCreateDoubleMatrix(utsize,1,mxREAL); 
     132                        mxinp = mxCreateDoubleMatrix ( utsize, 1, mxREAL ); 
    133133                } 
    134                 vec2mxArray(ut, mxinp); 
    135                 mexPutVariable("global",input_name.c_str(),mxinp); 
     134                vec2mxArray ( ut, mxinp ); 
     135                mexPutVariable ( "global", input_name.c_str(), mxinp ); 
    136136                // call function step_name 
    137                 mexCallMATLAB(1, &tmp, 0, (mxArray **) &dummy, step_name.c_str()); 
     137                mexCallMATLAB ( 1, &tmp, 0, ( mxArray ** ) &dummy, step_name.c_str() ); 
    138138                // save its results 
    139                 bdm_assert_debug((int)mxGetM(tmp)==ytsize || (int)mxGetN(tmp)==ytsize,"mexDS.step() expected return vector of length " + num2str(dtsize) + 
    140                 "got vector " + num2str((int)mxGetM(tmp)) + "x" + num2str((int)mxGetN(tmp))); 
     139                bdm_assert_debug ( ( int ) mxGetM ( tmp ) == ytsize || ( int ) mxGetN ( tmp ) == ytsize, "mexDS.step() expected return vector of length " + num2str ( dtsize ) + 
     140                                   "got vector " + num2str ( ( int ) mxGetM ( tmp ) ) + "x" + num2str ( ( int ) mxGetN ( tmp ) ) ); 
    141141                //write  y 
    142                 dt.set_subvector(0,mxArray2vec(tmp)); 
     142                dt.set_subvector ( 0, mxArray2vec ( tmp ) ); 
    143143                //write u 
    144                 dt.set_subvector(ytsize,ut); 
     144                dt.set_subvector ( ytsize, ut ); 
    145145        } 
    146         void write(const vec &ut0){  
    147                 bdm_assert_debug(ut0.length()==ut.length(),"mexDS: Incompatible input vector"); 
    148                 ut=ut0; 
     146        void write ( const vec &ut0 ) { 
     147                bdm_assert_debug ( ut0.length() == ut.length(), "mexDS: Incompatible input vector" ); 
     148                ut = ut0; 
    149149        } 
    150         void getdata(vec &dt_out) const { 
    151                 bdm_assert_debug(dt_out.length()==dt.length(),"mexDS: Incompatible output vector"); 
    152                 dt_out = dt;     
     150        void getdata ( vec &dt_out ) const { 
     151                bdm_assert_debug ( dt_out.length() == dt.length(), "mexDS: Incompatible output vector" ); 
     152                dt_out = dt; 
    153153        } 
    154154 
    155155        void validate() { 
    156                 dt=zeros(dtsize); 
    157                 ut=zeros(utsize); 
     156                dt = zeros ( dtsize ); 
     157                ut = zeros ( utsize ); 
    158158        } 
    159159 
  • library/bdm/mex/mex_logger.h

    r728 r737  
    3636                for ( r = 0; r < rows; r++ ) { 
    3737                        *temp++ = in ( c ) ( r ); 
    38                          
     38 
    3939                } 
    4040        } 
     
    4848        mexlog() : memlog ( 0, "" ) {}; 
    4949        //! constructor 
    50         mexlog(long maxlen0) : memlog ( maxlen0, "" ) {}; 
     50        mexlog ( long maxlen0 ) : memlog ( maxlen0, "" ) {}; 
    5151        //! copy internal data to output mxArray 
    5252        mxArray* toCell() { 
     
    6262                        istart = 0; 
    6363                        for ( int j = 0; j < entries ( i ).length(); j++ ) { // same for as in add!!! 
    64                                 vec_name = names ( i ) +prefix_sep()+ entries ( i ).name ( j ); 
     64                                vec_name = names ( i ) + prefix_sep() + entries ( i ).name ( j ); 
    6565                                iend = istart + entries ( i ).size ( j ) - 1; 
    6666                                M = vectors ( i ).get_cols ( istart, iend ); 
     
    7777                maxlen = root["maxlen"]; 
    7878        } 
    79         Config& _setting_conf(){return setting_conf;} 
     79        Config& _setting_conf() { 
     80                return setting_conf; 
     81        } 
    8082}; 
    8183UIREGISTER ( mexlog ); 
  • library/bdm/mex/mex_parser.h

    r706 r737  
    5353                //treat empty matrices independently 
    5454                mat val; 
    55                 if (mxGetM(value)>0) { 
     55                if ( mxGetM ( value ) > 0 ) { 
    5656                        val = mxArray2mat ( value ); 
    5757                } 
     
    112112                        mexErrMsgTxt ( "Given mxArray is not a cell." ); 
    113113                }; 
    114                 for ( unsigned int i = 0; i < (unsigned int) mxGetNumberOfElements ( mxarray ); i++ ) { 
     114                for ( unsigned int i = 0; i < ( unsigned int ) mxGetNumberOfElements ( mxarray ); i++ ) { 
    115115                        mxArray *value = mxGetCell ( mxarray, i ); 
    116116                        if ( mxIsChar ( value ) ) {