- Timestamp:
- Nov 27, 2005, 11:39:19 PM (17 years ago)
- Location:
- branches/better_matrix_class/lib/gslapi
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/better_matrix_class/lib/gslapi/vector.cc
r357 r406 4 4 #include <c++_tools/utility/stl_utility.h> 5 5 6 #include <iostream>7 6 #include <sstream> 8 #include <string>9 7 #include <vector> 10 8 #include <utility> … … 35 33 : view_(NULL) 36 34 { 37 v_ = other. TEMP_gsl_vector_copy();35 v_ = other.gsl_vector_copy(); 38 36 } 39 37 … … 49 47 50 48 49 /* Jari, remove this? 51 50 vector::vector(gsl_vector* vec) 52 51 : v_(vec), view_(NULL) 53 52 { 54 53 } 54 */ 55 55 56 56 … … 79 79 << ") and columns (" << nof_columns 80 80 << ").\n Expected a row or a column vector."; 81 std::string m=s.str(); 82 throw utility::IO_error(m); 81 throw utility::IO_error(s.str()); 83 82 } 84 else if (v.size()!=nof_columns) {83 else if (v.size()!=nof_columns) { 85 84 std::ostringstream s; 86 85 s << "vector::vector(std::istream&) data file error:\n" 87 86 << " Line " << (nof_rows+1) << " has " << v.size() 88 87 << " columns; expected " << nof_columns << " column."; 89 std::string m=s.str(); 90 throw utility::IO_error(m); 88 throw utility::IO_error(s.str()); 91 89 } 92 90 data_matrix.push_back(v); … … 116 114 117 115 118 gsl_vector* vector:: TEMP_gsl_vector_copy(void) const116 gsl_vector* vector::gsl_vector_copy(void) const 119 117 { 120 118 gsl_vector* vec = gsl_vector_alloc(size()); … … 199 197 if ( v_ ) 200 198 gsl_vector_free( v_ ); 201 v_ = other. TEMP_gsl_vector_copy();199 v_ = other.gsl_vector_copy(); 202 200 } 203 201 return *this; -
branches/better_matrix_class/lib/gslapi/vector.h
r357 r406 1 1 // $Id$ 2 2 3 #ifndef _theplu_gslapi_vector_ 3 #ifndef _theplu_gslapi_vector_ 4 4 #define _theplu_gslapi_vector_ 5 6 #include <c++_tools/utility/Exception.h> 5 7 6 8 #include <iostream> … … 9 11 10 12 #include <gsl/gsl_vector.h> 11 #include <c++_tools/utility/Exception.h>12 13 13 14 namespace theplu { … … 25 26 /// \par[Vector views] GSL vector views are supported and these are 26 27 /// disguised as ordinary gslapi::vectors. A support function is 27 /// added, gslapi::vector::is _view(), that can be used to check if28 /// the vector object is a view. Note that view vectors do not own29 /// the undelying data, and is not valid if the original vector is30 /// d eallocated.28 /// added, gslapi::vector::isview(), that can be used to check if a 29 /// vector object is a view. Note that view vectors do not own the 30 /// undelying data, and a view is not valid if the vector owning the 31 /// data is deallocated. 31 32 /// 32 33 class vector … … 63 64 /// is viewed. Also, using the copy constructor will create a new 64 65 /// vector object that is a copy of whatever is viewed. If a copy 65 /// of the view is needed the you should use this consturctor to66 /// of the view is needed then you should use this consturctor to 66 67 /// get one. 67 68 /// 68 69 /// @note If the object viewed by the view goes out of scope or is 69 /// deleted, the view becomes invalid. 70 /// 71 vector(vector& v, size_t offset, size_t n, size_t stride=1); 70 /// deleted, the view becomes invalid and the result of further 71 /// use is undefined. 72 /// 73 vector(vector& v, size_t offset, size_t n, size_t stride=1); 72 74 73 75 /// … … 75 77 /// by the created object. 76 78 /// 77 vector(gsl_vector*); 79 // Jari, remove this? 80 // vector(gsl_vector*); 78 81 79 82 /// … … 123 126 124 127 /// 125 /// Check if the vector object is a view (sub 128 /// Check if the vector object is a view (sub-vector) to another 126 129 /// vector. 127 130 /// 128 /// @return True if the object is a view, false othwerwise ;131 /// @return True if the object is a view, false othwerwise. 129 132 /// 130 133 inline bool isview(void) const { return view_; } … … 279 282 /// 280 283 // Jari, doxygen group as Accessing vector elements 281 inline const double& operator()(size_t i) const282 283 284 inline const double& 285 operator()(size_t i) const { return *gsl_vector_const_ptr(v_,i); } 286 284 287 /// 285 288 /// Element access operator. … … 296 299 /// 297 300 // Jari, doxygen group as Accessing vector elements 298 inline const double& operator[](size_t i) const299 300 301 inline const double& 302 operator[](size_t i) const { return *gsl_vector_const_ptr(v_,i); } 303 301 304 /// 302 305 /// @return The dot product. … … 309 312 /// @note This operator is not implemented! 310 313 /// 311 314 vector operator*(const double d) const; 312 315 313 316 /// … … 346 349 /// @return A const reference to the resulting vector. 347 350 /// 348 inline const vector& operator+=( const vector& other )349 { gsl_vector_add(v_,other.v_); return *this;}351 inline const vector& 352 operator+=(const vector& other) { gsl_vector_add(v_,other.v_); return *this;} 350 353 351 354 /// … … 354 357 /// @return A const reference to the resulting vector. 355 358 /// 356 inline const vector& operator-=( const vector& other )357 { gsl_vector_sub(v_,other.v_); return *this;}359 inline const vector& 360 operator-=(const vector& other) { gsl_vector_sub(v_,other.v_); return *this;} 358 361 359 362 /// … … 362 365 /// @return A const reference to the resulting vector. 363 366 /// 364 inline const vector& operator*=(const double d) 365 { gsl_vector_scale(v_,d); return *this; }366 367 368 367 inline const vector& 368 operator*=(const double d) { gsl_vector_scale(v_,d); return *this; } 369 370 371 private: 369 372 370 373 /// … … 376 379 /// @return A pointer to a copy of the internal GSL vector. 377 380 /// 378 gsl_vector* TEMP_gsl_vector_copy(void) const;379 380 381 gsl_vector* gsl_vector_copy(void) const; 382 383 gsl_vector* v_; 381 384 gsl_vector_view* view_; 382 385 }; 383 386 384 387 /// 385 388 /// The output operator for the vector class. 386 /// 389 /// 387 390 std::ostream& operator<<(std::ostream&, const vector& ); 388 391 … … 390 393 }} // of namespace gslapi and namespace theplu 391 394 392 #endif 395 #endif
Note: See TracChangeset
for help on using the changeset viewer.