MCPcopy Create free account
hub / github.com/PX4/eigen / vectorwiseop_matrix

Function vectorwiseop_matrix

test/vectorwiseop.cpp:130–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128}
129
130template<typename MatrixType> void vectorwiseop_matrix(const MatrixType& m)
131{
132 typedef typename MatrixType::Index Index;
133 typedef typename MatrixType::Scalar Scalar;
134 typedef typename NumTraits<Scalar>::Real RealScalar;
135 typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> ColVectorType;
136 typedef Matrix<Scalar, 1, MatrixType::ColsAtCompileTime> RowVectorType;
137 typedef Matrix<RealScalar, MatrixType::RowsAtCompileTime, 1> RealColVectorType;
138 typedef Matrix<RealScalar, 1, MatrixType::ColsAtCompileTime> RealRowVectorType;
139
140 Index rows = m.rows();
141 Index cols = m.cols();
142 Index r = internal::random<Index>(0, rows-1),
143 c = internal::random<Index>(0, cols-1);
144
145 MatrixType m1 = MatrixType::Random(rows, cols),
146 m2(rows, cols),
147 m3(rows, cols);
148
149 ColVectorType colvec = ColVectorType::Random(rows);
150 RowVectorType rowvec = RowVectorType::Random(cols);
151 RealColVectorType rcres;
152 RealRowVectorType rrres;
153
154 // test addition
155
156 m2 = m1;
157 m2.colwise() += colvec;
158 VERIFY_IS_APPROX(m2, m1.colwise() + colvec);
159 VERIFY_IS_APPROX(m2.col(c), m1.col(c) + colvec);
160
161 if(rows>1)
162 {
163 VERIFY_RAISES_ASSERT(m2.colwise() += colvec.transpose());
164 VERIFY_RAISES_ASSERT(m1.colwise() + colvec.transpose());
165 }
166
167 m2 = m1;
168 m2.rowwise() += rowvec;
169 VERIFY_IS_APPROX(m2, m1.rowwise() + rowvec);
170 VERIFY_IS_APPROX(m2.row(r), m1.row(r) + rowvec);
171
172 if(cols>1)
173 {
174 VERIFY_RAISES_ASSERT(m2.rowwise() += rowvec.transpose());
175 VERIFY_RAISES_ASSERT(m1.rowwise() + rowvec.transpose());
176 }
177
178 // test substraction
179
180 m2 = m1;
181 m2.colwise() -= colvec;
182 VERIFY_IS_APPROX(m2, m1.colwise() - colvec);
183 VERIFY_IS_APPROX(m2.col(c), m1.col(c) - colvec);
184
185 if(rows>1)
186 {
187 VERIFY_RAISES_ASSERT(m2.colwise() -= colvec.transpose());

Callers 1

test_vectorwiseopFunction · 0.85

Calls 14

colwiseMethod · 0.80
rowwiseMethod · 0.80
rowsMethod · 0.45
colsMethod · 0.45
colMethod · 0.45
transposeMethod · 0.45
rowMethod · 0.45
normMethod · 0.45
sumMethod · 0.45
maxCoeffMethod · 0.45
xMethod · 0.45
normalizedMethod · 0.45

Tested by 1

test_vectorwiseopFunction · 0.68