From: <hi...@us...> - 2008-02-18 14:53:16
|
Revision: 4656 http://octave.svn.sourceforge.net/octave/?rev=4656&view=rev Author: highegg Date: 2008-02-18 06:52:59 -0800 (Mon, 18 Feb 2008) Log Message: ----------- add const, replace fortran_vec() with data() where appropriate Modified Paths: -------------- trunk/octave-forge/main/octgpr/src/ChangeLog trunk/octave-forge/main/octgpr/src/forsubs.h trunk/octave-forge/main/octgpr/src/gpr_predict.cc trunk/octave-forge/main/octgpr/src/gpr_train.cc trunk/octave-forge/main/octgpr/src/gprmod.h trunk/octave-forge/main/octgpr/src/predict.c trunk/octave-forge/main/octgpr/src/setup.c trunk/octave-forge/main/octgpr/src/train.c Modified: trunk/octave-forge/main/octgpr/src/ChangeLog =================================================================== --- trunk/octave-forge/main/octgpr/src/ChangeLog 2008-02-18 14:29:53 UTC (rev 4655) +++ trunk/octave-forge/main/octgpr/src/ChangeLog 2008-02-18 14:52:59 UTC (rev 4656) @@ -1,3 +1,10 @@ +2008-02-18 Jaroslav Hajek <hi...@gm...> + + * forsubs.h gprmod.h predict.c train.c setup.c: added const modifiers + where appropriate. + * grp_train,gpr_predict: replaced Array::fortran_vec with Array::data + where appropriate, to prevent unnecessary copying. + 2008-02-15 Jaroslav Hajek <hi...@gm...> * octgpr.m: improved demo. Modified: trunk/octave-forge/main/octgpr/src/forsubs.h =================================================================== --- trunk/octave-forge/main/octgpr/src/forsubs.h 2008-02-18 14:29:53 UTC (rev 4655) +++ trunk/octave-forge/main/octgpr/src/forsubs.h 2008-02-18 14:52:59 UTC (rev 4656) @@ -22,7 +22,7 @@ #define _FORSUBS_H #include <config.h> -typedef void (*corfptr) (double *t,double *f,double *d); +typedef void (*corfptr) (const double *t,double *f,double *d); #ifdef __cplusplus extern "C" { @@ -39,22 +39,96 @@ #define F77_dtr2tp F77_FUNC(dtr2tp,DTR2TP) #define F77_optdrv F77_FUNC(optdrv,OPTDRV) -void F77_corgau(double *t, double *f, double *d); -void F77_corexp(double *t, double *f, double *d); -void F77_corimq(double *t, double *f, double *d); -void F77_nllgpr(int *ndim, int *nx, double x[], double y[], double theta[], double *nu, - double *var, int *nlin, double mu[], double r[], double *nll, corfptr corr, int *info); -void F77_nldgpr(int *ndim, int *nx, double x[], double theta[], double *nu, double *var, double r[], - double dtheta[], double dnu[], int *info); -void F77_nl0gpr(int *nx, double y[], double *nu, double *nll0, double *nllinf); -void F77_infgpr(int *ndim, int *nx, double x[], double theta[], double *nu, double *var, - int *nlin, double mu[], double rp[], corfptr corr, double x0[], - double *y0, double *sig0, int *nder, double yd0[], double *w); -void F77_stheta(int *ndim, int *nx, double x[], double theta[]); -void F77_dtr2tp(char *uplo, char *diag, int *n, double a[], int *lda, double ap[]); +void F77_corgau(const double *t, double *f, double *d); -void F77_optdrv(int *ndim, double theta[], double *nu, double *nll, double dtheta[], double dnu[], double theta0[], double *nu0, double *nll0, double dtheta0[], double dnu0[], int *info, double scal[], int *l2nu, double vm[], double cp[], int ic[]); +void F77_corexp(const double *t, double *f, double *d); +void F77_corimq(const double *t, double *f, double *d); + +void F77_nllgpr( + const int *ndim, + const int *nx, + const double x[], + const double y[], + const double theta[], + const double *nu, + double *var, + const int *nlin, + double mu[], + double r[], + double *nll, + const corfptr corr, + int *info); + +void F77_nldgpr( + const int *ndim, + const int *nx, + const double x[], + const double theta[], + const double *nu, + double *var, + double r[], + double dtheta[], + double dnu[], + int *info); +void F77_nl0gpr( + const int *nx, + const double y[], + const double *nu, + double *nll0, + double *nllinf); + +void F77_infgpr( + const int *ndim, + const int *nx, + const double x[], + const double theta[], + const double *nu, + const double *var, + const int *nlin, + const double mu[], + const double rp[], + const corfptr corr, + const double x0[], + double *y0, + double *sig0, + const int *nder, + double yd0[], + double *w); + +void F77_stheta( + const int *ndim, + const int *nx, + const double x[], + double theta[]); + +void F77_dtr2tp( + const char *uplo, + const char *diag, + const int *n, + const double a[], + const int *lda, + double ap[]); + +void F77_optdrv( + const int *ndim, + double theta[], + double *nu, + double *nll, + double dtheta[], + double dnu[], + double theta0[], + double *nu0, + double *nll0, + double dtheta0[], + double dnu0[], + int *info, + double scal[], + const int *l2nu, + double vm[], + double cp[], + int ic[]); + #ifdef __cplusplus } #endif Modified: trunk/octave-forge/main/octgpr/src/gpr_predict.cc =================================================================== --- trunk/octave-forge/main/octgpr/src/gpr_predict.cc 2008-02-18 14:29:53 UTC (rev 4655) +++ trunk/octave-forge/main/octgpr/src/gpr_predict.cc 2008-02-18 14:52:59 UTC (rev 4656) @@ -24,7 +24,7 @@ #include "gprmod.h" octave_value getfield(const Octave_map& map,const char *field,bool& err) { - Cell c = map.contents(field); + const Cell c = map.contents(field); if (!c.is_empty()) return c(0); else { @@ -117,10 +117,10 @@ if (nargout > 2) yd0 = Matrix(ndim,nx0); // do the predictions - if (nx0 > 0) GPR_predict(ndim,nx,X.fortran_vec(), - theta.fortran_vec(),&nu,nlin,corf, - &var,mu.fortran_vec(),RP.fortran_vec(), - nx0,X0.fortran_vec(),y0.fortran_vec(),sig0.fortran_vec(), + if (nx0 > 0) GPR_predict(ndim,nx,X.data(), + theta.data(),&nu,nlin,corf, + &var,mu.data(),RP.data(), + nx0,X0.data(),y0.fortran_vec(),sig0.fortran_vec(), (nargout > 2) ? yd0.fortran_vec() : 0); // build return list Modified: trunk/octave-forge/main/octgpr/src/gpr_train.cc =================================================================== --- trunk/octave-forge/main/octgpr/src/gpr_train.cc 2008-02-18 14:29:53 UTC (rev 4655) +++ trunk/octave-forge/main/octgpr/src/gpr_train.cc 2008-02-18 14:52:59 UTC (rev 4656) @@ -225,7 +225,7 @@ if (topts.maxev > 0) { // run training - int ierr = GPR_train(ndim,nx,X.fortran_vec(),y.fortran_vec(), + int ierr = GPR_train(ndim,nx,X.data(),y.data(), theta.fortran_vec(),&nu,&nll,nlin,corf,&topts); fprintf(stdout,"\n"); if (octave_signal_caught) { @@ -259,7 +259,7 @@ // make mu follow the theta convention (given by trans) Matrix mu(trans?1:nlin+1,trans?nlin+1:1); - GPR_setup(ndim,nx,X.fortran_vec(),y.fortran_vec(),theta.fortran_vec(),&nu, + GPR_setup(ndim,nx,X.data(),y.data(),theta.data(),&nu, nlin,corf,&var,mu.fortran_vec(),RP.fortran_vec(),&nll); // construct model structure Modified: trunk/octave-forge/main/octgpr/src/gprmod.h =================================================================== --- trunk/octave-forge/main/octgpr/src/gprmod.h 2008-02-18 14:29:53 UTC (rev 4655) +++ trunk/octave-forge/main/octgpr/src/gprmod.h 2008-02-18 14:52:59 UTC (rev 4656) @@ -48,22 +48,22 @@ corfptr get_corrf(const char *name); /* train model hyperparameters */ -int GPR_train(int ndim,int nx,double *X,double *y, +int GPR_train(int ndim,int nx,const double *X,const double *y, double *theta,double *nu,double *nll, - int nlin,corfptr corf,struct GPR_train_opts *opts); + int nlin,const corfptr corf,struct GPR_train_opts *opts); /* given hypers, setup model for predictions */ -int GPR_setup(int ndim,int nx,double *X,double *y, - double *theta,double *nu, - int nlin,corfptr corf, +int GPR_setup(int ndim,int nx,const double *X,const double *y, + const double *theta,const double *nu, + int nlin,const corfptr corf, double *var, double *mu,double *RP,double *nll); /* compute predictions */ -void GPR_predict(int ndim,int nx,double *X, - double *theta,double *nu, - int nlin,corfptr corf, - double *var,double *mu,double *RP, - int nx0,double *X0,double *y0,double *sig0,double *yd0); +void GPR_predict(int ndim,int nx,const double *X, + const double *theta,const double *nu, + int nlin,const corfptr corf, + const double *var,const double *mu,const double *RP, + int nx0,const double *X0,double *y0,double *sig0,double *yd0); #ifdef __cplusplus } Modified: trunk/octave-forge/main/octgpr/src/predict.c =================================================================== --- trunk/octave-forge/main/octgpr/src/predict.c 2008-02-18 14:29:53 UTC (rev 4655) +++ trunk/octave-forge/main/octgpr/src/predict.c 2008-02-18 14:52:59 UTC (rev 4656) @@ -24,11 +24,11 @@ #define DSIZE sizeof(double) -void GPR_predict(int ndim,int nx,double *X, - double *theta,double *nu, +void GPR_predict(int ndim,int nx,const double *X, + const double *theta,const double *nu, int nlin,corfptr corf, - double *var,double *mu,double *RP, - int nx0,double *X0,double *y0,double *sig0,double *yd0) + const double *var,const double *mu,const double *RP, + int nx0,const double *X0,double *y0,double *sig0,double *yd0) { int nder = (yd0) ? ndim : 0; double *work = malloc(nx*(1+(nder)?1:0)*DSIZE); Modified: trunk/octave-forge/main/octgpr/src/setup.c =================================================================== --- trunk/octave-forge/main/octgpr/src/setup.c 2008-02-18 14:29:53 UTC (rev 4655) +++ trunk/octave-forge/main/octgpr/src/setup.c 2008-02-18 14:52:59 UTC (rev 4656) @@ -24,8 +24,8 @@ #define DSIZE sizeof(double) -int GPR_setup(int ndim,int nx,double *X,double *y, - double *theta,double *nu, +int GPR_setup(int ndim,int nx,const double *X,const double *y, + const double *theta,const double *nu, int nlin,corfptr corf, double *var, double *mu,double *RP,double *nll) { Modified: trunk/octave-forge/main/octgpr/src/train.c =================================================================== --- trunk/octave-forge/main/octgpr/src/train.c 2008-02-18 14:29:53 UTC (rev 4655) +++ trunk/octave-forge/main/octgpr/src/train.c 2008-02-18 14:52:59 UTC (rev 4656) @@ -25,7 +25,7 @@ #include "gprmod.h" -int GPR_train(int ndim,int nx,double *X,double *y, +int GPR_train(int ndim,int nx,const double *X,const double *y, double *theta,double *nu,double *nll, int nlin,corfptr corf,struct GPR_train_opts *opts) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |