Changeset 415
- Timestamp:
- Dec 1, 2005, 4:52:36 PM (18 years ago)
- Location:
- branches/better_matrix_class
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/better_matrix_class/lib/gslapi/matrix.cc
r413 r415 98 98 99 99 100 gsl_matrix* matrix:: gsl_matrix_copy(void) const100 gsl_matrix* matrix::create_gsl_matrix_copy(void) const 101 101 { 102 102 gsl_matrix* m = gsl_matrix_alloc(rows(),columns()); … … 122 122 123 123 124 /*125 vector matrix::operator*( const vector &other ) const126 {127 gsl_vector* gslvec=gsl_vector_alloc(rows());128 gsl_blas_dgemv(CblasNoTrans, 1.0, m_, other.gsl_vector_pointer(), 0.0,129 gslvec );130 vector res(gslvec);131 return res;132 }133 */134 135 136 124 const matrix& matrix::operator=( const matrix& other ) 137 125 { 138 126 if ( this != &other ) { 139 if ( m_ ) 140 gsl_matrix_free( m_ ); 141 m_ = other.gsl_matrix_copy(); 127 if (view_) 128 delete view_; 129 else if (m_) 130 gsl_matrix_free(m_); 131 m_ = other.create_gsl_matrix_copy(); 142 132 } 143 133 return *this; -
branches/better_matrix_class/lib/gslapi/matrix.h
r413 r415 70 70 /// of the view will be copied, i.e. the view is not copied. 71 71 /// 72 inline matrix(const matrix& o) : view_(NULL) { m_ = o.gsl_matrix_copy();}72 inline matrix(const matrix& o) : view_(NULL) {m_=o.create_gsl_matrix_copy();} 73 73 74 74 /// … … 156 156 /// @return A const pointer to the internal GSL matrix. 157 157 /// 158 inline const gsl_matrix* gsl_matrix_p(void) const { return m_; } 159 160 /// 161 /// @return A pointer to the internal GSL matrix. 162 /// 158 163 // Jari, is this needed? 159 inline const gsl_matrix* gsl_matrix_pointer(void) const { return m_; } 160 161 /// 162 /// @return A pointer to the internal GSL matrix. 163 /// 164 // Jari, is this needed? 165 inline gsl_matrix* gsl_matrix_pointer(void) { return m_; }; 164 inline gsl_matrix* gsl_matrix_p(void) { return m_; }; 166 165 167 166 /// … … 245 244 246 245 /// 246 /// Set element values to values in \a mat. This function is 247 /// needed for assignment of viewed elements. 248 /// 249 /// @return Whatever GSL returns. 250 /// 251 /// @note No check on size is done. 252 /// 253 /// @see const matrix& operator=(const matrix&) 254 /// 255 inline int set(const matrix& mat) { return gsl_matrix_memcpy(m_,mat.m_); } 256 257 /// 247 258 /// Set all elements to \a value. 248 259 /// … … 250 261 251 262 /// 252 /// Set \a column to \a vec. 253 /// 254 /// @return Whatever GSL returns. 263 /// Set \a column values to values in \a vec. 264 /// 265 /// @return Whatever GSL returns. 266 /// 267 /// @note No check on size is done. 255 268 /// 256 269 inline int set_column(const size_t column, const vector& vec) 257 { return gsl_matrix_set_col(m_, column, vec.gsl_vector_pointer()); } 258 259 /// 260 /// Set \a row to \a vec. 261 /// 262 /// @return Whatever GSL returns. 270 { return gsl_matrix_set_col(m_, column, vec.gsl_vector_p()); } 271 272 /// 273 /// Set \a row values to values in \a vec. 274 /// 275 /// @return Whatever GSL returns. 276 /// 277 /// @note No check on size is done. 263 278 /// 264 279 inline int set_row(const size_t row, const vector& vec) 265 { return gsl_matrix_set_row(m_, row, vec.gsl_vector_p ointer()); }280 { return gsl_matrix_set_row(m_, row, vec.gsl_vector_p()); } 266 281 267 282 /// … … 346 361 /// 347 362 /// The assignment operator. There is no requirements on 348 /// dimensions. 363 /// dimensions, i.e. the matrix is remapped in memory if 364 /// necessary. This implies that in general views cannot be 365 /// assigned using this operator. Views will be mutated into 366 /// normal matrices. The only exception to this behaviour on views 367 /// is when self-assignemnt is done, since self-assignment is 368 /// ignored. 369 /// 370 /// @return A const reference to the resulting matrix. 371 /// 372 /// @see int set(const matrix&) 349 373 /// 350 374 const matrix& operator=(const matrix& other); … … 389 413 /// @return A pointer to a copy of the internal GSL matrix. 390 414 /// 391 gsl_matrix* gsl_matrix_copy(void) const;415 gsl_matrix* create_gsl_matrix_copy(void) const; 392 416 393 417 gsl_matrix* m_; -
branches/better_matrix_class/lib/gslapi/vector.cc
r413 r415 44 44 : const_view_(NULL) 45 45 { 46 view_ =new gsl_vector_view(row ?47 gsl_matrix_row (m.gsl_matrix_pointer(),i) :48 gsl_matrix_column(m.gsl_matrix_pointer(),i));46 view_=new gsl_vector_view(row ? 47 gsl_matrix_row (m.gsl_matrix_p(),i) : 48 gsl_matrix_column(m.gsl_matrix_p(),i) ); 49 49 v_ = &(view_->vector); 50 50 } … … 56 56 { 57 57 const_view_ = new gsl_vector_const_view(row ? 58 gsl_matrix_const_row (m.gsl_matrix_pointer(),i) :59 gsl_matrix_const_column(m.gsl_matrix_pointer(),i) );58 gsl_matrix_const_row (m.gsl_matrix_p(),i) : 59 gsl_matrix_const_column(m.gsl_matrix_p(),i) ); 60 60 v_ = const_cast<gsl_vector*>(&(const_view_->vector)); 61 61 } … … 123 123 124 124 125 gsl_vector* vector:: gsl_vector_copy(void) const125 gsl_vector* vector::create_gsl_vector_copy(void) const 126 126 { 127 127 gsl_vector* vec = gsl_vector_alloc(size()); … … 166 166 for ( size_t i = 0; i < size(); ++i ) 167 167 res += other[i] * (*this)[i]; 168 return res;169 }170 171 172 173 vector vector::operator+(const vector &other) const174 {175 vector res(*this);176 gsl_vector_add(res.v_,other.v_);177 return res;178 }179 180 181 182 vector vector::operator-( const vector &other ) const183 {184 vector res( *this );185 gsl_vector_sub(res.v_,other.v_);186 168 return res; 187 169 } … … 204 186 { 205 187 if( this != &other ) { 206 if ( v_ ) 188 if (view_) 189 delete view_; 190 else if (const_view_) 191 delete const_view_; 192 else if ( v_ ) 207 193 gsl_vector_free( v_ ); 208 v_ = other. gsl_vector_copy();194 v_ = other.create_gsl_vector_copy(); 209 195 } 210 196 return *this; -
branches/better_matrix_class/lib/gslapi/vector.h
r413 r415 62 62 /// 63 63 inline vector(const vector& other) : view_(NULL), const_view_(NULL) 64 { v_ = other. gsl_vector_copy(); }64 { v_ = other.create_gsl_vector_copy(); } 65 65 66 66 /// … … 185 185 /// @return A const pointer to the internal GSL vector, 186 186 /// 187 // Jari, is this needed? 188 inline const gsl_vector* gsl_vector_pointer(void) const { return v_; } 187 inline const gsl_vector* gsl_vector_p(void) const { return v_; } 189 188 190 189 /// 191 190 /// @return A pointer to the internal GSL vector, 192 191 /// 193 // Jari, is this needed? 194 inline gsl_vector* TEMP_gsl_vector_pointer(void) { return v_; } 192 inline gsl_vector* gsl_vector_p(void) { return v_; } 195 193 196 194 /// … … 276 274 277 275 /// 276 /// Set element values to values in \a vec. This function is 277 /// needed for assignment of viewed elements. 278 /// 279 /// @return Whatever GSL returns. 280 /// 281 /// @note No check on size is done. 282 /// 283 /// @see const vector& operator=(const vector&) 284 /// 285 inline int set(const vector& vec) { return gsl_vector_memcpy(v_,vec.v_); } 286 287 /// 278 288 /// Set all elements to \a value. 279 289 /// … … 373 383 374 384 /// 375 /// Vector with scalar multiplication.376 ///377 /// @note This operator is not implemented!378 ///379 vector operator*(const double d) const;380 381 ///382 /// Vector addition.383 ///384 /// @return The resulting vector.385 ///386 vector operator+( const vector& other ) const;387 388 ///389 /// Vector subtraction.390 ///391 /// @return The resulting vector.392 ///393 vector operator-( const vector& other ) const;394 395 ///396 385 /// Comparison operator. Takes linear time. 397 386 /// … … 403 392 /// 404 393 /// The assignment operator. There is no requirements on 405 /// dimensions. 394 /// dimensions, i.e. the vector is remapped in memory if 395 /// necessary. This implies that in general views cannot be 396 /// assigned using this operator. Views will be mutated into 397 /// normal vectors. The only exception to this behaviour on views 398 /// is when self-assignemnt is done, since self-assignment is 399 /// ignored. 406 400 /// 407 401 /// @return A const reference to the resulting vector. 402 /// 403 /// @see int set(const vector&) 408 404 /// 409 405 const vector& operator=(const vector&); … … 444 440 /// @return A pointer to a copy of the internal GSL vector. 445 441 /// 446 gsl_vector* gsl_vector_copy(void) const;442 gsl_vector* create_gsl_vector_copy(void) const; 447 443 448 444 gsl_vector* v_; -
branches/better_matrix_class/lib/statistics/Averager.cc
r295 r415 11 11 12 12 13 Averager::Averager(void)14 : n_(0), x_(0), xx_(0)15 {16 }17 18 Averager::Averager(const double x,const double xx,const long n)19 : n_(n), x_(x), xx_(xx)20 {21 }22 23 Averager::Averager(const Averager& a)24 : n_(a.n_), x_(a.x_), xx_(a.xx_)25 {26 }27 28 13 const Averager& Averager::operator+=(const Averager& a) 29 14 { … … 34 19 } 35 20 21 36 22 }} // of namespace statistics and namespace theplu -
branches/better_matrix_class/lib/statistics/Averager.h
r349 r415 26 26 /// Default constructor 27 27 /// 28 Averager(void);28 inline Averager(void) : n_(0), x_(0), xx_(0) {} 29 29 30 30 /// … … 32 32 /// number of samples \a n. 33 33 /// 34 Averager(const double x, const double xx, const long n); 34 inline Averager(const double x,const double xx,const long n) 35 : n_(n), x_(x), xx_(xx) {} 35 36 36 37 /// 37 38 /// Copy constructor 38 39 /// 39 Averager(const Averager&);40 40 inline Averager(const Averager& a) : n_(a.n_), x_(a.x_), xx_(a.xx_) {} 41 41 42 /// 42 43 /// Adding \a n (default=1) number of data point(s) with value \a d. 43 44 /// 44 inline void add(const double d,const long n=1) 45 {n_+=n; x_+=n*d; xx_+=n*d*d;} 45 inline void add(const double d,const long n=1) { n_+=n; x_+=n*d; xx_+=n*d*d;} 46 46 47 47 /// -
branches/better_matrix_class/lib/statistics/AveragerPair.cc
r295 r415 10 10 11 11 12 AveragerPair::AveragerPair(void)13 : x_(Averager()), y_(Averager()), xy_(0.0)14 {15 }16 17 AveragerPair::AveragerPair(const double x, const double xx, const double y,18 const double yy, const double xy, const long n)19 : x_(Averager(x,xx,n)), y_(Averager(y,yy,n)), xy_(xy)20 {21 }22 23 AveragerPair::AveragerPair(const AveragerPair& a)24 : x_(a.x_averager()), y_(a.y_averager()), xy_(a.sum_xy())25 {26 }27 28 12 const AveragerPair& AveragerPair::operator+=(const AveragerPair& a) 29 13 { … … 34 18 } 35 19 20 36 21 }} // of namespace statistics and namespace theplu -
branches/better_matrix_class/lib/statistics/AveragerPair.h
r355 r415 25 25 /// Default constructor 26 26 /// 27 AveragerPair(void);27 inline AveragerPair(void) : x_(Averager()), y_(Averager()), xy_(0.0) {} 28 28 29 29 /// … … 31 31 /// number of pair of values \a n 32 32 /// 33 AveragerPair(const double x, const double xx, const double y, 34 const double yy, const double xy, const long); 33 inline AveragerPair(const double x, const double xx, const double y, 34 const double yy, const double xy, const long n) 35 : x_(Averager(x,xx,n)), y_(Averager(y,yy,n)), xy_(xy) {} 35 36 36 37 /// 37 38 /// Copy constructor 38 39 /// 39 AveragerPair(const AveragerPair&); 40 inline AveragerPair(const AveragerPair& a) 41 : x_(a.x_averager()), y_(a.y_averager()), xy_(a.sum_xy()) {} 40 42 41 43 /// -
branches/better_matrix_class/lib/statistics/AveragerWeighted.cc
r397 r415 11 11 12 12 13 AveragerWeighted::AveragerWeighted(void)14 : w_(Averager()), wx_(Averager()), wwx_(0), wxx_(0)15 {16 }17 18 AveragerWeighted::AveragerWeighted(const AveragerWeighted& a)19 : w_(Averager(a.sum_w(),a.sum_ww(),1)),20 wx_(Averager(a.sum_wx(),a.sum_wwxx(),1)),21 wwx_(a.sum_wwx()),22 wxx_(a.sum_wxx())23 {24 }25 26 13 AveragerWeighted AveragerWeighted::operator+=(const AveragerWeighted& a) 27 14 { -
branches/better_matrix_class/lib/statistics/AveragerWeighted.h
r400 r415 33 33 /// 34 34 /// Default constructor 35 /// 36 AveragerWeighted(void); 35 /// 36 inline AveragerWeighted(void) 37 : w_(Averager()), wx_(Averager()), wwx_(0), wxx_(0) {} 37 38 38 39 /// 39 40 /// Copy constructor 40 41 /// 41 AveragerWeighted(const AveragerWeighted&); 42 inline AveragerWeighted(const AveragerWeighted& a) 43 : w_(Averager(a.sum_w(),a.sum_ww(),1)), 44 wx_(Averager(a.sum_wx(),a.sum_wwxx(),1)), wwx_(a.sum_wwx()), 45 wxx_(a.sum_wxx()) {} 42 46 43 47 /// -
branches/better_matrix_class/lib/statistics/Linear.h
r389 r415 32 32 /// Destructor 33 33 /// 34 virtual ~Linear(void) {};34 inline virtual ~Linear(void) {}; 35 35 36 36 /// -
branches/better_matrix_class/lib/statistics/MultiDimensional.cc
r386 r415 10 10 11 11 12 MultiDimensional::~MultiDimensional(void)13 {14 if (work_)15 gsl_multifit_linear_free(work_);16 }17 18 19 20 12 void MultiDimensional::fit(const gslapi::matrix& x, const gslapi::vector& y) 21 13 { … … 25 17 gsl_multifit_linear_free(work_); 26 18 work_=gsl_multifit_linear_alloc(x.rows(),fit_parameters_.size()); 27 gsl_multifit_linear(x.gsl_matrix_p ointer(),y.gsl_vector_pointer(),28 fit_parameters_. TEMP_gsl_vector_pointer(),29 covariance_.gsl_matrix_p ointer(),&chisquare_,work_);19 gsl_multifit_linear(x.gsl_matrix_p(),y.gsl_vector_p(), 20 fit_parameters_.gsl_vector_p(), 21 covariance_.gsl_matrix_p(),&chisquare_,work_); 30 22 } 31 23 -
branches/better_matrix_class/lib/statistics/MultiDimensional.h
r389 r415 29 29 /// @brief Destructor 30 30 /// 31 ~MultiDimensional(void);31 inline ~MultiDimensional(void) { if (work_) gsl_multifit_linear_free(work_);} 32 32 33 33 /// -
branches/better_matrix_class/lib/utility/SVD.cc
r413 r415 29 29 { 30 30 gslapi::vector w(U_.columns()); 31 return gsl_linalg_SV_decomp(U_.gsl_matrix_pointer(), 32 V_.gsl_matrix_pointer(), 33 s_.TEMP_gsl_vector_pointer(), 34 w.TEMP_gsl_vector_pointer()); 31 return gsl_linalg_SV_decomp(U_.gsl_matrix_p(), V_.gsl_matrix_p(), 32 s_.gsl_vector_p(), w.gsl_vector_p()); 35 33 } 36 34 … … 41 39 gslapi::vector w(U_.columns()); 42 40 gslapi::matrix X(U_.columns(),U_.columns()); 43 return gsl_linalg_SV_decomp_mod(U_.gsl_matrix_pointer(), 44 X.gsl_matrix_pointer(), 45 V_.gsl_matrix_pointer(), 46 s_.TEMP_gsl_vector_pointer(), 47 w.TEMP_gsl_vector_pointer()); 41 return gsl_linalg_SV_decomp_mod(U_.gsl_matrix_p(), X.gsl_matrix_p(), 42 V_.gsl_matrix_p(), s_.gsl_vector_p(), 43 w.gsl_vector_p()); 48 44 } 49 45 -
branches/better_matrix_class/lib/utility/SVD.h
r413 r415 84 84 /// 85 85 inline int solve(gslapi::vector b, gslapi::vector x) 86 { return gsl_linalg_SV_solve(U_.gsl_matrix_pointer(), 87 V_.gsl_matrix_pointer(), 88 s_.gsl_vector_pointer(), 89 b.gsl_vector_pointer(), 90 x.TEMP_gsl_vector_pointer()); 91 } 86 { return gsl_linalg_SV_solve(U_.gsl_matrix_p(), V_.gsl_matrix_p(), 87 s_.gsl_vector_p(), b.gsl_vector_p(), 88 x.gsl_vector_p()); } 92 89 93 90 /// … … 113 110 private: 114 111 inline int jacobi(void) 115 { return gsl_linalg_SV_decomp_jacobi(U_.gsl_matrix_pointer(), 116 V_.gsl_matrix_pointer(), 117 s_.TEMP_gsl_vector_pointer()); 118 } 112 { return gsl_linalg_SV_decomp_jacobi(U_.gsl_matrix_p(), V_.gsl_matrix_p(), 113 s_.gsl_vector_p()); } 119 114 int golub_reinsch(void); 120 115 int modified_golub_reinsch(void); -
branches/better_matrix_class/test/svm_test.cc
r337 r415 82 82 83 83 // Comparing alpha to alpha_matlab 84 theplu::gslapi::vector diff_alpha = alpha - alpha_matlab; 84 theplu::gslapi::vector diff_alpha(alpha); 85 diff_alpha-=alpha_matlab; 85 86 if (diff_alpha*diff_alpha> 1e-10 ){ 86 87 if (print) … … 90 91 91 92 // Comparing output to target 92 theplu::gslapi::vector output = svm.output();93 theplu::gslapi::vector output(svm.output()); 93 94 double slack = 0; 94 95 for (unsigned int i=0; i<target.size(); i++){
Note: See TracChangeset
for help on using the changeset viewer.