Changeset 2687
- Timestamp:
- Feb 27, 2012, 12:49:01 PM (11 years ago)
- Location:
- trunk/yat/utility
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/utility/Vector.cc
r2384 r2687 104 104 ss << "\nVector(std::istream&) data file error:\n" 105 105 << " File has inconsistent number of rows (" << nof_rows 106 << ") and columns (" << nof_columns 106 << ") and columns (" << nof_columns 107 107 << ").\n Expected a row or column Vector."; 108 108 throw IO_error(ss.str()); … … 117 117 // abort the program. 118 118 for (size_t i=0; i<nof_rows; i++) 119 for (size_t j=0; j<nof_columns; j++) 119 for (size_t j=0; j<nof_columns; j++) 120 120 gsl_vector_set( vec_, n++, data_matrix[i][j] ); 121 121 const_vec_ = vec_; … … 138 138 return *this; 139 139 } 140 // indirect self assignment if begin <= other.begin() < end 140 // indirect self assignment if begin <= other.begin() < end 141 141 if (begin() <= other.begin() && other.begin()<end()) { 142 142 if (size() != other.size()) { … … 146 146 } 147 147 return *this; 148 } 148 } 149 149 if (size()==other.size()){ 150 150 if (gsl_vector_memcpy(vec_, other.gsl_vector_p())) … … 157 157 const_vec_ = vec_; 158 158 return *this; 159 } 159 } 160 160 161 161 … … 184 184 185 185 186 void Vector::delete_allocated_memory(void) 186 void Vector::delete_allocated_memory(void) 187 187 { 188 188 if (vec_) … … 222 222 { 223 223 return assign(other); 224 } 224 } 225 225 226 226 -
trunk/yat/utility/Vector.h
r2119 r2687 45 45 46 46 /** 47 @brief This is the yat interface to GSL vector. 47 @brief This is the yat interface to GSL vector. 48 48 49 49 \par File streams: … … 68 68 \brief Allocates memory space for \a n elements, and sets all 69 69 elements to \a init_value. 70 70 71 71 \throw GSL_error if memory allocation fails. 72 72 */ … … 112 112 \return false 113 113 */ 114 bool isview(void) const; 114 bool isview(void) const; 115 115 116 116 /** -
trunk/yat/utility/VectorBase.cc
r2660 r2687 176 176 if (status) { 177 177 gsl_permutation_free(p); 178 throw utility::GSL_error(std::string("sort_index(vector&,const VectorBase&)",status)); 178 throw utility::GSL_error(std::string("sort_index(vector&,const VectorBase&)",status)); 179 179 } 180 180 std::vector<size_t> tmp(p->data,p->data+p->size); … … 184 184 185 185 186 void sort_smallest_index(std::vector<size_t>& sort_index, size_t k, 186 void sort_smallest_index(std::vector<size_t>& sort_index, size_t k, 187 187 const VectorBase& invec) 188 188 { … … 192 192 gsl_sort_vector_smallest_index(&sort_index[0],k,invec.gsl_vector_p()); 193 193 } 194 195 void sort_largest_index(std::vector<size_t>& sort_index, size_t k, 194 195 void sort_largest_index(std::vector<size_t>& sort_index, size_t k, 196 196 const VectorBase& invec) 197 197 { -
trunk/yat/utility/VectorBase.h
r2119 r2687 40 40 namespace yat { 41 41 namespace utility { 42 42 43 43 class matrix; 44 44 class Vector; 45 45 46 46 /** 47 @brief This is the yat interface to GSL vector. 47 @brief This is the yat interface to GSL vector. 48 48 49 49 This is an interface class for vectors containing the const … … 109 109 Check if the vector object is a view (sub-vector) to another 110 110 vector. 111 111 112 112 \return True if the object is a view, false othwerwise. 113 113 */ 114 virtual bool isview(void) const=0; 114 virtual bool isview(void) const=0; 115 115 116 116 /** … … 243 243 have been stored in that position if the VectorBase had been sorted 244 244 in place. The first element of \a sort_index gives the index of the least 245 element in \a invec, and the last element of \a sort_index gives the 246 index of the greatest element in \a invec . The VectorBase \a invec 245 element in \a invec, and the last element of \a sort_index gives the 246 index of the greatest element in \a invec . The VectorBase \a invec 247 247 is not changed. 248 248 … … 251 251 void sort_index(std::vector<size_t>& sort_index, const VectorBase& invec); 252 252 253 /** 253 /** 254 254 Similar to sort_index but creates a VectorBase with indices to 255 255 the \a k smallest elements in \a invec. … … 257 257 \relatesalso VectorBase 258 258 */ 259 void sort_smallest_index(std::vector<size_t>& sort_index, size_t k, 259 void sort_smallest_index(std::vector<size_t>& sort_index, size_t k, 260 260 const VectorBase& invec); 261 261 262 /** 262 /** 263 263 Similar to sort_index but creates a VectorBase with indices to 264 264 the \a k largest elements in \a invec. … … 266 266 \relatesalso VectorBase 267 267 */ 268 void sort_largest_index(std::vector<size_t>& sort_index, size_t k, 268 void sort_largest_index(std::vector<size_t>& sort_index, size_t k, 269 269 const VectorBase& invec); 270 270 … … 285 285 you, for example, want to print the VectorBase \a v with the 286 286 elements separated by a ':', you do so by: 287 \verbatim 288 s << setfill(':') << v; 287 \verbatim 288 s << setfill(':') << v; 289 289 \endverbatim 290 290 -
trunk/yat/utility/VectorConstView.cc
r2119 r2687 51 51 { 52 52 const_view_ = new gsl_vector_const_view( 53 gsl_vector_const_subvector_with_stride(v.gsl_vector_p(), 53 gsl_vector_const_subvector_with_stride(v.gsl_vector_p(), 54 54 offset, stride,n)); 55 55 const_vec_ = &(const_view_->vector); … … 60 60 : VectorBase(), const_view_(NULL) 61 61 { 62 const_view_ = 63 new gsl_vector_const_view(row ? 62 const_view_ = 63 new gsl_vector_const_view(row ? 64 64 gsl_matrix_const_row(m.gsl_matrix_p(),i) : 65 65 gsl_matrix_const_column(m.gsl_matrix_p(),i)); … … 76 76 void VectorConstView::copy(const VectorBase& other) 77 77 { 78 const_view_ = 79 new gsl_vector_const_view(gsl_vector_const_subvector(other.gsl_vector_p(), 78 const_view_ = 79 new gsl_vector_const_view(gsl_vector_const_subvector(other.gsl_vector_p(), 80 80 0, other.size())); 81 81 const_vec_ = &(const_view_->vector); -
trunk/yat/utility/VectorConstView.h
r2119 r2687 40 40 41 41 /** 42 @brief Read-only view. 42 @brief Read-only view. 43 43 44 Wrapper to gsl_vector_const_view 44 Wrapper to gsl_vector_const_view 45 45 46 46 With this class you can create a view into const 47 47 objects - either a vector or matrix. By design all functionality 48 48 in this class is const to guarantee that the viewed object is not 49 modified. 49 modified. 50 50 51 51 \note that view vectors do not own the underlying data, … … 64 64 /** 65 65 \brief Copy a VectorBase 66 */ 66 */ 67 67 explicit VectorConstView(const VectorBase& other); 68 68 … … 83 83 /** 84 84 \brief Matrix row/column view constructor. 85 86 Create a view into a row/column of a matrix. 85 86 Create a view into a row/column of a matrix. 87 87 88 88 \param m matrix to view into. … … 109 109 \return true 110 110 */ 111 bool isview(void) const; 111 bool isview(void) const; 112 112 113 113 private: … … 119 119 // because this pointer may be NULL. 120 120 gsl_vector_const_view* const_view_; 121 121 122 122 // assignment not allowed 123 123 VectorConstView& operator=(const VectorConstView&); -
trunk/yat/utility/VectorMutable.cc
r2384 r2687 91 91 { 92 92 if (vec_) 93 return iterator(&(this->operator()(0))+vec_->stride*size(), 93 return iterator(&(this->operator()(0))+vec_->stride*size(), 94 94 const_vec_->stride); 95 95 return iterator(NULL, 1); -
trunk/yat/utility/VectorMutable.h
r2121 r2687 31 31 #include "StrideIterator.h" 32 32 33 #include <gsl/gsl_vector.h> 34 33 35 #include <cstddef> // size_t 34 35 #include <gsl/gsl_vector.h>36 36 37 37 namespace theplu { … … 43 43 44 44 /** 45 @brief This is the mutable interface to GSL vector. 45 @brief This is the mutable interface to GSL vector. 46 46 47 47 This class contains the mutable interface to vector classes. … … 126 126 Check if the vector object is a view (sub-vector) to another 127 127 vector. 128 128 129 129 \return True if the object is a view, false othwerwise. 130 131 */ 132 virtual bool isview(void) const=0; 130 131 */ 132 virtual bool isview(void) const=0; 133 133 134 134 /** … … 226 226 Randomly shuffles the elements in VectorMutable \a invec 227 227 */ 228 void shuffle(VectorMutable& invec); 228 void shuffle(VectorMutable& invec); 229 229 230 230 /** -
trunk/yat/utility/VectorView.cc
r2119 r2687 44 44 : VectorMutable() 45 45 { 46 view_ = new gsl_vector_view(gsl_vector_subvector(other.gsl_vector_p(), 46 view_ = new gsl_vector_view(gsl_vector_subvector(other.gsl_vector_p(), 47 47 0, other.size())); 48 48 const_vec_ = vec_ = &(view_->vector); 49 49 50 50 } 51 51 … … 61 61 : VectorMutable() 62 62 { 63 view_ = 64 new gsl_vector_view(gsl_vector_subvector_with_stride(v.gsl_vector_p(), 63 view_ = 64 new gsl_vector_view(gsl_vector_subvector_with_stride(v.gsl_vector_p(), 65 65 offset, stride,n)); 66 66 const_vec_ = vec_ = &(view_->vector); … … 101 101 const_vec_ = vec_; 102 102 return *this; 103 } 103 } 104 104 105 105 … … 122 122 } 123 123 124 124 125 125 const VectorView& VectorView::operator=(const VectorBase& other ) 126 126 { … … 128 128 } 129 129 130 130 131 131 void VectorView::delete_allocated_memory(void) 132 132 { -
trunk/yat/utility/VectorView.h
r2119 r2687 40 40 41 41 /** 42 @brief This is the yat interface to gsl_vector_view. 42 @brief This is the yat interface to gsl_vector_view. 43 43 44 44 This class can be used to create a vector view into a Matrix or a … … 46 46 data, i.e., the Matrix or VectorMutable that is viewed into. For 47 47 that reason all constructors are taking non-const references to 48 disallow mutable views into a const objects. 48 disallow mutable views into a const objects. 49 49 50 50 The fact that there is no copy constructor with const argument, … … 93 93 underlying data (Vector or Matrix) is deallocated VectorView is 94 94 invalid. 95 */ 95 */ 96 96 VectorView(VectorView& other); 97 97 … … 128 128 /// A VectorView view can be used as any VectorMutable with the 129 129 /// difference that changes made to the view will also change the 130 /// object that is viewed. 130 /// object that is viewed. 131 131 /// 132 132 /// @note If the object viewed by the view goes out of scope or is … … 144 144 \return true 145 145 */ 146 bool isview(void) const; 146 bool isview(void) const; 147 147 148 148 /** … … 186 186 proxy. 187 187 */ 188 struct proxy 189 { 188 struct proxy 189 { 190 190 /// pointer to GSL vector keeping everything we need to create a 191 191 /// new VectorMutable from a proxy. … … 200 200 201 201 /** 202 conversion operator to private proxy class. 202 conversion operator to private proxy class. 203 203 */ 204 204 operator proxy();
Note: See TracChangeset
for help on using the changeset viewer.