22 #ifndef linear_algebra_h 23 #define linear_algebra_h 25 #include "square_matrix.h" 27 #include "row_vector.h" 28 #include "fixed_square_matrix.h" 29 #include "fixed_vector.h" 30 #include "fixed_row_vector.h" 31 #include "fixed_symmetric_matrix.h" 32 #include "var_square_matrix.h" 33 #include "var_symmetric_matrix.h" 34 #include "var_vector.h" 35 #include "var_row_vector.h" 36 #include "var_fixed_general_matrix.h" 37 #include "fixed_var_general_matrix.h" 38 #include "diagonal_matrix.h" 44 template<
class T> std::complex<T> operator+(
const std::complex<T> &x,
int y);
45 template<
class T> std::complex<T> operator-(
const std::complex<T> &x,
int y);
46 template<
class T> std::complex<T> operator*(
const std::complex<T> &x,
int y);
47 template<
class T> std::complex<T> operator/(
const std::complex<T> &x,
int y);
48 template<
class T> std::complex<T> operator+(
int x,
const std::complex<T> &y);
49 template<
class T> std::complex<T> operator-(
int x,
const std::complex<T> &y);
50 template<
class T> std::complex<T> operator*(
int x,
const std::complex<T> &y);
51 template<
class T> std::complex<T> operator/(
int x,
const std::complex<T> &y);
56 template <
class Row1,
class Row2,
class Row3,
class AT1,
class AT2,
class AT3>
57 inline void add(
const Vector<Row1, AT1> &a1,
const Vector<Row2, AT2> &a2, Vector<Row3, AT3> &a3) {
58 FMATVEC_ASSERT(a1.size() == a2.size(), AT3);
59 for (
int i = 0; i < a1.size(); i++)
60 a3.e(i) = a1.e(i) + a2.e(i);
63 template <
class Row1,
class Row2,
class AT>
64 inline void add(Vector<Row1, AT> &a1,
const Vector<Row2, AT> &a2) {
65 FMATVEC_ASSERT(a1.size() == a2.size(), AT);
66 for (
int i = 0; i < a1.size(); i++)
70 template <
class Row1,
class Row2,
class Row3,
class AT1,
class AT2>
72 FMATVEC_ASSERT(a1.size() == a2.size(), AT2);
73 for (
int i = 0; i < a1.size(); i++)
74 a3.e(i) = a1.e(i) - a2.e(i);
77 template <
class Row1,
class Row2,
class AT1,
class AT2>
78 inline void sub(Vector<Row1, AT1> &a1,
const Vector<Row2, AT2> &a2) {
79 FMATVEC_ASSERT(a1.size() == a2.size(), AT2);
80 for (
int i = 0; i < a1.size(); i++)
85 template <
class AT1,
class AT2,
class Row1,
class Row2>
86 inline Vector<Var, typename OperatorResult<AT1, AT2>::Type> operator+(
const Vector<Row1, AT1> &a,
const Vector<Row2, AT2> &b) {
87 Vector<Var, typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
91 template <
class AT1,
class AT2,
class Row>
92 inline Vector<Row, typename OperatorResult<AT1, AT2>::Type> operator+(
const Vector<Row, AT1> &a,
const Vector<Row, AT2> &b) {
93 Vector<Row, typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
97 template <
class AT1,
class AT2,
int M,
class Row>
98 inline Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Vector<Fixed<M>, AT1> &a,
const Vector<Row, AT2> &b) {
99 Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
103 template <
class AT1,
class AT2,
int M>
104 inline Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Vector<Fixed<M>, AT1> &a,
const Vector<Fixed<M>, AT2> &b) {
105 Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
110 template <
class Row1,
class Row2>
111 inline Vector<Row2, double> operator+(Vector<Row1, double> &&a, Vector<Row2, double> &&b) {
115 template <
class Row1,
class Row2>
116 inline Vector<Row1, double> operator+(Vector<Row1, double> &&a,
const Vector<Row2, double> &b) {
120 template <
class Row1,
class Row2>
121 inline Vector<Row2, double> operator+(
const Vector<Row1, double> &a, Vector<Row2, double> &&b) {
125 template <
class AT,
class Row1,
class Row2>
126 inline Vector<Row1, AT> operator+=(Vector<Row1, AT> &a,
const Vector<Row2, AT> &b) {
132 template <
class AT1,
class AT2,
class Row1,
class Row2>
133 inline Vector<Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Vector<Row1, AT1> &a,
const Vector<Row2, AT2> &b) {
134 Vector<Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
138 template <
class AT1,
class AT2,
class Row>
139 inline Vector<Row, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Vector<Row, AT1> &a,
const Vector<Row, AT2> &b) {
140 Vector<Row, typename fmatvec::OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
144 template <
class AT1,
class AT2,
int M,
class Row2>
150 template <
class AT1,
class AT2,
int M>
157 template <
class Row1,
class Row2>
158 inline Vector<Row2, double> operator-(Vector<Row1, double> &&a, Vector<Row2, double> &&b) {
162 template <
class Row1,
class Row2>
163 inline Vector<Row1, double> operator-(Vector<Row1, double> &&a,
const Vector<Row2, double> &b) {
167 template <
class Row1,
class Row2>
168 inline Vector<Row2, double> operator-(
const Vector<Row1, double> &a, Vector<Row2, double> &&b) {
169 FMATVEC_ASSERT(a.size() == b.size(), double);
170 for (
int i = 0; i < a.size(); i++)
171 b.e(i) = a.e(i) - b.e(i);
174 template <
class AT,
class Row1,
class Row2>
175 inline Vector<Row1, AT> operator-=(Vector<Row1, AT> &a,
const Vector<Row2, AT> &b) {
181 template <
class Col1,
class Col2,
class Col3,
class AT>
182 inline void add(
const RowVector<Col1, AT> &a1,
const RowVector<Col2, AT> &a2, RowVector<Col3, AT> &a3) {
183 FMATVEC_ASSERT(a1.size() == a2.size(), AT);
184 for (
int i = 0; i < a1.size(); i++)
185 a3.e(i) = a1.e(i) + a2.e(i);
188 template <
class Col1,
class Col2,
class AT>
189 inline void add(RowVector<Col1, AT> &a1,
const RowVector<Col2, AT> &a2) {
190 FMATVEC_ASSERT(a1.size() == a2.size(), AT);
191 for (
int i = 0; i < a1.size(); i++)
195 template <
class Col1,
class Col2,
class Col3,
class AT1,
class AT2>
197 FMATVEC_ASSERT(a1.size() == a2.size(), AT2);
198 for (
int i = 0; i < a1.size(); i++)
199 a3.e(i) = a1.e(i) - a2.e(i);
202 template <
class Col1,
class Col2,
class AT1,
class AT2>
203 inline void sub(RowVector<Col1, AT1> &a1,
const RowVector<Col2, AT2> &a2) {
204 FMATVEC_ASSERT(a1.size() == a2.size(), AT2);
205 for (
int i = 0; i < a1.size(); i++)
210 template <
class AT1,
class AT2,
class Col1,
class Col2>
211 inline RowVector<Var, typename OperatorResult<AT1, AT2>::Type> operator+(
const RowVector<Col1, AT1> &a,
const RowVector<Col2, AT2> &b) {
212 RowVector<Var, typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
216 template <
class AT1,
class AT2,
class Col>
217 inline RowVector<Col, typename OperatorResult<AT1, AT2>::Type> operator+(
const RowVector<Col, AT1> &a,
const RowVector<Col, AT2> &b) {
218 RowVector<Col, typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
222 template <
class AT1,
class AT2,
int N,
class Col2>
223 inline RowVector<Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const RowVector<Fixed<N>, AT1> &a,
const RowVector<Col2, AT2> &b) {
224 RowVector<Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
228 template <
class AT1,
class AT2,
int N>
229 inline RowVector<Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const RowVector<Fixed<N>, AT1> &a,
const RowVector<Fixed<N>, AT2> &b) {
230 RowVector<Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
235 template <
class Row1,
class Row2>
236 inline RowVector<Row2, double> operator+(RowVector<Row1, double> &&a, RowVector<Row2, double> &&b) {
240 template <
class Row1,
class Row2>
241 inline RowVector<Row1, double> operator+(RowVector<Row1, double> &&a,
const RowVector<Row2, double> &b) {
245 template <
class Row1,
class Row2>
246 inline RowVector<Row2, double> operator+(
const RowVector<Row1, double> &a, RowVector<Row2, double> &&b) {
250 template <
class AT,
class Col1,
class Col2>
251 inline RowVector<Col1, AT> operator+=(RowVector<Col1, AT> &a,
const RowVector<Col2, AT> &b) {
257 template <
class AT1,
class AT2,
class Col1,
class Col2>
258 inline RowVector<Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const RowVector<Col1, AT1> &a,
const RowVector<Col2, AT2> &b) {
259 RowVector<Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
263 template <
class AT1,
class AT2,
class Col>
264 inline RowVector<Col, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const RowVector<Col, AT1> &a,
const RowVector<Col, AT2> &b) {
265 RowVector<Col, typename fmatvec::OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
269 template <
class AT1,
class AT2,
int N,
class Col2>
275 template <
class AT1,
class AT2,
int N>
282 template <
class Row1,
class Row2>
283 inline RowVector<Row2, double> operator-(RowVector<Row1, double> &&a, RowVector<Row2, double> &&b) {
287 template <
class Row1,
class Row2>
288 inline RowVector<Row1, double> operator-(RowVector<Row1, double> &&a,
const RowVector<Row2, double> &b) {
292 template <
class Row1,
class Row2>
293 inline RowVector<Row2, double> operator-(
const RowVector<Row1, double> &a, RowVector<Row2, double> &&b) {
294 FMATVEC_ASSERT(a.size() == b.size(), double);
295 for (
int i = 0; i < a.size(); i++)
296 b.e(i) = a.e(i) - b.e(i);
299 template <
class AT,
class Col1,
class Col2>
300 inline RowVector<Col1, AT> operator-=(RowVector<Col1, AT> &a,
const RowVector<Col2, AT> &b) {
306 template <
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2,
class Type3,
class Row3,
class Col3,
class AT1,
class AT2,
class AT3>
307 inline void add(
const Matrix<Type1, Row1, Col1, AT1> &A1,
const Matrix<Type2, Row2, Col2, AT2> &A2, Matrix<Type3, Row3, Col3, AT3> &A3) {
308 FMATVEC_ASSERT(A1.rows() == A2.rows(), AT3);
309 FMATVEC_ASSERT(A1.cols() == A2.cols(), AT3);
310 for (
int i = 0; i < A1.rows(); i++)
311 for (
int j = 0; j < A2.cols(); j++)
312 A3.e(i, j) = A1.e(i, j) + A2.e(i, j);
315 template <
class Row1,
class Row2,
class Row3,
class AT>
316 inline void add(
const Matrix<Symmetric, Row1, Row1, AT> &A1,
const Matrix<Symmetric, Row2, Row2, AT> &A2, Matrix<Symmetric, Row3, Row3, AT> &A3) {
317 FMATVEC_ASSERT(A1.size() == A2.size(), AT);
318 for (
int i = 0; i < A1.size(); i++)
319 for (
int j = i; j < A2.size(); j++)
320 A3.ej(i, j) = A1.ej(i, j) + A2.ej(i, j);
323 template <
class Row1,
class Row2,
class Row3,
class AT>
324 inline void add(
const Matrix<Diagonal, Row1, Row1, AT> &A1,
const Matrix<Diagonal, Row2, Row2, AT> &A2, Matrix<Diagonal, Row3, Row3, AT> &A3) {
325 FMATVEC_ASSERT(A1.size() == A2.size(), AT);
326 for (
int i = 0; i < A3.size(); i++)
327 A3.e(i) = A1.e(i) + A2.e(i);
330 template <
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2,
class AT>
331 inline void add(Matrix<Type1, Row1, Col1, AT> &A1,
const Matrix<Type2, Row2, Col2, AT> &A2) {
332 FMATVEC_ASSERT(A1.rows() == A2.rows(), AT);
333 FMATVEC_ASSERT(A1.cols() == A2.cols(), AT);
334 for (
int i = 0; i < A1.rows(); i++)
335 for (
int j = 0; j < A2.cols(); j++)
336 A1.e(i, j) += A2.e(i, j);
339 template <
class Row1,
class Row2,
class AT>
340 inline void add(Matrix<Symmetric, Row1, Row1, AT> &A1,
const Matrix<Symmetric, Row2, Row2, AT> &A2) {
341 FMATVEC_ASSERT(A1.size() == A2.size(), AT);
342 for (
int i = 0; i < A1.size(); i++)
343 for (
int j = i; j < A2.size(); j++)
344 A1.ej(i, j) += A2.ej(i, j);
347 template <
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2,
class Type3,
class Row3,
class Col3,
class AT1,
class AT2>
348 inline void sub(
const Matrix<Type1, Row1, Col1, AT1> &A1,
const Matrix<Type2, Row2, Col2, AT2> &A2, Matrix<Type3, Row3, Col3,
typename fmatvec::OperatorResult<AT1, AT2>::Type> &A3) {
349 FMATVEC_ASSERT(A1.rows() == A2.rows(), AT2);
350 FMATVEC_ASSERT(A1.cols() == A2.cols(), AT2);
351 for (
int i = 0; i < A1.rows(); i++)
352 for (
int j = 0; j < A2.cols(); j++)
353 A3.e(i, j) = A1.e(i, j) - A2.e(i, j);
356 template <
class Row1,
class Row2,
class Row3,
class AT1,
class AT2>
357 inline void sub(
const Matrix<Symmetric, Row1, Row1, AT1> &A1,
const Matrix<Symmetric, Row2, Row2, AT2> &A2, Matrix<Symmetric, Row3, Row3,
typename fmatvec::OperatorResult<AT1, AT2>::Type> &A3) {
358 FMATVEC_ASSERT(A1.size() == A2.size(), AT2);
359 for (
int i = 0; i < A1.size(); i++)
360 for (
int j = i; j < A2.size(); j++)
361 A3.ej(i, j) = A1.ej(i, j) - A2.ej(i, j);
364 template <
class Row1,
class Row2,
class Row3,
class AT1,
class AT2>
365 inline void sub(
const Matrix<Diagonal, Row1, Row1, AT1> &A1,
const Matrix<Diagonal, Row2, Row2, AT2> &A2, Matrix<Diagonal, Row3, Row3,
typename fmatvec::OperatorResult<AT1, AT2>::Type> &A3) {
366 FMATVEC_ASSERT(A1.size() == A2.size(), AT2);
367 for (
int i = 0; i < A3.size(); i++)
368 A3.e(i) = A1.e(i) - A2.e(i);
371 template <
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2,
class AT1,
class AT2>
372 inline void sub(Matrix<Type1, Row1, Col1, AT1> &A1,
const Matrix<Type2, Row2, Col2, AT2> &A2) {
373 FMATVEC_ASSERT(A1.rows() == A2.rows(), AT2);
374 FMATVEC_ASSERT(A1.cols() == A2.cols(), AT2);
375 for (
int i = 0; i < A1.rows(); i++)
376 for (
int j = 0; j < A2.cols(); j++)
377 A1.e(i, j) -= A2.e(i, j);
380 template <
class Row1,
class Row2,
class AT1,
class AT2>
381 inline void sub(Matrix<Symmetric, Row1, Row1, AT1> &A1,
const Matrix<Symmetric, Row2, Row2, AT2> &A2) {
382 FMATVEC_ASSERT(A1.size() == A2.size(), AT2);
383 for (
int i = 0; i < A1.size(); i++)
384 for (
int j = i; j < A2.size(); j++)
385 A1.ej(i, j) -= A2.ej(i, j);
390 template <
class AT1,
class AT2,
class Type1,
class Type2,
class Row1,
class Col1,
class Row2,
class Col2>
391 inline Matrix<General, Var, Var, typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type1, Row1, Col1, AT1> &A,
const Matrix<Type2, Row2, Col2, AT2> &B) {
392 Matrix<General, Var, Var, typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
396 template <
class AT1,
class AT2,
class Type1,
class Type2,
class Row,
class Col>
397 inline Matrix<General, Row, Col, typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type1, Row, Col, AT1> &A,
const Matrix<Type2, Row, Col, AT2> &B) {
398 Matrix<General, Row, Col, typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
402 template <
class AT1,
class AT2,
int M,
class Type1,
class Type2,
class Row,
class Col>
403 inline Matrix<General, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type1, Fixed<M>, Var, AT1> &A,
const Matrix<Type2, Row, Col, AT2> &B) {
404 Matrix<General, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
408 template <
class AT1,
class AT2,
int M,
class Type1,
class Type2>
409 inline Matrix<General, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type1, Fixed<M>, Var, AT1> &A,
const Matrix<Type2, Fixed<M>, Var, AT2> &B) {
410 Matrix<General, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
414 template <
class AT1,
class AT2,
int N,
class Type1,
class Type2,
class Row,
class Col>
415 inline Matrix<General, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type1, Var, Fixed<N>, AT1> &A,
const Matrix<Type2, Row, Col, AT2> &B) {
416 Matrix<General, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
420 template <
class AT1,
class AT2,
int N,
class Type1,
class Type2>
421 inline Matrix<General, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type1, Var, Fixed<N>, AT1> &A,
const Matrix<Type2, Var, Fixed<N>, AT2> &B) {
422 Matrix<General, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
426 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2,
class Row,
class Col>
427 inline Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type1, Fixed<M>, Fixed<N>, AT1> &A,
const Matrix<Type2, Row, Col, AT2> &B) {
428 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
432 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
433 inline Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type1, Fixed<M>, Fixed<N>, AT1> &A,
const Matrix<Type2, Fixed<M>, Var, AT2> &B) {
434 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
438 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
439 inline Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type1, Fixed<M>, Fixed<N>, AT1> &A,
const Matrix<Type2, Var, Fixed<N>, AT2> &B) {
440 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
444 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
445 inline Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type1, Fixed<M>, Fixed<N>, AT1> &A,
const Matrix<Type2, Fixed<M>, Fixed<N>, AT2> &B) {
446 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
450 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2,
class Row,
class Col>
451 inline Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type2, Row, Col, AT1> &A,
const Matrix<Type1, Fixed<M>, Fixed<N>, AT2> &B) {
452 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
456 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
457 inline Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type2, Fixed<M>, Var, AT1> &A,
const Matrix<Type1, Fixed<M>, Fixed<N>, AT2> &B) {
458 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
462 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
463 inline Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type2, Var, Fixed<N>, AT1> &A,
const Matrix<Type1, Fixed<M>, Fixed<N>, AT2> &B) {
464 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
469 template <
class AT1,
class AT2,
class Type,
class Row1,
class Col1,
class Row2,
class Col2>
470 inline Matrix<Type, Var, Var, typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type, Row1, Col1, AT1> &A,
const Matrix<Type, Row2, Col2, AT2> &B) {
471 Matrix<Type, Var, Var, typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
475 template <
class AT1,
class AT2,
class Type,
class Row,
class Col>
476 inline Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type, Row, Col, AT1> &A,
const Matrix<Type, Row, Col, AT2> &B) {
477 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
481 template <
class AT1,
class AT2,
int M,
class Type,
class Row,
class Col>
482 inline Matrix<Type, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type, Fixed<M>, Var, AT1> &A,
const Matrix<Type, Row, Col, AT2> &B) {
483 Matrix<Type, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
487 template <
class AT1,
class AT2,
int M,
class Type>
488 inline Matrix<Type, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type, Fixed<M>, Var, AT1> &A,
const Matrix<Type, Fixed<M>, Var, AT2> &B) {
489 Matrix<Type, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
493 template <
class AT1,
class AT2,
int N,
class Type,
class Row,
class Col>
494 inline Matrix<Type, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type, Var, Fixed<N>, AT1> &A,
const Matrix<Type, Row, Col, AT2> &B) {
495 Matrix<Type, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
499 template <
class AT1,
class AT2,
int N,
class Type>
500 inline Matrix<Type, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type, Var, Fixed<N>, AT1> &A,
const Matrix<Type, Var, Fixed<N>, AT2> &B) {
501 Matrix<Type, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
505 template <
class AT1,
class AT2,
int M,
int N,
class Type,
class Row,
class Col>
506 inline Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type, Fixed<M>, Fixed<N>, AT1> &A,
const Matrix<Type, Row, Col, AT2> &B) {
507 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
511 template <
class AT1,
class AT2,
int M,
int N,
class Type>
512 inline Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type, Fixed<M>, Fixed<N>, AT1> &A,
const Matrix<Type, Fixed<M>, Var, AT2> &B) {
513 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
517 template <
class AT1,
class AT2,
int M,
int N,
class Type>
518 inline Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type, Fixed<M>, Fixed<N>, AT1> &A,
const Matrix<Type, Var, Fixed<N>, AT2> &B) {
519 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
523 template <
class AT1,
class AT2,
int M,
int N,
class Type>
524 inline Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type, Fixed<M>, Fixed<N>, AT1> &A,
const Matrix<Type, Fixed<M>, Fixed<N>, AT2> &B) {
525 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
529 template <
class AT1,
class AT2,
int M,
int N,
class Type,
class Row,
class Col>
530 inline Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type, Row, Col, AT1> &A,
const Matrix<Type, Fixed<M>, Fixed<N>, AT2> &B) {
531 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
535 template <
class AT1,
class AT2,
int M,
int N,
class Type>
536 inline Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type, Fixed<M>, Var, AT1> &A,
const Matrix<Type, Fixed<M>, Fixed<N>, AT2> &B) {
537 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
541 template <
class AT1,
class AT2,
int M,
int N,
class Type>
542 inline Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Matrix<Type, Var, Fixed<N>, AT1> &A,
const Matrix<Type, Fixed<M>, Fixed<N>, AT2> &B) {
543 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
548 template <
class Type1,
class Type2,
class Row1,
class Row2,
class Col1,
class Col2>
549 inline Matrix<Type2, Row2, Col2, double> operator+(Matrix<Type1, Row1, Col1, double> &&a, Matrix<Type2, Row2, Col2, double> &&b) {
553 template <
class Type1,
class Type2,
class Row1,
class Row2,
class Col1,
class Col2>
554 inline Matrix<Type1, Row1, Col1, double> operator+(Matrix<Type1, Row1, Col1, double> &&a,
const Matrix<Type2, Row2, Col2, double> &b) {
558 template <
class Type1,
class Type2,
class Row1,
class Row2,
class Col1,
class Col2>
559 inline Matrix<Type2, Row2, Col2, double> operator+(
const Matrix<Type1, Row1, Col1, double> &a, Matrix<Type2, Row2, Col2, double> &&b) {
563 template <
class AT,
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2>
564 inline Matrix<Type1, Row1, Col1, AT>& operator+=(Matrix<Type1, Row1, Col1, AT> &A,
const Matrix<Type2, Row2, Col2, AT> &B) {
571 template <
class AT1,
class AT2,
class Type1,
class Type2,
class Row1,
class Col1,
class Row2,
class Col2>
572 inline Matrix<General, Var, Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type1, Row1, Col1, AT1> &A,
const Matrix<Type2, Row2, Col2, AT2> &B) {
573 Matrix<General, Var, Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
577 template <
class AT1,
class AT2,
class Type1,
class Type2,
class Row,
class Col>
578 inline Matrix<General, Row, Col, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type1, Row, Col, AT1> &A,
const Matrix<Type2, Row, Col, AT2> &B) {
579 Matrix<General, Row, Col, typename fmatvec::OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
583 template <
class AT1,
class AT2,
int M,
class Type1,
class Type2,
class Row,
class Col>
584 inline Matrix<General, Fixed<M>, Var,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type1, Fixed<M>, Var, AT1> &A,
const Matrix<Type2, Row, Col, AT2> &B) {
589 template <
class AT1,
class AT2,
int M,
class Type1,
class Type2>
590 inline Matrix<General, Fixed<M>, Var,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type1, Fixed<M>, Var, AT1> &A,
const Matrix<Type2, Fixed<M>, Var, AT2> &B) {
595 template <
class AT1,
class AT2,
int N,
class Type1,
class Type2,
class Row,
class Col>
596 inline Matrix<General, Var, Fixed<N>,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type1, Var, Fixed<N>, AT1> &A,
const Matrix<Type2, Row, Col, AT2> &B) {
601 template <
class AT1,
class AT2,
int N,
class Type1,
class Type2>
602 inline Matrix<General, Var, Fixed<N>,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type1, Var, Fixed<N>, AT1> &A,
const Matrix<Type2, Var, Fixed<N>, AT2> &B) {
607 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2,
class Row,
class Col>
608 inline Matrix<General, Fixed<M>, Fixed<N>,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type1, Fixed<M>, Fixed<N>, AT1> &A,
const Matrix<Type2, Row, Col, AT2> &B) {
613 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
614 inline Matrix<General, Fixed<M>, Fixed<N>,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type1, Fixed<M>, Fixed<N>, AT1> &A,
const Matrix<Type2, Fixed<M>, Var, AT2> &B) {
619 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
620 inline Matrix<General, Fixed<M>, Fixed<N>,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type1, Fixed<M>, Fixed<N>, AT1> &A,
const Matrix<Type2, Var, Fixed<N>, AT2> &B) {
625 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
626 inline Matrix<General, Fixed<M>, Fixed<N>,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type1, Fixed<M>, Fixed<N>, AT1> &A,
const Matrix<Type2, Fixed<M>, Fixed<N>, AT2> &B) {
631 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2,
class Row,
class Col>
632 inline Matrix<General, Fixed<M>, Fixed<N>,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type2, Row, Col, AT1> &A,
const Matrix<Type1, Fixed<M>, Fixed<N>, AT2> &B) {
637 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
638 inline Matrix<General, Fixed<M>, Fixed<N>,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type2, Fixed<M>, Var, AT1> &A,
const Matrix<Type1, Fixed<M>, Fixed<N>, AT2> &B) {
643 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
644 inline Matrix<General, Fixed<M>, Fixed<N>,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type2, Var, Fixed<N>, AT1> &A,
const Matrix<Type1, Fixed<M>, Fixed<N>, AT2> &B) {
650 template <
class AT1,
class AT2,
class Type,
class Row1,
class Col1,
class Row2,
class Col2>
651 inline Matrix<Type, Var, Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type, Row1, Col1, AT1> &A,
const Matrix<Type, Row2, Col2, AT2> &B) {
652 Matrix<Type, Var, Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
656 template <
class AT1,
class AT2,
class Type,
class Row,
class Col>
657 inline Matrix<Type, Row, Col, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type, Row, Col, AT1> &A,
const Matrix<Type, Row, Col, AT2> &B) {
658 Matrix<Type, Row, Col, typename fmatvec::OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
662 template <
class AT1,
class AT2,
int M,
class Type,
class Row,
class Col>
663 inline Matrix<Type, Fixed<M>, Var,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type, Fixed<M>, Var, AT1> &A,
const Matrix<Type, Row, Col, AT2> &B) {
668 template <
class AT1,
class AT2,
int M,
class Type>
669 inline Matrix<Type, Fixed<M>, Var,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type, Fixed<M>, Var, AT1> &A,
const Matrix<Type, Fixed<M>, Var, AT2> &B) {
674 template <
class AT1,
class AT2,
int N,
class Type,
class Row,
class Col>
675 inline Matrix<Type, Var, Fixed<N>,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type, Var, Fixed<N>, AT1> &A,
const Matrix<Type, Row, Col, AT2> &B) {
680 template <
class AT1,
class AT2,
int N,
class Type>
681 inline Matrix<Type, Var, Fixed<N>,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type, Var, Fixed<N>, AT1> &A,
const Matrix<Type, Var, Fixed<N>, AT2> &B) {
686 template <
class AT1,
class AT2,
int M,
int N,
class Type,
class Row,
class Col>
687 inline Matrix<Type, Fixed<M>, Fixed<N>,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type, Fixed<M>, Fixed<N>, AT1> &A,
const Matrix<Type, Row, Col, AT2> &B) {
692 template <
class AT1,
class AT2,
int M,
int N,
class Type>
693 inline Matrix<Type, Fixed<M>, Fixed<N>,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type, Fixed<M>, Fixed<N>, AT1> &A,
const Matrix<Type, Fixed<M>, Var, AT2> &B) {
698 template <
class AT1,
class AT2,
int M,
int N,
class Type>
699 inline Matrix<Type, Fixed<M>, Fixed<N>,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type, Fixed<M>, Fixed<N>, AT1> &A,
const Matrix<Type, Var, Fixed<N>, AT2> &B) {
704 template <
class AT1,
class AT2,
int M,
int N,
class Type>
705 inline Matrix<Type, Fixed<M>, Fixed<N>,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type, Fixed<M>, Fixed<N>, AT1> &A,
const Matrix<Type, Fixed<M>, Fixed<N>, AT2> &B) {
710 template <
class AT1,
class AT2,
int M,
int N,
class Type,
class Row,
class Col>
711 inline Matrix<Type, Fixed<M>, Fixed<N>,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type, Row, Col, AT1> &A,
const Matrix<Type, Fixed<M>, Fixed<N>, AT2> &B) {
716 template <
class AT1,
class AT2,
int M,
int N,
class Type>
717 inline Matrix<Type, Fixed<M>, Fixed<N>,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type, Fixed<M>, Var, AT1> &A,
const Matrix<Type, Fixed<M>, Fixed<N>, AT2> &B) {
722 template <
class AT1,
class AT2,
int M,
int N,
class Type>
723 inline Matrix<Type, Fixed<M>, Fixed<N>,
typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Matrix<Type, Var, Fixed<N>, AT1> &A,
const Matrix<Type, Fixed<M>, Fixed<N>, AT2> &B) {
729 template <
class Type1,
class Type2,
class Row1,
class Row2,
class Col1,
class Col2>
730 inline Matrix<Type2, Row2, Col2, double> operator-(Matrix<Type1, Row1, Col1, double> &&a, Matrix<Type2, Row2, Col2, double> &&b) {
734 template <
class Type1,
class Type2,
class Row1,
class Row2,
class Col1,
class Col2>
735 inline Matrix<Type1, Row1, Col1, double> operator-(Matrix<Type1, Row1, Col1, double> &&a,
const Matrix<Type2, Row2, Col2, double> &b) {
739 template <
class Type1,
class Type2,
class Row1,
class Row2,
class Col1,
class Col2>
740 inline Matrix<Type2, Row2, Col2, double> operator-(
const Matrix<Type1, Row1, Col1, double> &a, Matrix<Type2, Row2, Col2, double> &&b) {
741 FMATVEC_ASSERT(a.rows() == b.rows(), double);
742 FMATVEC_ASSERT(a.cols() == b.cols(), double);
743 for (
int i = 0; i < a.rows(); i++)
744 for (
int j = 0; j < a.cols(); j++)
745 b.e(i, j) = a.e(i, j) - b.e(i, j);
748 template <
class AT,
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2>
749 inline Matrix<Type1, Row1, Col1, AT>& operator-=(Matrix<Type1, Row1, Col1, AT> &A,
const Matrix<Type2, Row2, Col2, AT> &B) {
755 template <
class AT1,
class AT2,
class Row1,
class Row2>
756 inline SquareMatrix<Var, typename OperatorResult<AT1, AT2>::Type> operator+(
const SquareMatrix<Row1, AT1> &A1,
const SquareMatrix<Row2, AT2> &A2) {
757 SquareMatrix<Var, typename OperatorResult<AT1, AT2>::Type> A3(A1.size(), NONINIT);
761 template <
class AT1,
class AT2,
class Row>
762 inline SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> operator+(
const SquareMatrix<Row, AT1> &A1,
const SquareMatrix<Row, AT2> &A2) {
763 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> A3(A1.size(), NONINIT);
768 template <
class Row1,
class Row2>
769 inline SquareMatrix<Row1, double> operator+(SquareMatrix<Row1, double> &&A1, SquareMatrix<Row2, double> &&A2) {
771 return std::move(A1);;
773 template <
class Row1,
class Row2>
774 inline SquareMatrix<Row1, double> operator+(SquareMatrix<Row1, double> &&A1,
const SquareMatrix<Row2, double> &A2) {
776 return std::move(A1);;
778 template <
class Row1,
class Row2>
779 inline SquareMatrix<Row2, double> operator+(
const SquareMatrix<Row1, double> &A1, SquareMatrix<Row2, double> &&A2) {
781 return std::move(A2);
785 template <
class AT1,
class AT2,
class Row1,
class Row2>
786 inline SquareMatrix<Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const SquareMatrix<Row1, AT1> &A1,
const SquareMatrix<Row2, AT2> &A2) {
787 SquareMatrix<Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> A3(A1.size(), NONINIT);
791 template <
class AT1,
class AT2,
class Row>
792 inline SquareMatrix<Row, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const SquareMatrix<Row, AT1> &A1,
const SquareMatrix<Row, AT2> &A2) {
793 SquareMatrix<Row, typename fmatvec::OperatorResult<AT1, AT2>::Type> A3(A1.size(), NONINIT);
798 template <
class Row1,
class Row2>
799 inline SquareMatrix<Row1, double> operator-(SquareMatrix<Row1, double> &&A1, SquareMatrix<Row2, double> &&A2) {
801 return std::move(A1);;
803 template <
class Row1,
class Row2>
804 inline SquareMatrix<Row1, double> operator-(SquareMatrix<Row1, double> &&A1,
const SquareMatrix<Row2, double> &A2) {
806 return std::move(A1);;
808 template <
class Row1,
class Row2>
809 inline SquareMatrix<Row2, double> operator-(
const SquareMatrix<Row1, double> &A1, SquareMatrix<Row2, double> &&A2) {
810 FMATVEC_ASSERT(A1.size() == A2.size(), double);
811 for (
int i = 0; i < A1.size(); i++)
812 for (
int j = 0; j < A1.size(); j++)
813 A2.e(i, j) = A1.e(i, j) - A2.e(i, j);
814 return std::move(A2);
822 template <
class Type1,
class Row1,
class Col1,
class Row2,
class Row3,
class AT1,
class AT2>
824 FMATVEC_ASSERT(A.cols() == x.size(), AT2);
825 for (
int i = 0; i < y.size(); i++) {
827 for (
int j = 0; j < x.size(); j++)
828 y.e(i) += A.e(i, j) * x.e(j);
832 template <
class Row1,
class Row2,
class Row3,
class AT1,
class AT2>
834 FMATVEC_ASSERT(A.cols() == x.size(), AT2);
835 for (
int i = 0; i < y.size(); i++) {
837 for (
int j = 0; j < i; j++)
838 y.e(i) += A.ei(i, j) * x.e(j);
839 for (
int j = i; j < x.size(); j++)
840 y.e(i) += A.ej(i, j) * x.e(j);
845 template <
class AT1,
class AT2,
class Type1,
class Row1,
class Col1,
class Row2>
846 inline Vector<Var, typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type1, Row1, Col1, AT1> &A,
const Vector<Row2, AT2> &x) {
847 Vector<Var, typename OperatorResult<AT1, AT2>::Type> y(A.rows(), NONINIT);
851 template <
class AT1,
class AT2,
class Type1,
class Row,
class Col>
852 inline Vector<Row, typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type1, Row, Col, AT1> &A,
const Vector<Row, AT2> &x) {
853 Vector<Row, typename OperatorResult<AT1, AT2>::Type> y(A.rows(), NONINIT);
857 template <
class AT1,
class AT2,
int M,
class Type1,
class Col1,
class Row2>
858 inline Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type1, Fixed<M>, Col1, AT1> &A,
const Vector<Row2, AT2> &x) {
859 Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> y(A.rows(), NONINIT);
863 template <
class AT1,
class AT2,
int M,
class Type1>
864 inline Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type1, Fixed<M>, Fixed<M>, AT1> &A,
const Vector<Fixed<M>, AT2> &x) {
865 Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> y(A.rows(), NONINIT);
869 template <
class AT1,
class AT2,
int M,
int N,
class Type,
class Row2>
870 inline Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type, Fixed<M>, Fixed<N>, AT1> &A,
const Vector<Row2, AT2> &x) {
871 Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> y(A.rows(), NONINIT);
875 template <
class AT1,
class AT2,
int M,
int N,
class Type>
876 inline Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type, Fixed<M>, Fixed<N>, AT1> &A,
const Vector<Fixed<N>, AT2> &x) {
877 Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> y(A.rows(), NONINIT);
883 template <
class Col1,
class Type2,
class Row2,
class Col2,
class Type3,
class Col3,
class AT1,
class AT2>
885 FMATVEC_ASSERT(x.size() == A.rows(), AT2);
886 for (
int i = 0; i < y.size(); i++) {
888 for (
int j = 0; j < x.size(); j++)
889 y.e(i) += x.e(j) * A.e(j, i);
893 template <
class Col1,
class Row2,
class Col3,
class AT1,
class AT2>
895 FMATVEC_ASSERT(x.size() == A.rows(), AT2);
896 for (
int i = 0; i < y.size(); i++) {
898 for (
int j = 0; j < i; j++)
899 y.e(i) += x.e(j) * A.ej(j, i);
900 for (
int j = i; j < x.size(); j++)
901 y.e(i) += x.e(j) * A.ei(j, i);
905 template <
class AT1,
class AT2,
class Type2,
class Col2,
class Row1,
class Col1>
906 inline RowVector<Var, typename OperatorResult<AT1, AT2>::Type> operator*(
const RowVector<Col2, AT1> &x,
const Matrix<Type2, Row1, Col1, AT2> &A) {
907 RowVector<Var, typename OperatorResult<AT1, AT2>::Type> y(A.cols(), NONINIT);
911 template <
class AT1,
class AT2,
class Type2,
class Row,
class Col>
912 inline RowVector<Col, typename OperatorResult<AT1, AT2>::Type> operator*(
const RowVector<Col, AT1> &x,
const Matrix<Type2, Row, Col, AT2> &A) {
913 RowVector<Col, typename OperatorResult<AT1, AT2>::Type> y(A.cols(), NONINIT);
917 template <
class AT1,
class AT2,
int N,
class Type2,
class Col1,
class Row2>
918 inline RowVector<Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator*(
const RowVector<Col1, AT1> &x,
const Matrix<Type2, Row2, Fixed<N>, AT2> &A) {
919 RowVector<Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> y(A.cols(), NONINIT);
923 template <
class AT1,
class AT2,
int N,
class Type2>
924 inline RowVector<Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator*(
const RowVector<Fixed<N>, AT1> &x,
const Matrix<Type2, Fixed<N>, Fixed<N>, AT2> &A) {
925 RowVector<Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> y(A.cols(), NONINIT);
931 template <
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2,
class Type3,
class Row3,
class Col3,
class AT1,
class AT2>
932 inline void mult(
const Matrix<Type1, Row1, Col1, AT1> &A1,
const Matrix<Type2, Row2, Col2, AT2> &A2, Matrix<Type3, Row3, Col3,
typename fmatvec::OperatorResult<AT1, AT2>::Type> &A3) {
933 FMATVEC_ASSERT(A1.cols() == A2.rows(), AT2);
934 for (
int i = 0; i < A3.rows(); i++) {
935 for (
int k = 0; k < A3.cols(); k++) {
937 for (
int j = 0; j < A1.cols(); j++)
938 A3.e(i, k) += A1.e(i, j) * A2.e(j, k);
942 template <
class Row1,
class Type2,
class Row2,
class Col2,
class Type3,
class Row3,
class Col3,
class AT1,
class AT2>
943 inline void mult(
const Matrix<Symmetric, Row1, Row1, AT1> &A1,
const Matrix<Type2, Row2, Col2, AT2> &A2, Matrix<Type3, Row3, Col3,
typename fmatvec::OperatorResult<AT1, AT2>::Type> &A3) {
944 FMATVEC_ASSERT(A1.size() == A2.rows(), AT2);
945 for (
int i = 0; i < A3.rows(); i++) {
946 for (
int k = 0; k < A3.cols(); k++) {
948 for (
int j = 0; j < i; j++)
949 A3.e(i, k) += A1.ei(i, j) * A2.e(j, k);
950 for (
int j = i; j < A1.cols(); j++)
951 A3.e(i, k) += A1.ej(i, j) * A2.e(j, k);
955 template <
class Row1,
class Row2,
class Row3,
class AT1,
class AT2>
956 inline void mult(
const Matrix<Diagonal, Row1, Row1, AT1> &A1,
const Matrix<Diagonal, Row2, Row2, AT2> &A2, Matrix<Diagonal, Row3, Row3,
typename fmatvec::OperatorResult<AT1, AT2>::Type> &A3) {
957 FMATVEC_ASSERT(A1.size() == A2.size(), AT2);
958 for (
int i = 0; i < A3.size(); i++)
959 A3.e(i) = A1.e(i) * A2.e(i);
962 template <
class AT1,
class AT2,
class Type1,
class Type2,
class Row1,
class Col1,
class Row2,
class Col2>
963 inline Matrix<General, Var, Var, typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type1, Row1, Col1, AT1> &A1,
const Matrix<Type2, Row2, Col2, AT2> &A2) {
964 Matrix<General, Var, Var, typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
968 template <
class AT1,
class AT2,
class Type1,
class Type2,
class Row,
class Col>
969 inline Matrix<General, Row, Col, typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type1, Row, Col, AT1> &A1,
const Matrix<Type2, Row, Col, AT2> &A2) {
970 Matrix<General, Row, Col, typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
974 template <
class AT1,
class AT2,
int M,
class Type1,
class Type2,
class Col1,
class Row2,
class Col2>
975 inline Matrix<General, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type1, Fixed<M>, Col1, AT1> &A1,
const Matrix<Type2, Row2, Col2, AT2> &A2) {
976 Matrix<General, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
980 template <
class AT1,
class AT2,
int N,
class Type1,
class Row1,
class Col1,
class Type2,
class Row2>
981 inline Matrix<General, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type1, Row1, Col1, AT1> &A1,
const Matrix<Type2, Row2, Fixed<N>, AT2> &A2) {
982 Matrix<General, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
986 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2,
class Col1,
class Row2>
987 inline Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type1, Fixed<M>, Col1, AT1> &A1,
const Matrix<Type2, Row2, Fixed<N>, AT2> &A2) {
988 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
992 template <
class AT1,
class AT2,
int M,
class Type1,
class Type2>
993 inline Matrix<General, Fixed<M>, Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type1, Fixed<M>, Fixed<M>, AT1> &A1,
const Matrix<Type2, Fixed<M>, Fixed<M>, AT2> &A2) {
994 Matrix<General, Fixed<M>, Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
998 template <
class AT1,
class AT2,
class Type,
class Row1,
class Col1,
class Row2,
class Col2>
999 inline Matrix<Type, Var, Var, typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type, Row1, Col1, AT1> &A1,
const Matrix<Type, Row2, Col2, AT2> &A2) {
1000 Matrix<Type, Var, Var, typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1004 template <
class AT1,
class AT2,
class Type,
class Row,
class Col>
1005 inline Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type, Row, Col, AT1> &A1,
const Matrix<Type, Row, Col, AT2> &A2) {
1006 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1010 template <
class AT1,
class AT2,
int M,
class Type,
class Col1,
class Row2,
class Col2>
1011 inline Matrix<Type, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type, Fixed<M>, Col1, AT1> &A1,
const Matrix<Type, Row2, Col2, AT2> &A2) {
1012 Matrix<Type, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1016 template <
class AT1,
class AT2,
int N,
class Type,
class Row1,
class Col1,
class Row2>
1017 inline Matrix<Type, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type, Row1, Col1, AT1> &A1,
const Matrix<Type, Row2, Fixed<N>, AT2> &A2) {
1018 Matrix<Type, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1022 template <
class AT1,
class AT2,
int M,
int N,
class Type,
class Col1,
class Row2>
1023 inline Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type, Fixed<M>, Col1, AT1> &A1,
const Matrix<Type, Row2, Fixed<N>, AT2> &A2) {
1024 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1028 template <
class AT1,
class AT2,
int M,
class Type>
1029 inline Matrix<Type, Fixed<M>, Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type, Fixed<M>, Fixed<M>, AT1> &A1,
const Matrix<Type, Fixed<M>, Fixed<M>, AT2> &A2) {
1030 Matrix<Type, Fixed<M>, Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1036 template <
class AT1,
class AT2,
class Row1,
class Row2>
1037 inline SquareMatrix<Var, typename OperatorResult<AT1, AT2>::Type> operator*(
const SquareMatrix<Row1, AT1> &A1,
const SquareMatrix<Row2, AT2> &A2) {
1038 SquareMatrix<Var, typename OperatorResult<AT1, AT2>::Type> A3(A1.size(), NONINIT);
1042 template <
class AT1,
class AT2,
class Row>
1043 inline SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> operator*(
const SquareMatrix<Row, AT1> &A1,
const SquareMatrix<Row, AT2> &A2) {
1044 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> A3(A1.size(), NONINIT);
1050 template <
class AT1,
class AT2,
class Row1,
class Row2>
1051 inline Matrix<General, Var, Var, typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Symmetric, Row1, Row1, AT1> &A1,
const Matrix<Symmetric, Row2, Row2, AT2> &A2) {
1052 Matrix<General, Var, Var, typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1056 template <
class AT1,
class AT2,
class Row>
1057 inline Matrix<General, Row, Row, typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Symmetric, Row, Row, AT1> &A1,
const Matrix<Symmetric, Row, Row, AT2> &A2) {
1058 Matrix<General, Row, Row, typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1071 template <
class Row,
class AT1,
class AT2>
1076 for (
int i = 0; i < x.size(); i++)
1077 y.e(i) = x.e(i) * alpha;
1082 template <
class Row>
1083 Vector<Row, double> operator*(Vector<Row, double> &&x,
const double& alpha) {
1084 for (
int i = 0; i < x.size(); i++)
1086 return std::move(x);
1093 template <
class Row,
class AT1,
class AT2>
1098 for (
int i = 0; i < x.size(); i++)
1099 y.e(i) = x.e(i) * alpha;
1104 template <
class Row>
1105 Vector<Row, double> operator*(
const double& alpha, Vector<Row, double> &&x) {
1106 for (
int i = 0; i < x.size(); i++)
1108 return std::move(x);
1111 template <
class Row,
class AT1,
class AT2>
1112 inline Vector<Row, AT1> operator*=(Vector<Row, AT1> &x,
const AT2 &alpha) {
1113 for (
int i = 0; i < x.size(); i++)
1118 template <
class Row,
class AT1,
class AT2>
1119 inline Vector<Row, typename OperatorResult<AT1, AT2>::Type> operator/(
const Vector<Row, AT1> &x,
const AT2 &alpha) {
1120 Vector<Row, typename OperatorResult<AT1, AT2>::Type> y(x.size(), NONINIT);
1121 for (
int i = 0; i < x.size(); i++)
1122 y.e(i) = x.e(i) / alpha;
1126 template <
class Row>
1127 inline Vector<Row, double> operator/(Vector<Row, double> &&x,
const double &alpha) {
1128 for (
int i = 0; i < x.size(); i++)
1130 return std::move(x);
1133 template <
class Row,
class AT1,
class AT2>
1134 inline Vector<Row, AT1> operator/=(Vector<Row, AT1> &x,
const AT2 &alpha) {
1135 for (
int i = 0; i < x.size(); i++)
1145 template <
class Col,
class AT1,
class AT2>
1150 for (
int i = 0; i < x.size(); i++)
1151 y.e(i) = x.e(i) * alpha;
1156 template <
class Col>
1157 RowVector<Col, double> operator*(RowVector<Col, double> &&x,
const double& alpha) {
1158 for (
int i = 0; i < x.size(); i++)
1160 return std::move(x);
1167 template <
class Col,
class AT1,
class AT2>
1172 for (
int i = 0; i < x.size(); i++)
1173 y.e(i) = x.e(i) * alpha;
1178 template <
class Col>
1179 RowVector<Col, double> operator*(
const double &alpha, RowVector<Col, double> &&x) {
1180 for (
int i = 0; i < x.size(); i++)
1182 return std::move(x);
1185 template <
class Col,
class AT1,
class AT2>
1186 inline RowVector<Col, AT1> operator*=(RowVector<Col, AT1> &x,
const AT2 &alpha) {
1187 for (
int i = 0; i < x.size(); i++)
1192 template <
class Col,
class AT1,
class AT2>
1193 inline RowVector<Col, typename OperatorResult<AT1, AT2>::Type> operator/(
const RowVector<Col, AT1> &x,
const AT2 &a) {
1194 RowVector<Col, typename OperatorResult<AT1, AT2>::Type> y(x.size(), NONINIT);
1195 for (
int i = 0; i < x.size(); i++)
1196 y.e(i) = x.e(i) / a;
1200 template <
class Col>
1201 inline RowVector<Col, double> operator/(RowVector<Col, double> &&x,
const double &a) {
1202 for (
int i = 0; i < x.size(); i++)
1204 return std::move(x);
1207 template <
class Col,
class AT1,
class AT2>
1208 inline RowVector<Col, AT1> operator/=(RowVector<Col, AT1> &x,
const AT2 &a) {
1209 for (
int i = 0; i < x.size(); i++)
1224 template <
class Col,
class Row,
class AT1,
class AT2>
1227 FMATVEC_ASSERT(x.size() == y.size(), AT2);
1231 for (
int i = 0; i < x.size(); i++)
1232 res += x.e(i) * y.e(i);
1242 template <
class Row,
class AT>
1245 FMATVEC_ASSERT(x.size() == y.size(), AT);
1249 for (
int i = 0; i < x.size(); i++)
1250 res += x.e(i) * y.e(i);
1260 template <
class Row1,
class Row2,
class AT1,
class AT2>
1263 FMATVEC_ASSERT(x.size() == 3, AT2);
1264 FMATVEC_ASSERT(y.size() == 3, AT2);
1268 z.e(0) = x.e(1) * y.e(2) - x.e(2) * y.e(1);
1269 z.e(1) = x.e(2) * y.e(0) - x.e(0) * y.e(2);
1270 z.e(2) = x.e(0) * y.e(1) - x.e(1) * y.e(0);
1280 template <
class Row,
class AT>
1283 FMATVEC_ASSERT(a.size() == 3, AT);
1284 FMATVEC_ASSERT(x.size() == 3, AT);
1285 FMATVEC_ASSERT(y.size() == 3, AT);
1287 return a.e(0) * (x.e(1) * y.e(2) - x.e(2) * y.e(1)) + a.e(1) * (x.e(2) * y.e(0) - x.e(0) * y.e(2)) + a.e(2) * (x.e(0) * y.e(1) - x.e(1) * y.e(0));
1302 template <
class Type,
class Row,
class Col,
class AT1,
class AT2>
1307 for (
int i = 0; i < A.
rows(); i++)
1308 for (
int j = 0; j < A.
cols(); j++)
1309 B.e(i, j) = A.e(i, j) * alpha;
1314 template <
class Type,
class Row,
class Col>
1315 Matrix<Type, Row, Col, double> operator*(Matrix<Type, Row, Col, double> &&A,
const double &alpha) {
1316 for (
int i = 0; i < A.rows(); i++)
1317 for (
int j = 0; j < A.cols(); j++)
1319 return std::move(A);
1322 template <
class Type,
class Row,
class Col,
class AT1,
class AT2>
1323 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> operator*(
const AT1 &alpha,
const Matrix<Type, Row, Col, AT2> &A) {
1325 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> B(A.rows(), A.cols(), NONINIT);
1327 for (
int i = 0; i < A.rows(); i++)
1328 for (
int j = 0; j < A.cols(); j++)
1329 B.e(i, j) = A.e(i, j) * alpha;
1334 template <
class Type,
class Row,
class Col>
1335 Matrix<Type, Row, Col, double> operator*(
const double &alpha, Matrix<Type, Row, Col, double> &&A) {
1336 for (
int i = 0; i < A.rows(); i++)
1337 for (
int j = 0; j < A.cols(); j++)
1339 return std::move(A);
1342 template <
class Row,
class AT1,
class AT2>
1343 inline Matrix<Symmetric, Row, Row, typename OperatorResult<AT1, AT2>::Type> operator*(
const AT1 &alpha,
const Matrix<Symmetric, Row, Row, AT2> &A) {
1344 Matrix<Symmetric, Row, Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), A.size(), NONINIT);
1345 for (
int i = 0; i < A.size(); i++)
1346 for (
int j = i; j < A.size(); j++)
1347 B.ej(i, j) = A.ej(i, j) * alpha;
1351 template <
class Row>
1352 inline Matrix<Symmetric, Row, Row, double> operator*(
const double &alpha, Matrix<Symmetric, Row, Row, double> &&A) {
1353 for (
int i = 0; i < A.size(); i++)
1354 for (
int j = i; j < A.size(); j++)
1355 A.ej(i, j) *= alpha;
1356 return std::move(A);
1359 template <
class Row,
class AT1,
class AT2>
1360 inline Matrix<Symmetric, Row, Row, typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Symmetric, Row, Row, AT1> &A,
const AT2 &alpha) {
1361 Matrix<Symmetric, Row, Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), A.size(), NONINIT);
1362 for (
int i = 0; i < A.size(); i++)
1363 for (
int j = i; j < A.size(); j++)
1364 B.ej(i, j) = A.ej(i, j) * alpha;
1368 template <
class Row>
1369 inline Matrix<Symmetric, Row, Row, double> operator*(Matrix<Symmetric, Row, Row, double> &&A,
const double &alpha) {
1370 for (
int i = 0; i < A.size(); i++)
1371 for (
int j = i; j < A.size(); j++)
1372 A.ej(i, j) *= alpha;
1373 return std::move(A);
1376 template <
class AT1,
class AT2>
1377 inline Matrix<Diagonal, Ref, Ref, typename OperatorResult<AT1, AT2>::Type> operator*(
const AT1 &alpha,
const Matrix<Diagonal, Ref, Ref, AT2> &A) {
1378 Matrix<Diagonal, Ref, Ref, typename OperatorResult<AT1, AT2>::Type> B(A.rows(), A.cols(), NONINIT);
1379 for (
int i = 0; i < A.rows(); i++)
1380 B.e(i) = A.e(i) * alpha;
1384 inline Matrix<Diagonal, Ref, Ref, double> operator*(
const double &alpha, Matrix<Diagonal, Ref, Ref, double> &&A) {
1385 for (
int i = 0; i < A.rows(); i++)
1387 return std::move(A);
1390 template <
class AT1,
class AT2>
1391 inline Matrix<Diagonal, Ref, Ref, typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Diagonal, Ref, Ref, AT1> &A,
const AT2 &alpha) {
1392 Matrix<Diagonal, Ref, Ref, typename OperatorResult<AT1, AT2>::Type> B(A.rows(), A.cols(), NONINIT);
1393 for (
int i = 0; i < A.size(); i++)
1394 B.e(i) = A.e(i) * alpha;
1398 inline Matrix<Diagonal, Ref, Ref, double> operator*(Matrix<Diagonal, Ref, Ref, double> &&A,
const double &alpha) {
1399 for (
int i = 0; i < A.size(); i++)
1401 return std::move(A);
1404 template <
class Type,
class Row,
class Col,
class AT1,
class AT2>
1405 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> operator/(
const Matrix<Type, Row, Col, AT1> &A,
const AT2 &alpha) {
1407 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> B(A.rows(), A.cols(), NONINIT);
1409 for (
int i = 0; i < A.rows(); i++)
1410 for (
int j = 0; j < A.cols(); j++)
1411 B.e(i, j) = A.e(i, j) / alpha;
1416 template <
class Type,
class Row,
class Col>
1417 Matrix<Type, Row, Col, double> operator/(Matrix<Type, Row, Col, double> &&A,
const double &alpha) {
1418 for (
int i = 0; i < A.rows(); i++)
1419 for (
int j = 0; j < A.cols(); j++)
1421 return std::move(A);
1424 template <
class Row,
class AT1,
class AT2>
1425 inline Matrix<Symmetric, Row, Row, typename OperatorResult<AT1, AT2>::Type> operator/(
const Matrix<Symmetric, Row, Row, AT1> &A,
const AT2 &alpha) {
1426 Matrix<Symmetric, Row, Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), A.size(), NONINIT);
1427 for (
int i = 0; i < A.size(); i++)
1428 for (
int j = i; j < A.size(); j++)
1429 B.ej(i, j) = A.ej(i, j) / alpha;
1433 template <
class Row>
1434 inline Matrix<Symmetric, Row, Row, double> operator/(Matrix<Symmetric, Row, Row, double> &&A,
const double &alpha) {
1435 for (
int i = 0; i < A.size(); i++)
1436 for (
int j = i; j < A.size(); j++)
1437 A.ej(i, j) /= alpha;
1438 return std::move(A);
1441 template <
class Row,
class AT1,
class AT2>
1442 inline Matrix<Diagonal, Row, Row, typename OperatorResult<AT1, AT2>::Type> operator/(
const Matrix<Diagonal, Row, Row, AT1> &A,
const AT2 &alpha) {
1443 Matrix<Diagonal, Row, Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), A.size(), NONINIT);
1444 for (
int i = 0; i < A.size(); i++)
1445 B.e(i) = A.e(i) / alpha;
1449 template <
class Row>
1450 inline Matrix<Diagonal, Row, Row, double> operator/(Matrix<Diagonal, Row, Row, double> &&A,
const double &alpha) {
1451 for (
int i = 0; i < A.size(); i++)
1453 return std::move(A);
1456 template <
class Row,
class AT1,
class AT2>
1457 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> operator*(
const SquareMatrix<Row, AT1> &A,
const AT2 &alpha) {
1459 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), NONINIT);
1461 for (
int i = 0; i < A.size(); i++)
1462 for (
int j = 0; j < A.size(); j++)
1463 B.e(i, j) = A.e(i, j) * alpha;
1468 template <
class Row>
1469 SquareMatrix<Row, double> operator*(SquareMatrix<Row, double> &&A,
const double &alpha) {
1470 for (
int i = 0; i < A.size(); i++)
1471 for (
int j = 0; j < A.size(); j++)
1473 return std::move(A);
1476 template <
class Row,
class AT1,
class AT2>
1477 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> operator*(
const AT1 &alpha,
const SquareMatrix<Row, AT2> &A) {
1479 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), NONINIT);
1481 for (
int i = 0; i < A.size(); i++)
1482 for (
int j = 0; j < A.size(); j++)
1483 B.e(i, j) = A.e(i, j) * alpha;
1488 template <
class Row>
1489 SquareMatrix<Row, double> operator*(
const double &alpha, SquareMatrix<Row, double> &&A) {
1490 for (
int i = 0; i < A.size(); i++)
1491 for (
int j = 0; j < A.size(); j++)
1493 return std::move(A);
1496 template <
class Row,
class AT1,
class AT2>
1497 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> operator/(
const SquareMatrix<Row, AT1> &A,
const AT2 &alpha) {
1499 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), NONINIT);
1501 for (
int i = 0; i < A.size(); i++)
1502 for (
int j = 0; j < A.size(); j++)
1503 B.e(i, j) = A.e(i, j) / alpha;
1508 template <
class Row>
1509 SquareMatrix<Row, double> operator/(SquareMatrix<Row, double> &&A,
const double &alpha) {
1510 for (
int i = 0; i < A.size(); i++)
1511 for (
int j = 0; j < A.size(); j++)
1513 return std::move(A);
1516 template <
class Type,
class Row,
class Col,
class AT1,
class AT2>
1517 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> operator*=(Matrix<Type, Row, Col, AT1> &A,
const AT2 &alpha) {
1518 for (
int i = 0; i < A.rows(); i++)
1519 for (
int j = 0; j < A.cols(); j++)
1525 template <
class Row,
class AT1,
class AT2>
1526 inline Matrix<Symmetric, Row, Row, AT1> operator*=(Matrix<Symmetric, Row, Row, AT1> &A,
const AT2 &alpha) {
1527 for (
int i = 0; i < A.size(); i++)
1528 for (
int j = i; j < A.size(); j++)
1529 A.ej(i, j) *= alpha;
1533 template <
class Row,
class AT1,
class AT2>
1534 inline Matrix<Diagonal, Row, Row, AT1> operator*=(Matrix<Diagonal, Row, Row, AT1> &A,
const AT2 &alpha) {
1535 for (
int i = 0; i < A.size(); i++)
1540 template <
class Type,
class Row,
class Col,
class AT1,
class AT2>
1541 Matrix<Type, Row, Col, AT1> operator/=(Matrix<Type, Row, Col, AT1> &A,
const AT2 &alpha) {
1542 for (
int i = 0; i < A.rows(); i++)
1543 for (
int j = 0; j < A.cols(); j++)
1549 template <
class Row,
class AT1,
class AT2>
1550 inline Matrix<Symmetric, Row, Row, AT1> operator/=(Matrix<Symmetric, Row, Row, AT1> &A,
const AT2 &alpha) {
1551 for (
int i = 0; i < A.size(); i++)
1552 for (
int j = i; j < A.size(); j++)
1553 A.ej(i, j) /= alpha;
1557 template <
class Row,
class AT1,
class AT2>
1558 inline Matrix<Diagonal, Row, Row, AT1> operator/=(Matrix<Diagonal, Row, Row, AT1> &A,
const AT2 &alpha) {
1559 for (
int i = 0; i < A.size(); i++)
1573 template <
class Row,
class AT>
1578 for (
int i = 0; i < x.size(); i++)
1584 template <
class Row>
1585 Vector<Row, double> operator-(Vector<Row, double> &&x) {
1586 for (
int i = 0; i < x.size(); i++)
1588 return std::move(x);
1596 template <
class Col,
class AT>
1601 for (
int i = 0; i < a.size(); i++)
1607 template <
class Col>
1608 RowVector<Col, double> operator-(RowVector<Col, double> &&a) {
1609 for (
int i = 0; i < a.size(); i++)
1611 return std::move(a);
1619 template <
class Row,
class AT>
1624 for (
int i = 0; i < A.size(); i++)
1625 for (
int j = 0; j < A.size(); j++)
1626 B.e(i, j) = -A.e(i, j);
1631 template <
class Row>
1632 SquareMatrix<Row, double> operator-(SquareMatrix<Row, double> &&A) {
1633 for (
int i = 0; i < A.size(); i++)
1634 for (
int j = 0; j < A.size(); j++)
1635 A.e(i, j) = -A.e(i, j);
1636 return std::move(A);
1644 template <
class Type,
class Row,
class Col,
class AT>
1649 for (
int i = 0; i < A.
rows(); i++)
1650 for (
int j = 0; j < A.
cols(); j++)
1651 B.e(i, j) = -A.e(i, j);
1656 template <
class Type,
class Row,
class Col>
1657 Matrix<Type, Row, Col, double> operator-(Matrix<Type, Row, Col, double> &&A) {
1658 for (
int i = 0; i < A.rows(); i++)
1659 for (
int j = 0; j < A.cols(); j++)
1660 A.e(i, j) = -A.e(i, j);
1661 return std::move(A);
1672 template <
class Row,
class AT>
1675 inline RowVector<Var,double>
trans(Vector<Var,double> &&x) {
return std::move(x).T(); }
1684 template <
class Col,
class AT>
1687 inline Vector<Var,double>
trans(RowVector<Var,double> &&x) {
return std::move(x).T(); }
1697 template <
class Type,
class Row,
class Col,
class AT>
1708 template <
class Row,
class AT>
1748 template <
class Row,
class AT>
1749 inline AT nrmInf(
const Vector<Row, AT> &x) {
1751 for (
int i = 0; i < x.size(); i++)
1752 if (c < fabs(x.e(i)))
1757 template <
class Row,
class AT>
1758 inline AT nrmInf(
const RowVector<Row, AT> &x) {
1760 for (
int i = 0; i < x.size(); i++)
1761 if (c < fabs(x.e(i)))
1766 template <
class Row,
class AT>
1767 inline typename OperatorResult<AT, AT>::Type nrm2(
const Vector<Row, AT> &x) {
1768 typename OperatorResult<AT, AT>::Type c=
typename OperatorResult<AT, AT>::Type();
1769 for (
int i = 0; i < x.size(); i++)
1770 c += pow(x.e(i), 2);
1774 template <
class Col,
class AT>
1775 inline typename OperatorResult<AT, AT>::Type nrm2(
const RowVector<Col, AT> &x) {
1776 typename OperatorResult<AT, AT>::Type c=
typename OperatorResult<AT, AT>::Type();
1777 for (
int i = 0; i < x.size(); i++)
1778 c += pow(x.e(i), 2);
1795 template <
class Row,
class AT>
1803 B.e(0, 1) = -x.e(2);
1806 B.e(1, 2) = -x.e(0);
1807 B.e(2, 0) = -x.e(1);
1818 template <
class AT,
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2>
1827 for (
int i = 0; i < A.
rows(); i++)
1828 for (
int j = 0; j < A.
cols(); j++)
1829 if (A(i, j) != B(i, j))
1840 template <
class AT,
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2>
1846 for (
int i = 0; i < A.
rows(); i++)
1847 for (
int j = 0; j < A.
cols(); j++)
1848 if (A(i, j) != B(i, j))
1859 template <
class Row,
class AT>
1862 FMATVEC_ASSERT(x.size() > 0, AT);
1863 AT maximum = x.e(0);
1864 for (
int i = 1; i < x.size(); i++) {
1865 if (x.e(i) > maximum)
1876 template <
class Row,
class AT>
1879 FMATVEC_ASSERT(x.size() > 0, AT);
1880 AT maximum = x.e(0);
1882 for (
int i = 1; i < x.size(); i++) {
1883 if (x.e(i) > maximum) {
1896 template <
class Row,
class AT>
1899 FMATVEC_ASSERT(x.size() > 0, AT);
1900 AT minimum = x.e(0);
1901 for (
int i = 1; i < x.size(); i++) {
1902 if (x.e(i) < minimum)
1913 template <
class Row,
class AT>
1916 FMATVEC_ASSERT(x.size() > 0, AT);
1917 AT minimum = x.e(0);
1919 for (
int i = 1; i < x.size(); i++) {
1920 if (x.e(i) < minimum) {
1938 FMATVEC_ASSERT(A_.
rows() > 0, AT);
1939 FMATVEC_ASSERT(A_.
cols() > 0, AT);
1940 FMATVEC_ASSERT(A_.
cols() > PivotCol, AT);
1945 for (i = 1; i <= N - 1; i++) {
1946 for (j = 0; j < N - 1; j++) {
1947 if (A(j, PivotCol) > A(j + 1, PivotCol)) {
1949 A.set(j, A.row(j + 1));
1963 int i = l - 1, j = r;
1966 int m = l + (r - l) / 2;
1967 if (A(l, PivotCol) > A(m, PivotCol)) {
1972 if (A(l, PivotCol) > A(r, PivotCol)) {
1977 else if (A(r, PivotCol) > A(m, PivotCol)) {
1985 while(A(++i,PivotCol) < A(r,PivotCol));
1986 while(A(--j,PivotCol) > A(r,PivotCol) && j>i);
2018 template <
class Row,
class Col,
class AT>
2019 inline Matrix<Symmetric, Col, Col, AT> JTJ(
const Matrix<General, Row, Col, AT> &A) {
2020 Matrix<Symmetric, Col, Col, AT> S(A.cols(), A.cols(), NONINIT);
2021 for (
int i = 0; i < A.cols(); i++) {
2022 for (
int k = i; k < A.cols(); k++) {
2024 for (
int j = 0; j < A.rows(); j++)
2025 S.ej(i, k) += A.e(j, i) * A.e(j, k);
2031 template <
class Row,
class Col,
class AT>
2032 inline Matrix<Symmetric, Col, Col, AT> JTMJ(
const Matrix<Symmetric, Row, Row, AT> &B,
const Matrix<General, Row, Col, AT> &A) {
2034 Matrix<Symmetric, Col, Col, AT> S(A.cols(), A.cols(), NONINIT);
2035 Matrix<General, Row, Col, AT> C = B * A;
2037 for (
int i = 0; i < A.cols(); i++) {
2038 for (
int k = i; k < A.cols(); k++) {
2040 for (
int j = 0; j < A.rows(); j++)
2041 S.ej(i, k) += A.e(j, i) * C.e(j, k);
2047 template <
class Row,
class Col,
class AT>
2048 inline Matrix<Symmetric, Row, Row, AT> JMJT(
const Matrix<General, Row, Col, AT> &A,
const Matrix<Symmetric, Col, Col, AT> &B) {
2050 Matrix<Symmetric, Row, Row, AT> S(A.rows(), A.rows(), NONINIT);
2051 Matrix<General, Row, Col, AT> C = A * B;
2053 for (
int i = 0; i < S.size(); i++) {
2054 for (
int k = i; k < S.size(); k++) {
2056 for (
int j = 0; j < A.cols(); j++)
2057 S.ej(i, k) += C.e(k, j) * A.e(i, j);
RowVector< Row, AT > trans(const Vector< Row, AT > &x)
Transpose of a vector.
Definition: linear_algebra.h:1673
Matrix< General, Ref, Ref, AT > quickSortMedian(const Matrix< General, Ref, Ref, AT > &A_, int PivotCol)
Modified QuickSort Algorithm (unstable sorting Algorithm )
Definition: linear_algebra.h:2010
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:41
int rows() const
Number of rows.
Definition: general_matrix.h:304
void quicksortmedian_intern(Matrix< General, Ref, Ref, AT > &A, int PivotCol, RowVector< Ref, AT > &tmp, int l, int r)
Definition: linear_algebra.h:1960
int minIndex(const Vector< Row, AT > &x)
Index of minimum value.
Definition: linear_algebra.h:1914
Vector< Fixed< 3 >, typename OperatorResult< AT1, AT2 >::Type > crossProduct(const Vector< Row1, AT1 > &x, const Vector< Row2, AT2 > &y)
Cross product.
Definition: linear_algebra.h:1261
This is a rowvector class of general shape in dense storage format.
Definition: row_vector.h:36
AT min(const Vector< Row, AT > &x)
Minimum value.
Definition: linear_algebra.h:1897
Matrix< General, Ref, Ref, AT > bubbleSort(const Matrix< General, Ref, Ref, AT > &A_, int PivotCol)
Bubble Sort Algorithm (stable sorting Algorithm )
Definition: linear_algebra.h:1936
int maxIndex(const Vector< Row, AT > &x)
Index of maximum value.
Definition: linear_algebra.h:1877
int cols() const
Number of columns.
This is a matrix class for general matrices.
Definition: general_matrix.h:41
Namespace fmatvec.
Definition: _memory.cc:28
bool operator==(const Matrix< Type1, Row1, Col1, AT > &A, const Matrix< Type2, Row2, Col2, AT > &B)
Matrix-matrix comparison.
Definition: linear_algebra.h:1819
int cols() const
Number of columns.
Definition: general_matrix.h:310
const RowVector< Ref, AT > row(int i) const
Row operator.
Definition: general_matrix.h:516
bool operator!=(const Matrix< Type1, Row1, Col1, AT > &A, const Matrix< Type2, Row2, Col2, AT > &B)
Matrix-matrix comparison.
Definition: linear_algebra.h:1841
AT max(const Vector< Row, AT > &x)
Maximum value.
Definition: linear_algebra.h:1860
double tripleProduct(const Vector< Row, AT > &a, const Vector< Row, AT > &x, const Vector< Row, AT > &y)
Triple product.
Definition: linear_algebra.h:1281
SquareMatrix< Row, AT > tilde(const Vector< Row, AT > &x)
Tilde operator.
Definition: linear_algebra.h:1796
int rows() const
Number of rows.
AT scalarProduct(const Vector< Row, AT > &x, const Vector< Row, AT > &y)
Scalar product.
Definition: linear_algebra.h:1243