Medusa  1.1
Coordinate Free Mehless Method implementation
MatrixAddons.hpp
Go to the documentation of this file.
1 #ifndef MEDUSA_BITS_TYPES_MATRIXADDONS_HPP_
2 #define MEDUSA_BITS_TYPES_MATRIXADDONS_HPP_
3 
14 Matrix& operator=(const Scalar& s) {
16  this->setConstant(s);
17  return *this;
18 }
19 
21 Matrix(const Scalar& s) {
22  _init1alt<RowsAtCompileTime != Dynamic && ColsAtCompileTime != Dynamic>(s);
23 }
24 
25 private:
27 template <bool is_fixed>
28 void _init1alt(const Scalar& s,
29  typename std::enable_if<is_fixed>::type* = nullptr) {
30  this->setConstant(s);
31 }
32 
33 template <bool is_fixed>
34 void _init1alt(const Scalar& s, typename std::enable_if<!is_fixed>::type* = nullptr) {
35  Base::_check_template_params();
36  Base::template _init1<Scalar>(s);
37 }
39 
40 public:
42 Matrix(std::initializer_list<Scalar> lst) {
43  EIGEN_STATIC_ASSERT_FIXED_SIZE(Matrix);
44  assert((lst.size() == RowsAtCompileTime || lst.size() == ColsAtCompileTime) &&
45  "Initializer list of inappropriate size.");
46  int i = 0;
47  for (const Scalar& s : lst) {
48  this->operator()(i++) = s;
49  }
50 }
51 
53 Map<Matrix<Scalar, Dynamic, 1>> asLinear() {
54  return {this->data(), this->size()};
55 }
56 Map<Matrix<Scalar, Dynamic, 1>> asLinear() const {
57  return {this->data(), this->size()};
58 }
60 Map<Matrix<Scalar, Dynamic, 1>> asRowLinear() {
61  return {this->data(), this->size()};
62 }
63 Map<Matrix<Scalar, Dynamic, 1>> asRowLinear() const {
64  return {this->data(), this->size()};
65 }
66 
67 #endif // MEDUSA_BITS_TYPES_MATRIXADDONS_HPP_
operator=
Matrix & operator=(const Scalar &s)
Assign scalar to a matrix, setting all its elements to s.
Definition: MatrixAddons.hpp:15
asLinear
Map< Matrix< Scalar, Dynamic, 1 > > asLinear()
Returns a view to a matrix as a column vector.
Definition: MatrixAddons.hpp:53
asRowLinear
Map< Matrix< Scalar, Dynamic, 1 > > asRowLinear()
Returns a view to a matrix as a row vector.
Definition: MatrixAddons.hpp:60
Matrix
Matrix(const Scalar &s)
Construct matrix from scalar. Enabled only for fixed size matrices.
Definition: MatrixAddons.hpp:21