Changeset 4141
- Timestamp:
- Feb 1, 2022, 6:11:36 AM (20 months ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/matrix_view.cc
r4137 r4141 219 219 test_iterators<MatrixView>(suite, m); 220 220 MatrixView view = make_view(m); 221 221 222 } 222 223 … … 242 243 243 244 MatrixConstView view = make_const_view(m); 244 } 245 246 std::vector<double> vec(100,0); 247 for (size_t i=0; i<vec.size(); ++i) 248 vec[i] = i; 249 utility::Matrix correct(4, 5); 250 for (size_t i=0; i<correct.rows(); ++i) 251 for (size_t j=0; j<correct.columns(); ++j) 252 correct(i,j) = 5*i + j; 253 MatrixConstView view2(&vec.front(), 4, 5); 254 if (!suite.equal_matrix(view2, correct)) { 255 suite.add(false); 256 suite.err() << "error: view2 not equal correct\n"; 257 suite.err() << "view2:\n" << view2 << "\ncorrect:\n" << correct << "\n"; 258 } 259 260 size_t tda = 10; 261 MatrixConstView view3(&vec.front(), 4, 5, tda); 262 for (size_t i=0; i<correct.rows(); ++i) 263 for (size_t j=0; j<correct.columns(); ++j) 264 correct(i,j) = tda*i + j; 265 if (!suite.equal_matrix(view3, correct)) { 266 suite.add(false); 267 suite.err() << "error: view3 not equal correct\n"; 268 suite.err() << "view3:\n" << view3 << "\ncorrect:\n" << correct << "\n"; 269 } 270 271 MatrixConstView view4(correct.gsl_matrix_p()); 272 if (!suite.equal_matrix(view4, correct)) { 273 suite.add(false); 274 suite.err() << "error: view4 not equal correct\n"; 275 suite.err() << "view4:\n" << view4 << "\ncorrect:\n" << correct << "\n"; 276 } 277 } -
trunk/test/view.cc
r3661 r4141 40 40 41 41 int main(int argc, char* argv[]) 42 { 42 { 43 43 using namespace theplu::yat::utility; 44 44 theplu::yat::test::Suite suite(argc, argv); … … 132 132 suite.add(false); 133 133 } 134 135 134 test_rvalue(suite); 135 136 // test view from double* or gsl_vector* 137 std::vector<double> vec(100,0); 138 VectorView view2(&vec.front(), 5); 139 VectorConstView cview2(&vec.front(), 5); 140 if (view2.size() != 5) { 141 suite.err() << "error: view2 incorrect dimensions\n"; 142 suite.add(false); 143 } 144 else { 145 for (size_t i=0; i<view2.size(); ++i) { 146 double x = 12*i; 147 view2(i) = x; 148 if (vec[i] != x) { 149 suite.add(false); 150 } 151 } 152 } 153 if (view2 != cview2) { 154 suite.err() << "error: view2 != cview2\n"; 155 suite.add(false); 156 } 157 158 size_t stride = 3; 159 VectorView view3(&vec.front(), 5, stride); 160 VectorConstView cview3(&vec.front(), 5, stride); 161 if (view3.size() != 5) { 162 suite.err() << "error: view3 incorrect dimensions\n"; 163 suite.add(false); 164 } 165 else { 166 for (size_t i=0; i<view3.size(); ++i) { 167 double x = 12*i; 168 view3(i) = x; 169 if (vec[stride*i] != x) { 170 suite.add(false); 171 } 172 } 173 } 174 if (view3 != cview3) { 175 suite.err() << "error: view3 != cview3\n"; 176 suite.add(false); 177 } 178 179 Vector v(5); 180 gsl_vector* p = v.gsl_vector_p(); 181 const gsl_vector* cp = v.gsl_vector_p(); 182 VectorView view4(p); 183 VectorConstView cview4(cp); 184 view4(0) = 3.12; 185 view4(3) = 4.28; 186 if (view4 != v) { 187 suite.add(false); 188 suite.err() << "error: v not equal view4\n"; 189 } 190 if (view4 != cview4) { 191 suite.err() << "error: view4 != cview4\n"; 192 suite.add(false); 193 } 136 194 137 195 return suite.return_value(); -
trunk/yat/utility/Matrix.h
r4140 r4141 100 100 /// most functionality defined for GSL matrices can be achieved with 101 101 /// this interface class. Most notable GSL functionality not 102 /// supported are no binary file support and views on arrays, 103 /// utility::vectors, gsl_vectors, diagonals, subdiagonals, and 104 /// superdiagonals. 102 /// supported are no binary file support. 105 103 /// 106 104 class Matrix : public MatrixMutable -
trunk/yat/utility/MatrixConstView.cc
r4129 r4141 59 59 60 60 61 MatrixConstView::MatrixConstView(const gsl_matrix* m) 62 : view_(nullptr) 63 { 64 copy(m); 65 } 66 67 68 MatrixConstView::MatrixConstView(const double* p, size_t rows, size_t cols) 69 : view_(nullptr) 70 { 71 assert(p); 72 assert(rows); 73 assert(cols); 74 view_ = 75 new gsl_matrix_const_view(gsl_matrix_const_view_array(p, rows, cols)); 76 } 77 78 79 MatrixConstView::MatrixConstView(const double* p, size_t rows, 80 size_t cols, size_t tda) 81 : view_(nullptr) 82 { 83 assert(p); 84 assert(rows); 85 assert(cols); 86 assert(tda >= cols); 87 view_ = 88 new gsl_matrix_const_view(gsl_matrix_const_view_array_with_tda(p, rows, 89 cols, 90 tda)); 91 } 92 93 61 94 MatrixConstView::~MatrixConstView(void) 62 95 { -
trunk/yat/utility/MatrixConstView.h
r4129 r4141 69 69 70 70 /** 71 Create a view into \c m. 72 */ 73 explicit MatrixConstView(const gsl_matrix* m); 74 75 /** 76 Create a view with \c rows rows and \c cols columns. Data are 77 stored in row-major order such that p[1] correspond to 78 view(0,1). 79 */ 80 MatrixConstView(const double* p, size_t rows, size_t cols); 81 82 /** 83 Create a view with \c rows rows and \c cols columns. The 84 physical row dimension is \c tda, i.e., the first element on 85 the second row is p[tda]. 86 */ 87 MatrixConstView(const double* p, size_t rows, size_t cols, size_t tda); 88 89 /** 71 90 \brief Destructor 72 91 */ -
trunk/yat/utility/MatrixView.cc
r4137 r4141 57 57 { 58 58 copy(other.gsl_matrix_p(), row_offset, col_offset, rows, columns); 59 } 60 61 62 MatrixView::MatrixView(gsl_matrix* m) 63 { 64 assert(0); 65 } 66 67 68 MatrixView::MatrixView(double* p, size_t rows, size_t cols) 69 { 70 assert(0); 71 } 72 73 74 MatrixView::MatrixView(double* p, size_t rows, size_t cols, size_t tda) 75 { 76 assert(0); 59 77 } 60 78 -
trunk/yat/utility/MatrixView.h
r4137 r4141 85 85 86 86 /** 87 Create a view into \c m. 88 */ 89 explicit MatrixView(gsl_matrix* m); 90 91 /** 92 Create a view with \c rows rows and \c cols columns. Data are 93 stored in row-major order such that p[1] correspond to 94 view(0,1). 95 */ 96 MatrixView(double* p, size_t rows, size_t cols); 97 98 /** 99 Create a view with \c rows rows and \c cols columns. The 100 physical row dimension is \c tda, i.e., the first element on 101 the second row is p[tda]. 102 */ 103 MatrixView(double* p, size_t rows, size_t cols, size_t tda); 104 105 /** 87 106 \brief Destructor 88 107 */ -
trunk/yat/utility/VectorConstView.cc
r4119 r4141 29 29 #include "MatrixBase.h" 30 30 #include "VectorView.h" 31 32 #include <cassert> 31 33 32 34 namespace theplu { … … 78 80 79 81 82 VectorConstView::VectorConstView(const gsl_vector* v) 83 { 84 const_view_ = 85 new gsl_vector_const_view(gsl_vector_const_subvector(v, 0, v->size)); 86 const_vec_ = &(const_view_->vector); 87 } 88 89 90 VectorConstView::VectorConstView(const double* v, size_t size, size_t stride) 91 { 92 const_view_ = 93 new gsl_vector_const_view(gsl_vector_const_view_array_with_stride(v, 94 stride, 95 size)); 96 const_vec_ = &(const_view_->vector); 97 } 98 99 80 100 VectorConstView::~VectorConstView(void) 81 101 { -
trunk/yat/utility/VectorConstView.h
r4119 r4141 113 113 114 114 /** 115 Create a view into \c v 116 117 \since New in yat 0.20 118 */ 119 explicit VectorConstView(const gsl_vector* v); 120 121 /** 122 Create a view with size \c size and stride \c stride such that 123 view(0) = v[0] and view(1) = v[stride]. 124 125 \since New in yat 0.20 126 */ 127 VectorConstView(const double* v, size_t size, size_t stride=1); 128 129 /** 115 130 The destructor. 116 131 */ -
trunk/yat/utility/VectorView.cc
r4119 r4141 83 83 { 84 84 copy(p.vec_); 85 } 86 87 88 VectorView::VectorView(gsl_vector* v) 89 { 90 copy(v); 91 } 92 93 94 VectorView::VectorView(double* v, size_t size, size_t stride) 95 { 96 assert(v); 97 assert(size); 98 assert(stride); 99 view_ = 100 new gsl_vector_view(gsl_vector_view_array_with_stride(v, stride, size)); 101 const_vec_ = vec_ = &(view_->vector); 85 102 } 86 103 -
trunk/yat/utility/VectorView.h
r4119 r4141 137 137 VectorView(MatrixMutable& m, size_t i, bool row=true); 138 138 139 /** 140 Create a view into \c v 141 142 \since New in yat 0.20 143 */ 144 explicit VectorView(gsl_vector* v); 145 146 /** 147 Create a view with size \c size and stride \c stride such that 148 view(0) = v[0] and view(1) = v[stride]. 149 150 \since New in yat 0.20 151 */ 152 VectorView(double* v, size_t size, size_t stride=1); 153 139 154 /// 140 155 /// The destructor.
Note: See TracChangeset
for help on using the changeset viewer.