25 #ifndef FIBER_MATRIX_H_
26 #define FIBER_MATRIX_H_
31 template <
typename Scalar,
int Rows,
int Cols>
33 public _RValue<Scalar, Matrix<Scalar, Rows, Cols> > {
60 assert(i <
Rows && j < Cols);
61 return data_[i * Cols + j];
65 assert(i <
Rows && j < Cols);
66 return data_[i * Cols + j];
73 template <
typename Exp>
75 static_assert(Exp::ROWS_ ==
ROWS_ && Exp::COLS_ ==
COLS_,
76 "Cannot construct a matrix from a matrix of a differnt size");
78 for (
int i = 0; i <
ROWS_; i++) {
79 for (
int j = 0; j <
COLS_; j++) {
80 (*this)(i, j) = exp(i, j);
85 #ifdef FIBER_USE_VARIADIC_TEMPLATES
89 template <
int Index,
typename... Tail>2
90 void BulkAssign(Scalar head, Tail... tail) {
91 static_assert(
Index <
Rows * Cols,
"Too many inputs to BulkAssign!");
92 (*this)[
Index] = head;
93 BulkAssign<Index + 1>(tail...);
98 template <
typename... Scalars>
99 Matrix(Scalar a, Scalar b, Scalars... scalars) {
100 BulkAssign<0>(a, b, scalars...);
105 Matrix(Scalar x0, Scalar x1, Scalar x2, Scalar x3) {
106 static_assert(
SIZE_ == 4,
107 "This constructor is only for size 4 matrices");
115 Matrix(Scalar x0, Scalar x1, Scalar x2) {
116 static_assert(
SIZE_ == 3,
117 "This constructor is only for size 3 matrices");
125 static_assert(
SIZE_ == 2,
126 "This constructor is only for size 2 matrices");
130 #endif // USE_VARIADIC_TEMPLATES
133 static_assert(
SIZE_ == 1,
134 "This constructor is only for size 1 matrices");
159 #endif // FIBER_MATRIX_H_
Matrix(const _RValue< Scalar, Exp > &exp)
Construct from any MatrixExpression:
Matrix< float, 4, 1 > Vector4f
Matrix< float, 2, 1 > Vector2f
Matrix< double, 4, 1 > Vector4d
Matrix(Scalar x0, Scalar x1, Scalar x2, Scalar x3)
Fixed size construction.
expression template for rvalues
Matrix< float, 4, 4 > Matrix4f
Matrix(Scalar x0, Scalar x1)
Fixed size construction.
Matrix< double, 3, 1 > Vector3d
Matrix< float, 2, 2 > Matrix2f
Matrix< float, 3, 3 > Matrix3f
Matrix(Scalar x0, Scalar x1, Scalar x2)
Fixed size construction.
Scalar & operator[](Index i)
Matrix< float, 3, 1 > Vector3f
Matrix< double, 2, 1 > Vector2d
LView< Scalar, Exp, rows, Exp::COLS_ > Rows(_LValue< Scalar, Exp > &A, int i)
expression template for rvalues
Scalar const & operator[](Index i) const
Scalar operator()(int i, int j) const
Matrix< double, 2, 2 > Matrix2d
Matrix()
Default constructor.
Matrix< double, 4, 4 > Matrix4d
Matrix< double, 3, 3 > Matrix3d
Scalar & operator()(int i, int j)