Show
Ignore:
Timestamp:
08/12/09 09:27:40 (15 years ago)
Author:
vbarta
Message:

returning shared pointers from epdf::marginal & epdf::condition; testsuite run leaks down from 8402 to 6510 bytes

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/stat/exp_family.h

    r488 r504  
    9999}; 
    100100 
    101 template<class sq_T, template <typename> class TEpdf > 
     101template<class sq_T, template <typename> class TEpdf> 
    102102class mlnorm; 
    103103 
     
    142142                vec variance() const {return diag (R.to_mat());} 
    143143//      mlnorm<sq_T>* condition ( const RV &rvn ) const ; <=========== fails to cmpile. Why? 
    144                 mpdf* condition (const RV &rvn) const ; 
    145                 enorm<sq_T>* marginal (const RV &rv) const; 
    146 //                      epdf* marginal ( const RV &rv ) const; 
     144                shared_ptr<mpdf> condition ( const RV &rvn ) const; 
     145 
     146                // target not typed to mlnorm<sq_T, enorm<sq_T> > & 
     147                // because that doesn't compile (perhaps because we 
     148                // haven't finished defining enorm yet), but the type 
     149                // is required 
     150                void condition ( const RV &rvn, mpdf &target ) const; 
     151 
     152                shared_ptr<epdf> marginal (const RV &rvn ) const; 
     153                void marginal ( const RV &rvn, enorm<sq_T> &target ) const; 
    147154                //!@} 
    148155 
     
    12351242 
    12361243template<class sq_T> 
    1237 enorm<sq_T>* enorm<sq_T>::marginal (const RV &rvn) const 
     1244shared_ptr<epdf> enorm<sq_T>::marginal ( const RV &rvn ) const 
     1245{ 
     1246        enorm<sq_T> *tmp = new enorm<sq_T> (); 
     1247        shared_ptr<epdf> narrow(tmp); 
     1248        marginal ( rvn, *tmp ); 
     1249        return narrow; 
     1250} 
     1251 
     1252template<class sq_T> 
     1253void enorm<sq_T>::marginal ( const RV &rvn, enorm<sq_T> &target ) const 
    12381254{ 
    12391255        it_assert_debug (isnamed(), "rv description is not assigned"); 
    12401256        ivec irvn = rvn.dataind (rv); 
    12411257 
    1242         sq_T Rn (R, irvn);  //select rows and columns of R 
    1243  
    1244         enorm<sq_T>* tmp = new enorm<sq_T>; 
    1245         tmp->set_rv (rvn); 
    1246         tmp->set_parameters (mu (irvn), Rn); 
    1247         return tmp; 
     1258        sq_T Rn (R, irvn);  // select rows and columns of R 
     1259 
     1260        target.set_rv ( rvn ); 
     1261        target.set_parameters (mu (irvn), Rn); 
    12481262} 
    12491263 
    12501264template<class sq_T> 
    1251 mpdf* enorm<sq_T>::condition (const RV &rvn) const 
    1252 { 
     1265shared_ptr<mpdf> enorm<sq_T>::condition ( const RV &rvn ) const 
     1266{ 
     1267        mlnorm<sq_T> *tmp = new mlnorm<sq_T> (); 
     1268        shared_ptr<mpdf> narrow(tmp); 
     1269        condition ( rvn, *tmp ); 
     1270        return narrow; 
     1271} 
     1272 
     1273template<class sq_T> 
     1274void enorm<sq_T>::condition ( const RV &rvn, mpdf &target ) const 
     1275{ 
     1276        typedef mlnorm<sq_T> TMlnorm; 
    12531277 
    12541278        it_assert_debug (isnamed(), "rvs are not assigned"); 
     1279        TMlnorm &uptarget = dynamic_cast<TMlnorm &>(target); 
    12551280 
    12561281        RV rvc = rv.subt (rvn); 
     
    12761301        sq_T R_n (S11 - A *S12.T()); 
    12771302 
    1278         mlnorm<sq_T>* tmp = new mlnorm<sq_T> (); 
    1279         tmp->set_rv (rvn); tmp->set_rvc (rvc); 
    1280         tmp->set_parameters (A, mu1 - A*mu2, R_n); 
    1281         return tmp; 
     1303        uptarget.set_rv (rvn); 
     1304        uptarget.set_rvc (rvc); 
     1305        uptarget.set_parameters (A, mu1 - A*mu2, R_n); 
    12821306} 
    12831307