- Timestamp:
- Dec 25, 2006, 1:53:13 AM (16 years ago)
- Location:
- trunk/yat/utility
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/utility/matrix.cc
r703 r716 154 154 155 155 156 int matrix::add(const matrix& b) 157 { 158 return gsl_matrix_add(m_, b.m_); 159 } 160 161 162 int matrix::add_constant(const double d) 163 { 164 return gsl_matrix_add_constant(m_, d); 165 } 166 167 168 size_t matrix::columns(void) const 169 { 170 return m_->size2; 171 } 172 173 174 gsl_matrix* matrix::create_gsl_matrix_copy(void) const 175 { 176 gsl_matrix* m = gsl_matrix_alloc(rows(),columns()); 177 gsl_matrix_memcpy(m,m_); // Jari, a GSL return value is ignored here 178 return m; 179 } 180 181 182 int matrix::div_elements(const matrix& b) 183 { 184 return gsl_matrix_div_elements(m_, b.m_); 185 } 186 156 187 157 188 bool matrix::equal(const matrix& other, const double d) const … … 169 200 170 201 171 172 gsl_matrix* matrix::create_gsl_matrix_copy(void) const 173 { 174 gsl_matrix* m = gsl_matrix_alloc(rows(),columns()); 175 gsl_matrix_memcpy(m,m_); // Jari, a GSL return value is ignored here 176 return m; 177 } 178 202 const gsl_matrix* matrix::gsl_matrix_p(void) const 203 { 204 return m_; 205 } 206 207 208 gsl_matrix* matrix::gsl_matrix_p(void) 209 { 210 return m_; 211 } 212 213 214 bool matrix::isnull(void) const 215 { 216 return gsl_matrix_isnull(m_); 217 } 218 219 220 bool matrix::isview(void) const 221 { 222 return view_; 223 } 224 225 226 double matrix::max(void) const 227 { 228 return gsl_matrix_max(m_); 229 } 230 231 232 double matrix::min(void) const 233 { 234 return gsl_matrix_min(m_); 235 } 236 237 238 void matrix::minmax_index(std::pair<size_t,size_t>& min, 239 std::pair<size_t,size_t>& max) const 240 { 241 gsl_matrix_minmax_index(m_, &min.first, &min.second, &max.first, 242 &max.second); 243 } 179 244 180 245 … … 193 258 194 259 260 int matrix::mul_elements(const matrix& b) 261 { 262 return gsl_matrix_mul_elements(m_, b.m_); 263 } 264 265 266 size_t matrix::rows(void) const 267 { 268 return m_->size1; 269 } 270 271 272 int matrix::scale(const double d) 273 { 274 return gsl_matrix_scale(m_, d); 275 } 276 277 278 int matrix::set(const matrix& mat) 279 { 280 return gsl_matrix_memcpy(m_, mat.m_); 281 } 282 283 284 void matrix::set_all(const double value) 285 { 286 gsl_matrix_set_all(m_, value); 287 } 288 289 290 int matrix::set_column(const size_t column, const vector& vec) 291 { 292 return gsl_matrix_set_col(m_, column, vec.gsl_vector_p()); 293 } 294 295 296 int matrix::set_row(const size_t row, const vector& vec) 297 { 298 return gsl_matrix_set_row(m_, row, vec.gsl_vector_p()); 299 } 300 301 302 int matrix::sub(const matrix& b) 303 { 304 return gsl_matrix_sub(m_, b.m_); 305 } 306 307 308 int matrix::swap(matrix& other) 309 { 310 return gsl_matrix_swap(m_, other.m_); 311 } 312 313 314 int matrix::swap_columns(const size_t i, const size_t j) 315 { 316 return gsl_matrix_swap_columns(m_, i, j); 317 } 318 319 320 int matrix::swap_rowcol(const size_t i, const size_t j) 321 { 322 return gsl_matrix_swap_rowcol(m_, i, j); 323 } 324 325 326 int matrix::swap_rows(const size_t i, const size_t j) 327 { 328 return gsl_matrix_swap_rows(m_, i, j); 329 } 330 195 331 196 332 // Jari, checkout GSL transpose support in GSL manual 8.4.9 … … 208 344 209 345 346 double& matrix::operator()(size_t row, size_t column) 347 { 348 return (*gsl_matrix_ptr(m_, row, column)); 349 } 350 351 352 const double& matrix::operator()(size_t row, size_t column) const 353 { 354 return (*gsl_matrix_const_ptr(m_, row, column)); 355 } 356 210 357 211 358 const vector matrix::operator*(const vector&) const … … 217 364 } 218 365 366 367 bool matrix::operator==(const matrix& other) const 368 { 369 return equal(other); 370 } 371 372 373 bool matrix::operator!=(const matrix& other) const 374 { 375 return !equal(other); 376 } 219 377 220 378 … … 285 443 } 286 444 287 288 445 }}} // of namespace utility, yat and thep -
trunk/yat/utility/matrix.h
r703 r716 33 33 #include <gsl/gsl_matrix.h> 34 34 #include <iostream> 35 #include <utility> 35 36 36 37 namespace theplu { … … 144 145 /// @return Whatever GSL returns. 145 146 /// 146 in line int add(const matrix& b) { return gsl_matrix_add(m_,b.m_); }147 int add(const matrix& b); 147 148 148 149 /// … … 153 154 /// @return Whatever GSL returns. 154 155 /// 155 inline int 156 add_constant(const double d) { return gsl_matrix_add_constant(m_,d); } 156 int add_constant(const double d); 157 157 158 158 /// 159 159 /// @return The number of columns in the matrix. 160 160 /// 161 inline size_t columns(void) const { return m_->size2; }161 size_t columns(void) const; 162 162 163 163 /// … … 168 168 /// @return Whatever GSL returns. 169 169 /// 170 inline int 171 div_elements(const matrix& b) { return gsl_matrix_div_elements(m_,b.m_); } 170 int div_elements(const matrix& b); 172 171 173 172 /// … … 183 182 /// @return A const pointer to the internal GSL matrix. 184 183 /// 185 inline const gsl_matrix* gsl_matrix_p(void) const { return m_; }184 const gsl_matrix* gsl_matrix_p(void) const; 186 185 187 186 /// … … 189 188 /// 190 189 // Jari, is this needed? 191 inline gsl_matrix* gsl_matrix_p(void) { return m_; };190 gsl_matrix* gsl_matrix_p(void); 192 191 193 192 /// … … 195 194 /// othwerwise; 196 195 /// 197 inline bool isnull(void) const { return gsl_matrix_isnull(m_); }196 bool isnull(void) const; 198 197 199 198 /// … … 203 202 /// @return True if the object is a view, false othwerwise. 204 203 /// 205 inline bool isview(void) const { return view_; }204 bool isview(void) const; 206 205 207 206 /// 208 207 /// @return The maximum value of the matrix. 209 208 /// 210 inline double max(void) const { return gsl_matrix_max(m_); }209 double max(void) const; 211 210 212 211 /// … … 220 219 /// @return The minimum value of the matrix. 221 220 /// 222 inline double min(void) const { return gsl_matrix_min(m_); }221 double min(void) const; 223 222 224 223 /// … … 234 233 /// has precedence (searching in row-major order). 235 234 /// 236 inline void minmax_index(std::pair<size_t,size_t>& min, 237 std::pair<size_t,size_t>& max) const 238 { gsl_matrix_minmax_index(m_,&min.first,&min.second, 239 &max.first,&max.second); } 235 void minmax_index(std::pair<size_t,size_t>& min, 236 std::pair<size_t,size_t>& max) const; 240 237 241 238 /// … … 262 259 /// @return Whatever GSL returns. 263 260 /// 264 in line int265 mul_elements(const matrix& b) { return gsl_matrix_mul_elements(m_,b.m_); }261 int 262 mul_elements(const matrix& b); 266 263 267 264 /// 268 265 /// @return The number of rows in the matrix. 269 266 /// 270 inline size_t rows(void) const { return m_->size1; }267 size_t rows(void) const; 271 268 272 269 /// … … 277 274 /// @return Whatever GSL returns. 278 275 /// 279 in line int scale(const double d) { return gsl_matrix_scale(m_,d); }276 int scale(const double d); 280 277 281 278 /// … … 289 286 /// @see const matrix& operator=(const matrix&) 290 287 /// 291 in line int set(const matrix& mat) { return gsl_matrix_memcpy(m_,mat.m_); }288 int set(const matrix& mat); 292 289 293 290 /// 294 291 /// Set all elements to \a value. 295 292 /// 296 inline void set_all(const double value) { gsl_matrix_set_all(m_,value); }293 void set_all(const double value); 297 294 298 295 /// … … 303 300 /// @note No check on size is done. 304 301 /// 305 inline int set_column(const size_t column, const vector& vec) 306 { return gsl_matrix_set_col(m_, column, vec.gsl_vector_p()); } 302 int set_column(const size_t column, const vector& vec); 307 303 308 304 /// … … 313 309 /// @note No check on size is done. 314 310 /// 315 inline int set_row(const size_t row, const vector& vec) 316 { return gsl_matrix_set_row(m_, row, vec.gsl_vector_p()); } 311 int set_row(const size_t row, const vector& vec); 317 312 318 313 /// … … 323 318 /// @return Whatever GSL returns. 324 319 /// 325 in line int sub(const matrix& b) { return gsl_matrix_sub(m_,b.m_); }320 int sub(const matrix& b); 326 321 327 322 /// … … 331 326 /// @return Whatever GSL returns. 332 327 /// 333 in line int swap(matrix& other) { return gsl_matrix_swap(m_,other.m_); }328 int swap(matrix& other); 334 329 335 330 /// 336 331 /// @brief Swap columns \a i and \a j. 337 332 /// 338 inline int swap_columns(const size_t i,const size_t j) 339 { return gsl_matrix_swap_columns(m_,i,j); } 333 int swap_columns(const size_t i,const size_t j); 340 334 341 335 /// 342 336 /// @brief Swap row \a i and column \a j. 343 337 /// 344 inline int swap_rowcol(const size_t i,const size_t j) 345 { return gsl_matrix_swap_rowcol(m_,i,j); } 338 int swap_rowcol(const size_t i,const size_t j); 346 339 347 340 /// 348 341 /// @brief Swap rows \a i and \a j. 349 342 /// 350 inline int swap_rows(const size_t i, const size_t j) 351 { return gsl_matrix_swap_rows(m_,i,j); } 343 int swap_rows(const size_t i, const size_t j); 352 344 353 345 /// … … 359 351 /// @return Reference to the element position (\a row, \a column). 360 352 /// 361 inline double& operator()(size_t row,size_t column) 362 { return (*gsl_matrix_ptr(m_,row,column)); } 353 double& operator()(size_t row,size_t column); 363 354 364 355 /// … … 366 357 /// column). 367 358 /// 368 inline const double& operator()(size_t row,size_t column) const 369 { return (*gsl_matrix_const_ptr(m_,row,column)); } 359 const double& operator()(size_t row,size_t column) const; 370 360 371 361 /// … … 384 374 /// @see equal 385 375 /// 386 inline bool operator==(const matrix& other) const { return equal(other); }376 bool operator==(const matrix& other) const; 387 377 388 378 /// … … 393 383 /// @see equal 394 384 /// 395 inline bool operator!=(const matrix& other) const { return !equal(other); }385 bool operator!=(const matrix& other) const; 396 386 397 387 ///
Note: See TracChangeset
for help on using the changeset viewer.