9 #ifndef YAGE_MATH_MATRIX_HPP 10 #define YAGE_MATH_MATRIX_HPP 22 template<
int Rows,
int Cols,
class Type>
class Matrix;
32 template<
int Rows,
int Cols,
class Type>
class Row 40 parent_(parent), index_(index)
43 Type& operator[](
int col)
46 return parent_->data_[index_*Cols+col];
49 const Type& operator[](
int col)
const 51 return parent_->data_[index_*Cols+col];
61 template<
int Rows=4,
int Cols=4,
class Type=
double>
class Matrix 66 std::vector<Type> data_;
85 for(
int i=0; i<Cols; ++i)
87 rowMatrix[0][i]=data_[row][i];
96 for(
int i=0; i<Rows; ++i)
98 colMatrix[i][0]=data_[i][col];
104 typename std::vector<Type>::iterator begin()
106 return data_.begin();
110 typename std::vector<Type>::iterator end()
117 virtual std::string toString()
const 119 std::stringstream ss;
121 for(
int i=0; i<Rows-1; ++i)
124 for(
int j=0; j<Cols-1; ++j)
126 ss<<data_[i*Cols+j]<<
' ';
128 ss<<data_[(Rows-1)*Cols+Cols-1]<<
"],";
131 for(
int j=0; j<Cols-1; ++j)
133 ss<<data_[(Rows-1)*Cols+j]<<
' ';
135 ss<<data_[(Rows-1)*Cols+Cols-1]<<
"]]";
161 std::vector<Type> out;
162 out.reserve(data_.size());
163 std::transform(data_.begin(), data_.end(), rhs.data_.begin(), std::back_inserter(out),
164 [] (Type a, Type b) {
167 data_=std::move(out);
173 std::vector<Type> out;
174 out.reserve(data_.size());
175 std::transform(data_.begin(), data_.end(), rhs.begin(), std::back_inserter(out),
176 [] (Type a, Type b) {
179 data_=std::move(out);
184 template<
int M,
int N,
class T>
191 template<
int M,
int N,
class T>
198 template<
int M,
int N,
class T>
201 for(
auto &data : lhs)
208 template<
int M,
int N,
class T>
211 for(
auto &data : rhs)
218 template<
int M,
int N,
class T>
221 for(
auto &data : lhs)
228 template<
int M,
int N,
class T>
231 for(
auto &data : rhs)
238 template<
int M,
int N,
class T>
241 for(
auto &data : lhs)
248 template<
int M,
int N,
class T>
251 for(
auto &data : rhs)
258 template<
int M,
int N,
class T>
261 for(
auto &data : lhs)
268 template<
int M,
int N,
class T>
271 for(
int i=0; i<M; ++i)
272 for(
int j=0; j<N; ++j)
273 if(lhs[i][j]!=rhs[i][j])
278 template<
int M,
int N,
class T>
279 std::ostream& operator<<(std::ostream &os, const Matrix<M, N, T> &mat)
281 return os<<mat.toString();
284 template<
int Rows=2,
class Type=
double>
class Vector :
public Matrix<Rows, 1, Type>
290 Type& operator[](
int col)
292 return this->data_[col];
295 const Type& operator[](
int col)
const 297 return this->data_[col];
300 virtual std::string toString()
const 302 std::stringstream ss;
304 for(std::size_t i=0; i<this->data_.size()-1; ++i)
306 ss<<this->data_[i]<<
" ";
308 ss<<this->data_[this->data_.size()-1]<<
"]";
328 return this->data_[0];
331 const Type& x()
const 333 return this->data_[0];
338 return this->data_[1];
341 const Type& y()
const 343 return this->data_[1];
355 for(
int i=0; i<M; ++i)
357 for(
int j=0; j<N; ++j)
368 for(
int i=0; i<R; ++i)
370 sum += m1[i][0]*m2[i][0];
375 template<
int M,
int N,
int P,
int Q,
class T>
380 throw std::runtime_error(
"Matrices don't have the right dimensions for multiplication");
385 for(
int i=0; i<M; ++i)
387 for(
int j=0; j<Q; ++j)
389 res[i][j] = dot(transpose(m1.getRow(i)), m2.getCol(j));
Definition: matrix.hpp:313
Definition: matrix.hpp:32
Definition: matrix.hpp:284
Definition: matrix.hpp:22
Definition: camera2d.hpp:17