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" 39 #include "sparse_matrix.h" 40 #include "symmetric_sparse_matrix.h" 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*(
const std::complex<T> &x,
int y);
49 template<
class T> std::complex<T> operator/(
const std::complex<T> &x,
int 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);
52 template<
class T> std::complex<T> operator*(
int x,
const std::complex<T> &y);
53 template<
class T> std::complex<T> operator/(
int x,
const std::complex<T> &y);
58 template <
class Row1,
class Row2,
class Row3,
class AT1,
class AT2,
class AT3>
59 inline void add(
const Vector<Row1, AT1> &a1,
const Vector<Row2, AT2> &a2, Vector<Row3, AT3> &a3) {
60 FMATVEC_ASSERT(a1.size() == a2.size(), AT3);
61 for (
int i = 0; i < a1.size(); i++)
62 a3.e(i) = a1.e(i) + a2.e(i);
65 template <
class Row1,
class Row2,
class AT>
66 inline void add(Vector<Row1, AT> &a1,
const Vector<Row2, AT> &a2) {
67 FMATVEC_ASSERT(a1.size() == a2.size(), AT);
68 for (
int i = 0; i < a1.size(); i++)
72 template <
class Row1,
class Row2,
class Row3,
class AT1,
class AT2>
74 FMATVEC_ASSERT(a1.size() == a2.size(), AT2);
75 for (
int i = 0; i < a1.size(); i++)
76 a3.e(i) = a1.e(i) - a2.e(i);
79 template <
class Row1,
class Row2,
class AT1,
class AT2>
80 inline void sub(Vector<Row1, AT1> &a1,
const Vector<Row2, AT2> &a2) {
81 FMATVEC_ASSERT(a1.size() == a2.size(), AT2);
82 for (
int i = 0; i < a1.size(); i++)
87 template <
class AT1,
class AT2,
class Row1,
class Row2>
88 inline Vector<Var, typename OperatorResult<AT1, AT2>::Type> operator+(
const Vector<Row1, AT1> &a,
const Vector<Row2, AT2> &b) {
89 Vector<Var, typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
93 template <
class AT1,
class AT2,
class Row>
94 inline Vector<Row, typename OperatorResult<AT1, AT2>::Type> operator+(
const Vector<Row, AT1> &a,
const Vector<Row, AT2> &b) {
95 Vector<Row, typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
99 template <
class AT1,
class AT2,
int M,
class Row>
100 inline Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Vector<Fixed<M>, AT1> &a,
const Vector<Row, AT2> &b) {
101 Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
105 template <
class AT1,
class AT2,
int M>
106 inline Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Vector<Fixed<M>, AT1> &a,
const Vector<Fixed<M>, AT2> &b) {
107 Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
112 template <
class Row1,
class Row2>
113 inline Vector<Row2, double> operator+(Vector<Row1, double> &&a, Vector<Row2, double> &&b) {
117 template <
class Row1,
class Row2>
118 inline Vector<Row1, double> operator+(Vector<Row1, double> &&a,
const Vector<Row2, double> &b) {
122 template <
class Row1,
class Row2>
123 inline Vector<Row2, double> operator+(
const Vector<Row1, double> &a, Vector<Row2, double> &&b) {
127 template <
class AT,
class Row1,
class Row2>
128 inline Vector<Row1, AT> operator+=(Vector<Row1, AT> &a,
const Vector<Row2, AT> &b) {
134 template <
class AT1,
class AT2,
class Row1,
class Row2>
135 inline Vector<Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Vector<Row1, AT1> &a,
const Vector<Row2, AT2> &b) {
136 Vector<Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
140 template <
class AT1,
class AT2,
class Row>
141 inline Vector<Row, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Vector<Row, AT1> &a,
const Vector<Row, AT2> &b) {
142 Vector<Row, typename fmatvec::OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
146 template <
class AT1,
class AT2,
int M,
class Row2>
152 template <
class AT1,
class AT2,
int M>
159 template <
class Row1,
class Row2>
160 inline Vector<Row2, double> operator-(Vector<Row1, double> &&a, Vector<Row2, double> &&b) {
164 template <
class Row1,
class Row2>
165 inline Vector<Row1, double> operator-(Vector<Row1, double> &&a,
const Vector<Row2, double> &b) {
169 template <
class Row1,
class Row2>
170 inline Vector<Row2, double> operator-(
const Vector<Row1, double> &a, Vector<Row2, double> &&b) {
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) {
297 template <
class AT,
class Col1,
class Col2>
298 inline RowVector<Col1, AT> operator-=(RowVector<Col1, AT> &a,
const RowVector<Col2, AT> &b) {
304 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>
305 inline void add(
const Matrix<Type1, Row1, Col1, AT1> &A1,
const Matrix<Type2, Row2, Col2, AT2> &A2, Matrix<Type3, Row3, Col3, AT3> &A3) {
306 FMATVEC_ASSERT(A1.rows() == A2.rows(), AT3);
307 FMATVEC_ASSERT(A1.cols() == A2.cols(), AT3);
308 for (
int i = 0; i < A1.rows(); i++)
309 for (
int j = 0; j < A2.cols(); j++)
310 A3.e(i, j) = A1.e(i, j) + A2.e(i, j);
313 template <
class Row1,
class Row2,
class Row3,
class AT>
314 inline void add(
const Matrix<Symmetric, Row1, Row1, AT> &A1,
const Matrix<Symmetric, Row2, Row2, AT> &A2, Matrix<Symmetric, Row3, Row3, AT> &A3) {
315 FMATVEC_ASSERT(A1.size() == A2.size(), AT);
316 for (
int i = 0; i < A1.size(); i++)
317 for (
int j = i; j < A2.size(); j++)
318 A3.ej(i, j) = A1.ej(i, j) + A2.ej(i, j);
321 template <
class Row1,
class Row2,
class Row3,
class AT>
322 inline void add(
const Matrix<Diagonal, Row1, Row1, AT> &A1,
const Matrix<Diagonal, Row2, Row2, AT> &A2, Matrix<Diagonal, Row3, Row3, AT> &A3) {
323 FMATVEC_ASSERT(A1.size() == A2.size(), AT);
324 for (
int i = 0; i < A3.size(); i++)
325 A3.e(i) = A1.e(i) + A2.e(i);
328 template <
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2,
class AT>
329 inline void add(Matrix<Type1, Row1, Col1, AT> &A1,
const Matrix<Type2, Row2, Col2, AT> &A2) {
330 FMATVEC_ASSERT(A1.rows() == A2.rows(), AT);
331 FMATVEC_ASSERT(A1.cols() == A2.cols(), AT);
332 for (
int i = 0; i < A1.rows(); i++)
333 for (
int j = 0; j < A2.cols(); j++)
334 A1.e(i, j) += A2.e(i, j);
337 template <
class Row1,
class Row2,
class AT>
338 inline void add(Matrix<Symmetric, Row1, Row1, AT> &A1,
const Matrix<Symmetric, Row2, Row2, AT> &A2) {
339 FMATVEC_ASSERT(A1.size() == A2.size(), AT);
340 for (
int i = 0; i < A1.size(); i++)
341 for (
int j = i; j < A2.size(); j++)
342 A1.ej(i, j) += A2.ej(i, j);
345 template <
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2,
class Type3,
class Row3,
class Col3,
class AT1,
class AT2>
346 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) {
347 FMATVEC_ASSERT(A1.rows() == A2.rows(), AT2);
348 FMATVEC_ASSERT(A1.cols() == A2.cols(), AT2);
349 for (
int i = 0; i < A1.rows(); i++)
350 for (
int j = 0; j < A2.cols(); j++)
351 A3.e(i, j) = A1.e(i, j) - A2.e(i, j);
354 template <
class Row1,
class Row2,
class Row3,
class AT1,
class AT2>
355 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) {
356 FMATVEC_ASSERT(A1.size() == A2.size(), AT2);
357 for (
int i = 0; i < A1.size(); i++)
358 for (
int j = i; j < A2.size(); j++)
359 A3.ej(i, j) = A1.ej(i, j) - A2.ej(i, j);
362 template <
class Row1,
class Row2,
class Row3,
class AT1,
class AT2>
363 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) {
364 FMATVEC_ASSERT(A1.size() == A2.size(), AT2);
365 for (
int i = 0; i < A3.size(); i++)
366 A3.e(i) = A1.e(i) - A2.e(i);
369 template <
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2,
class AT1,
class AT2>
370 inline void sub(Matrix<Type1, Row1, Col1, AT1> &A1,
const Matrix<Type2, Row2, Col2, AT2> &A2) {
371 FMATVEC_ASSERT(A1.rows() == A2.rows(), AT2);
372 FMATVEC_ASSERT(A1.cols() == A2.cols(), AT2);
373 for (
int i = 0; i < A1.rows(); i++)
374 for (
int j = 0; j < A2.cols(); j++)
375 A1.e(i, j) -= A2.e(i, j);
378 template <
class Row1,
class Row2,
class AT1,
class AT2>
379 inline void sub(Matrix<Symmetric, Row1, Row1, AT1> &A1,
const Matrix<Symmetric, Row2, Row2, AT2> &A2) {
380 FMATVEC_ASSERT(A1.size() == A2.size(), AT2);
381 for (
int i = 0; i < A1.size(); i++)
382 for (
int j = i; j < A2.size(); j++)
383 A1.ej(i, j) -= A2.ej(i, j);
388 template <
class AT1,
class AT2,
class Type1,
class Type2,
class Row1,
class Col1,
class Row2,
class Col2>
389 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) {
390 Matrix<General, Var, Var, typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
394 template <
class AT1,
class AT2,
class Type1,
class Type2,
class Row,
class Col>
395 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) {
396 Matrix<General, Row, Col, typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
400 template <
class AT1,
class AT2,
int M,
class Type1,
class Type2,
class Row,
class Col>
401 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) {
402 Matrix<General, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
406 template <
class AT1,
class AT2,
int M,
class Type1,
class Type2>
407 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) {
408 Matrix<General, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
412 template <
class AT1,
class AT2,
int N,
class Type1,
class Type2,
class Row,
class Col>
413 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) {
414 Matrix<General, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
418 template <
class AT1,
class AT2,
int N,
class Type1,
class Type2>
419 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) {
420 Matrix<General, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
424 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2,
class Row,
class Col>
425 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) {
426 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
430 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
431 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) {
432 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
436 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
437 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) {
438 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
442 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
443 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) {
444 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
448 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2,
class Row,
class Col>
449 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) {
450 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
454 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
455 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) {
456 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
460 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
461 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) {
462 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
467 template <
class AT1,
class AT2,
class Type,
class Row1,
class Col1,
class Row2,
class Col2>
468 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) {
469 Matrix<Type, Var, Var, typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
473 template <
class AT1,
class AT2,
class Type,
class Row,
class Col>
474 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) {
475 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
479 template <
class AT1,
class AT2,
int M,
class Type,
class Row,
class Col>
480 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) {
481 Matrix<Type, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
485 template <
class AT1,
class AT2,
int M,
class Type>
486 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) {
487 Matrix<Type, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
491 template <
class AT1,
class AT2,
int N,
class Type,
class Row,
class Col>
492 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) {
493 Matrix<Type, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
497 template <
class AT1,
class AT2,
int N,
class Type>
498 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) {
499 Matrix<Type, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
503 template <
class AT1,
class AT2,
int M,
int N,
class Type,
class Row,
class Col>
504 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) {
505 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
509 template <
class AT1,
class AT2,
int M,
int N,
class Type>
510 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) {
511 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
515 template <
class AT1,
class AT2,
int M,
int N,
class Type>
516 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) {
517 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
521 template <
class AT1,
class AT2,
int M,
int N,
class Type>
522 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) {
523 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
527 template <
class AT1,
class AT2,
int M,
int N,
class Type,
class Row,
class Col>
528 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) {
529 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
533 template <
class AT1,
class AT2,
int M,
int N,
class Type>
534 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) {
535 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
539 template <
class AT1,
class AT2,
int M,
int N,
class Type>
540 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) {
541 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
546 template <
class Type1,
class Type2,
class Row1,
class Row2,
class Col1,
class Col2>
547 inline Matrix<Type2, Row2, Col2, double> operator+(Matrix<Type1, Row1, Col1, double> &&a, Matrix<Type2, Row2, Col2, double> &&b) {
551 template <
class Type1,
class Type2,
class Row1,
class Row2,
class Col1,
class Col2>
552 inline Matrix<Type1, Row1, Col1, double> operator+(Matrix<Type1, Row1, Col1, double> &&a,
const Matrix<Type2, Row2, Col2, double> &b) {
556 template <
class Type1,
class Type2,
class Row1,
class Row2,
class Col1,
class Col2>
557 inline Matrix<Type2, Row2, Col2, double> operator+(
const Matrix<Type1, Row1, Col1, double> &a, Matrix<Type2, Row2, Col2, double> &&b) {
561 template <
class AT,
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2>
562 inline Matrix<Type1, Row1, Col1, AT>& operator+=(Matrix<Type1, Row1, Col1, AT> &A,
const Matrix<Type2, Row2, Col2, AT> &B) {
569 template <
class AT1,
class AT2,
class Type1,
class Type2,
class Row1,
class Col1,
class Row2,
class Col2>
570 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) {
571 Matrix<General, Var, Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
575 template <
class AT1,
class AT2,
class Type1,
class Type2,
class Row,
class Col>
576 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) {
577 Matrix<General, Row, Col, typename fmatvec::OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
581 template <
class AT1,
class AT2,
int M,
class Type1,
class Type2,
class Row,
class Col>
582 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) {
587 template <
class AT1,
class AT2,
int M,
class Type1,
class Type2>
588 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) {
593 template <
class AT1,
class AT2,
int N,
class Type1,
class Type2,
class Row,
class Col>
594 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) {
599 template <
class AT1,
class AT2,
int N,
class Type1,
class Type2>
600 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) {
605 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2,
class Row,
class Col>
606 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) {
611 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
612 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) {
617 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
618 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) {
623 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
624 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) {
629 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2,
class Row,
class Col>
630 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) {
635 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
636 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) {
641 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
642 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) {
648 template <
class AT1,
class AT2,
class Type,
class Row1,
class Col1,
class Row2,
class Col2>
649 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) {
650 Matrix<Type, Var, Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
654 template <
class AT1,
class AT2,
class Type,
class Row,
class Col>
655 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) {
656 Matrix<Type, Row, Col, typename fmatvec::OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
660 template <
class AT1,
class AT2,
int M,
class Type,
class Row,
class Col>
661 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) {
666 template <
class AT1,
class AT2,
int M,
class Type>
667 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) {
672 template <
class AT1,
class AT2,
int N,
class Type,
class Row,
class Col>
673 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) {
678 template <
class AT1,
class AT2,
int N,
class Type>
679 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) {
684 template <
class AT1,
class AT2,
int M,
int N,
class Type,
class Row,
class Col>
685 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) {
690 template <
class AT1,
class AT2,
int M,
int N,
class Type>
691 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) {
696 template <
class AT1,
class AT2,
int M,
int N,
class Type>
697 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) {
702 template <
class AT1,
class AT2,
int M,
int N,
class Type>
703 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) {
708 template <
class AT1,
class AT2,
int M,
int N,
class Type,
class Row,
class Col>
709 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) {
714 template <
class AT1,
class AT2,
int M,
int N,
class Type>
715 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) {
720 template <
class AT1,
class AT2,
int M,
int N,
class Type>
721 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) {
727 template <
class Type1,
class Type2,
class Row1,
class Row2,
class Col1,
class Col2>
728 inline Matrix<Type2, Row2, Col2, double> operator-(Matrix<Type1, Row1, Col1, double> &&a, Matrix<Type2, Row2, Col2, double> &&b) {
732 template <
class Type1,
class Type2,
class Row1,
class Row2,
class Col1,
class Col2>
733 inline Matrix<Type1, Row1, Col1, double> operator-(Matrix<Type1, Row1, Col1, double> &&a,
const Matrix<Type2, Row2, Col2, double> &b) {
737 template <
class Type1,
class Type2,
class Row1,
class Row2,
class Col1,
class Col2>
738 inline Matrix<Type2, Row2, Col2, double> operator-(
const Matrix<Type1, Row1, Col1, double> &a, Matrix<Type2, Row2, Col2, double> &&b) {
742 template <
class AT,
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2>
743 inline Matrix<Type1, Row1, Col1, AT>& operator-=(Matrix<Type1, Row1, Col1, AT> &A,
const Matrix<Type2, Row2, Col2, AT> &B) {
749 template <
class AT1,
class AT2,
class Row1,
class Row2>
750 inline SquareMatrix<Var, typename OperatorResult<AT1, AT2>::Type> operator+(
const SquareMatrix<Row1, AT1> &A1,
const SquareMatrix<Row2, AT2> &A2) {
751 SquareMatrix<Var, typename OperatorResult<AT1, AT2>::Type> A3(A1.size(), NONINIT);
755 template <
class AT1,
class AT2,
class Row>
756 inline SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> operator+(
const SquareMatrix<Row, AT1> &A1,
const SquareMatrix<Row, AT2> &A2) {
757 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> A3(A1.size(), NONINIT);
762 template <
class Row1,
class Row2>
763 inline SquareMatrix<Row1, double> operator+(SquareMatrix<Row1, double> &&A1, SquareMatrix<Row2, double> &&A2) {
765 return std::move(A1);;
767 template <
class Row1,
class Row2>
768 inline SquareMatrix<Row1, double> operator+(SquareMatrix<Row1, double> &&A1,
const SquareMatrix<Row2, double> &A2) {
770 return std::move(A1);;
772 template <
class Row1,
class Row2>
773 inline SquareMatrix<Row2, double> operator+(
const SquareMatrix<Row1, double> &A1, SquareMatrix<Row2, double> &&A2) {
775 return std::move(A2);
779 template <
class AT1,
class AT2,
class Row1,
class Row2>
780 inline SquareMatrix<Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const SquareMatrix<Row1, AT1> &A1,
const SquareMatrix<Row2, AT2> &A2) {
781 SquareMatrix<Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> A3(A1.size(), NONINIT);
785 template <
class AT1,
class AT2,
class Row>
786 inline SquareMatrix<Row, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const SquareMatrix<Row, AT1> &A1,
const SquareMatrix<Row, AT2> &A2) {
787 SquareMatrix<Row, typename fmatvec::OperatorResult<AT1, AT2>::Type> A3(A1.size(), NONINIT);
792 template <
class Row1,
class Row2>
793 inline SquareMatrix<Row1, double> operator-(SquareMatrix<Row1, double> &&A1, SquareMatrix<Row2, double> &&A2) {
795 return std::move(A1);;
797 template <
class Row1,
class Row2>
798 inline SquareMatrix<Row1, double> operator-(SquareMatrix<Row1, double> &&A1,
const SquareMatrix<Row2, double> &A2) {
800 return std::move(A1);;
802 template <
class Row1,
class Row2>
803 inline SquareMatrix<Row2, double> operator-(
const SquareMatrix<Row1, double> &A1, SquareMatrix<Row2, double> &&A2) {
805 return std::move(A2);
813 template <
class Type1,
class Row1,
class Col1,
class Row2,
class Row3,
class AT1,
class AT2>
815 FMATVEC_ASSERT(A.cols() == x.size(), AT2);
816 for (
int i = 0; i < y.size(); i++) {
818 for (
int j = 0; j < x.size(); j++)
819 y.e(i) += A.e(i, j) * x.e(j);
823 template <
class Row1,
class Row2,
class Row3,
class AT1,
class AT2>
825 FMATVEC_ASSERT(A.cols() == x.size(), AT2);
826 for (
int i = 0; i < y.size(); i++) {
828 for (
int j = 0; j < i; j++)
829 y.e(i) += A.ei(i, j) * x.e(j);
830 for (
int j = i; j < x.size(); j++)
831 y.e(i) += A.ej(i, j) * x.e(j);
835 template <
class Row2,
class Row3,
class AT1,
class AT2>
837 FMATVEC_ASSERT(A.cols() == x.size(), AT2);
838 for (
int i = 0; i < y.size(); i++) {
840 for (
int j = A.Ip()[i]; j < A.Ip()[i+1]; j++)
841 y.e(i) += A()[j]*x.e(A.Jp()[j]);
845 template <
class Row2,
class Row3,
class AT1,
class AT2>
847 FMATVEC_ASSERT(A.cols() == x.size(), AT2);
848 for (
int i = 0; i < y.size(); i++)
849 y.e(i) = A()[A.Ip()[i]]*x.e(A.Jp()[A.Ip()[i]]);
850 for (
int i = 0; i < y.size(); i++) {
851 for (
int j = A.Ip()[i]+1; j < A.Ip()[i+1]; j++) {
852 y.e(i) += A()[j]*x.e(A.Jp()[j]);
853 y.e(A.Jp()[j]) += A()[j]*x.e(i);
859 template <
class AT1,
class AT2,
class Type1,
class Row1,
class Col1,
class Row2>
860 inline Vector<Var, typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type1, Row1, Col1, AT1> &A,
const Vector<Row2, AT2> &x) {
861 Vector<Var, typename OperatorResult<AT1, AT2>::Type> y(A.rows(), NONINIT);
865 template <
class AT1,
class AT2,
class Type1,
class Row,
class Col>
866 inline Vector<Row, typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type1, Row, Col, AT1> &A,
const Vector<Row, AT2> &x) {
867 Vector<Row, typename OperatorResult<AT1, AT2>::Type> y(A.rows(), NONINIT);
871 template <
class AT1,
class AT2,
int M,
class Type1,
class Col1,
class Row2>
872 inline Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type1, Fixed<M>, Col1, AT1> &A,
const Vector<Row2, AT2> &x) {
873 Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> y(A.rows(), NONINIT);
877 template <
class AT1,
class AT2,
int M,
class Type1>
878 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) {
879 Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> y(A.rows(), NONINIT);
883 template <
class AT1,
class AT2,
int M,
int N,
class Type,
class Row2>
884 inline Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type, Fixed<M>, Fixed<N>, AT1> &A,
const Vector<Row2, AT2> &x) {
885 Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> y(A.rows(), NONINIT);
889 template <
class AT1,
class AT2,
int M,
int N,
class Type>
890 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) {
891 Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> y(A.rows(), NONINIT);
897 template <
class Col1,
class Type2,
class Row2,
class Col2,
class Type3,
class Col3,
class AT1,
class AT2>
899 FMATVEC_ASSERT(x.size() == A.rows(), AT2);
900 for (
int i = 0; i < y.size(); i++) {
902 for (
int j = 0; j < x.size(); j++)
903 y.e(i) += x.e(j) * A.e(j, i);
907 template <
class Col1,
class Row2,
class Col3,
class AT1,
class AT2>
909 FMATVEC_ASSERT(x.size() == A.rows(), AT2);
910 for (
int i = 0; i < y.size(); i++) {
912 for (
int j = 0; j < i; j++)
913 y.e(i) += x.e(j) * A.ej(j, i);
914 for (
int j = i; j < x.size(); j++)
915 y.e(i) += x.e(j) * A.ei(j, i);
919 template <
class AT1,
class AT2,
class Type2,
class Col2,
class Row1,
class Col1>
920 inline RowVector<Var, typename OperatorResult<AT1, AT2>::Type> operator*(
const RowVector<Col2, AT1> &x,
const Matrix<Type2, Row1, Col1, AT2> &A) {
921 RowVector<Var, typename OperatorResult<AT1, AT2>::Type> y(A.cols(), NONINIT);
925 template <
class AT1,
class AT2,
class Type2,
class Row,
class Col>
926 inline RowVector<Col, typename OperatorResult<AT1, AT2>::Type> operator*(
const RowVector<Col, AT1> &x,
const Matrix<Type2, Row, Col, AT2> &A) {
927 RowVector<Col, typename OperatorResult<AT1, AT2>::Type> y(A.cols(), NONINIT);
931 template <
class AT1,
class AT2,
int N,
class Type2,
class Col1,
class Row2>
932 inline RowVector<Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator*(
const RowVector<Col1, AT1> &x,
const Matrix<Type2, Row2, Fixed<N>, AT2> &A) {
933 RowVector<Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> y(A.cols(), NONINIT);
937 template <
class AT1,
class AT2,
int N,
class Type2>
938 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) {
939 RowVector<Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> y(A.cols(), NONINIT);
945 template <
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2,
class Type3,
class Row3,
class Col3,
class AT1,
class AT2>
946 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) {
947 FMATVEC_ASSERT(A1.cols() == A2.rows(), AT2);
948 for (
int i = 0; i < A3.rows(); i++) {
949 for (
int k = 0; k < A3.cols(); k++) {
951 for (
int j = 0; j < A1.cols(); j++)
952 A3.e(i, k) += A1.e(i, j) * A2.e(j, k);
956 template <
class Row1,
class Type2,
class Row2,
class Col2,
class Type3,
class Row3,
class Col3,
class AT1,
class AT2>
957 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) {
958 FMATVEC_ASSERT(A1.size() == A2.rows(), AT2);
959 for (
int i = 0; i < A3.rows(); i++) {
960 for (
int k = 0; k < A3.cols(); k++) {
962 for (
int j = 0; j < i; j++)
963 A3.e(i, k) += A1.ei(i, j) * A2.e(j, k);
964 for (
int j = i; j < A1.cols(); j++)
965 A3.e(i, k) += A1.ej(i, j) * A2.e(j, k);
969 template <
class Row1,
class Row2,
class Row3,
class AT1,
class AT2>
970 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) {
971 FMATVEC_ASSERT(A1.size() == A2.size(), AT2);
972 for (
int i = 0; i < A3.size(); i++)
973 A3.e(i) = A1.e(i) * A2.e(i);
976 template <
class Type2,
class Row2,
class Col2,
class Type3,
class Row3,
class Col3,
class AT1,
class AT2>
977 inline void mult(
const Matrix<Sparse, Ref, Ref, AT1> &A1,
const Matrix<Type2, Row2, Col2, AT2> &A2, Matrix<Type3, Row3, Col3,
typename fmatvec::OperatorResult<AT1, AT2>::Type> &A3) {
978 FMATVEC_ASSERT(A1.cols() == A2.rows(), AT2);
979 for (
int i = 0; i < A3.rows(); i++) {
980 for (
int k = 0; k < A3.cols(); k++) {
982 for (
int j = A1.Ip()[i]; j < A1.Ip()[i+1]; j++)
983 A3.e(i, k) += A1()[j]*A2.e(A1.Jp()[j], k);
988 template <
class Type2,
class Row2,
class Col2,
class Type3,
class Row3,
class Col3,
class AT1,
class AT2>
989 inline void mult(
const Matrix<SymmetricSparse, Ref, Ref, AT1> &A1,
const Matrix<Type2, Row2, Col2, AT2> &A2, Matrix<Type3, Row3, Col3,
typename fmatvec::OperatorResult<AT1, AT2>::Type> &A3) {
990 FMATVEC_ASSERT(A1.size() == A2.rows(), AT2);
991 for (
int i = 0; i < A3.rows(); i++) {
992 for (
int k = 0; k < A3.cols(); k++)
993 A3.e(i, k) = A1()[A1.Ip()[i]]*A2.e(A1.Jp()[A1.Ip()[i]], k);
995 for (
int i = 0; i < A3.rows(); i++) {
996 for (
int k = 0; k < A3.cols(); k++) {
997 for (
int j = A1.Ip()[i]+1; j < A1.Ip()[i+1]; j++) {
998 A3.e(i, k) += A1()[j]*A2.e(A1.Jp()[j], k);
999 A3.e(A1.Jp()[j], k) += A1()[j]*A2.e(i, k);
1005 template <
class AT1,
class AT2,
class Type1,
class Type2,
class Row1,
class Col1,
class Row2,
class Col2>
1006 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) {
1007 Matrix<General, Var, Var, typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1011 template <
class AT1,
class AT2,
class Type1,
class Type2,
class Row,
class Col>
1012 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) {
1013 Matrix<General, Row, Col, typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1017 template <
class AT1,
class AT2,
int M,
class Type1,
class Type2,
class Col1,
class Row2,
class Col2>
1018 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) {
1019 Matrix<General, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1023 template <
class AT1,
class AT2,
int N,
class Type1,
class Row1,
class Col1,
class Type2,
class Row2>
1024 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) {
1025 Matrix<General, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1029 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2,
class Col1,
class Row2>
1030 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) {
1031 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1035 template <
class AT1,
class AT2,
int M,
class Type1,
class Type2>
1036 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) {
1037 Matrix<General, Fixed<M>, Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1041 template <
class AT1,
class AT2,
class Type,
class Row1,
class Col1,
class Row2,
class Col2>
1042 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) {
1043 Matrix<Type, Var, Var, typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1047 template <
class AT1,
class AT2,
class Type,
class Row,
class Col>
1048 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) {
1049 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1053 template <
class AT1,
class AT2,
int M,
class Type,
class Col1,
class Row2,
class Col2>
1054 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) {
1055 Matrix<Type, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1059 template <
class AT1,
class AT2,
int N,
class Type,
class Row1,
class Col1,
class Row2>
1060 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) {
1061 Matrix<Type, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1065 template <
class AT1,
class AT2,
int M,
int N,
class Type,
class Col1,
class Row2>
1066 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) {
1067 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1071 template <
class AT1,
class AT2,
int M,
class Type>
1072 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) {
1073 Matrix<Type, Fixed<M>, Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1079 template <
class AT1,
class AT2,
class Row1,
class Row2>
1080 inline SquareMatrix<Var, typename OperatorResult<AT1, AT2>::Type> operator*(
const SquareMatrix<Row1, AT1> &A1,
const SquareMatrix<Row2, AT2> &A2) {
1081 SquareMatrix<Var, typename OperatorResult<AT1, AT2>::Type> A3(A1.size(), NONINIT);
1085 template <
class AT1,
class AT2,
class Row>
1086 inline SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> operator*(
const SquareMatrix<Row, AT1> &A1,
const SquareMatrix<Row, AT2> &A2) {
1087 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> A3(A1.size(), NONINIT);
1093 template <
class AT1,
class AT2,
class Row1,
class Row2>
1094 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) {
1095 Matrix<General, Var, Var, typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1099 template <
class AT1,
class AT2,
class Row>
1100 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) {
1101 Matrix<General, Row, Row, typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1114 template <
class Row,
class AT1,
class AT2>
1119 for (
int i = 0; i < x.size(); i++)
1120 y.e(i) = x.e(i) * alpha;
1125 template <
class Row>
1126 Vector<Row, double> operator*(Vector<Row, double> &&x,
const double& alpha) {
1127 for (
int i = 0; i < x.size(); i++)
1129 return std::move(x);
1136 template <
class Row,
class AT1,
class AT2>
1141 for (
int i = 0; i < x.size(); i++)
1142 y.e(i) = x.e(i) * alpha;
1147 template <
class Row>
1148 Vector<Row, double> operator*(
const double& alpha, Vector<Row, double> &&x) {
1149 for (
int i = 0; i < x.size(); i++)
1151 return std::move(x);
1154 template <
class Row,
class AT1,
class AT2>
1155 inline Vector<Row, AT1> operator*=(Vector<Row, AT1> &x,
const AT2 &alpha) {
1156 for (
int i = 0; i < x.size(); i++)
1161 template <
class Row,
class AT1,
class AT2>
1162 inline Vector<Row, typename OperatorResult<AT1, AT2>::Type> operator/(
const Vector<Row, AT1> &x,
const AT2 &alpha) {
1163 Vector<Row, typename OperatorResult<AT1, AT2>::Type> y(x.size(), NONINIT);
1164 for (
int i = 0; i < x.size(); i++)
1165 y.e(i) = x.e(i) / alpha;
1169 template <
class Row>
1170 inline Vector<Row, double> operator/(Vector<Row, double> &&x,
const double &alpha) {
1171 for (
int i = 0; i < x.size(); i++)
1173 return std::move(x);
1176 template <
class Row,
class AT1,
class AT2>
1177 inline Vector<Row, AT1> operator/=(Vector<Row, AT1> &x,
const AT2 &alpha) {
1178 for (
int i = 0; i < x.size(); i++)
1188 template <
class Col,
class AT1,
class AT2>
1193 for (
int i = 0; i < x.size(); i++)
1194 y.e(i) = x.e(i) * alpha;
1199 template <
class Col>
1200 RowVector<Col, double> operator*(RowVector<Col, double> &&x,
const double& alpha) {
1201 for (
int i = 0; i < x.size(); i++)
1203 return std::move(x);
1210 template <
class Col,
class AT1,
class AT2>
1215 for (
int i = 0; i < x.size(); i++)
1216 y.e(i) = x.e(i) * alpha;
1221 template <
class Col>
1222 RowVector<Col, double> operator*(
const double &alpha, RowVector<Col, double> &&x) {
1223 for (
int i = 0; i < x.size(); i++)
1225 return std::move(x);
1228 template <
class Col,
class AT1,
class AT2>
1229 inline RowVector<Col, AT1> operator*=(RowVector<Col, AT1> &x,
const AT2 &alpha) {
1230 for (
int i = 0; i < x.size(); i++)
1235 template <
class Col,
class AT1,
class AT2>
1236 inline RowVector<Col, typename OperatorResult<AT1, AT2>::Type> operator/(
const RowVector<Col, AT1> &x,
const AT2 &a) {
1237 RowVector<Col, typename OperatorResult<AT1, AT2>::Type> y(x.size(), NONINIT);
1238 for (
int i = 0; i < x.size(); i++)
1239 y.e(i) = x.e(i) / a;
1243 template <
class Col>
1244 inline RowVector<Col, double> operator/(RowVector<Col, double> &&x,
const double &a) {
1245 for (
int i = 0; i < x.size(); i++)
1247 return std::move(x);
1250 template <
class Col,
class AT1,
class AT2>
1251 inline RowVector<Col, AT1> operator/=(RowVector<Col, AT1> &x,
const AT2 &a) {
1252 for (
int i = 0; i < x.size(); i++)
1267 template <
class Col,
class Row,
class AT1,
class AT2>
1270 FMATVEC_ASSERT(x.size() == y.size(), AT2);
1274 for (
int i = 0; i < x.size(); i++)
1275 res += x.e(i) * y.e(i);
1285 template <
class Row,
class AT>
1288 FMATVEC_ASSERT(x.size() == y.size(), AT);
1292 for (
int i = 0; i < x.size(); i++)
1293 res += x.e(i) * y.e(i);
1303 template <
class Row1,
class Row2,
class AT1,
class AT2>
1306 FMATVEC_ASSERT(x.size() == 3, AT2);
1307 FMATVEC_ASSERT(y.size() == 3, AT2);
1311 z.e(0) = x.e(1) * y.e(2) - x.e(2) * y.e(1);
1312 z.e(1) = x.e(2) * y.e(0) - x.e(0) * y.e(2);
1313 z.e(2) = x.e(0) * y.e(1) - x.e(1) * y.e(0);
1323 template <
class Row,
class AT>
1326 FMATVEC_ASSERT(a.size() == 3, AT);
1327 FMATVEC_ASSERT(x.size() == 3, AT);
1328 FMATVEC_ASSERT(y.size() == 3, AT);
1330 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));
1345 template <
class Type,
class Row,
class Col,
class AT1,
class AT2>
1350 for (
int i = 0; i < A.
rows(); i++)
1351 for (
int j = 0; j < A.
cols(); j++)
1352 B.e(i, j) = A.e(i, j) * alpha;
1357 template <
class Type,
class Row,
class Col>
1358 Matrix<Type, Row, Col, double> operator*(Matrix<Type, Row, Col, double> &&A,
const double &alpha) {
1359 for (
int i = 0; i < A.rows(); i++)
1360 for (
int j = 0; j < A.cols(); j++)
1362 return std::move(A);
1365 template <
class Type,
class Row,
class Col,
class AT1,
class AT2>
1366 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> operator*(
const AT1 &alpha,
const Matrix<Type, Row, Col, AT2> &A) {
1368 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> B(A.rows(), A.cols(), NONINIT);
1370 for (
int i = 0; i < A.rows(); i++)
1371 for (
int j = 0; j < A.cols(); j++)
1372 B.e(i, j) = A.e(i, j) * alpha;
1377 template <
class Type,
class Row,
class Col>
1378 Matrix<Type, Row, Col, double> operator*(
const double &alpha, Matrix<Type, Row, Col, double> &&A) {
1379 for (
int i = 0; i < A.rows(); i++)
1380 for (
int j = 0; j < A.cols(); j++)
1382 return std::move(A);
1385 template <
class Row,
class AT1,
class AT2>
1386 inline Matrix<Symmetric, Row, Row, typename OperatorResult<AT1, AT2>::Type> operator*(
const AT1 &alpha,
const Matrix<Symmetric, Row, Row, AT2> &A) {
1387 Matrix<Symmetric, Row, Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), A.size(), NONINIT);
1388 for (
int i = 0; i < A.size(); i++)
1389 for (
int j = i; j < A.size(); j++)
1390 B.ej(i, j) = A.ej(i, j) * alpha;
1394 template <
class Row>
1395 inline Matrix<Symmetric, Row, Row, double> operator*(
const double &alpha, Matrix<Symmetric, Row, Row, double> &&A) {
1396 for (
int i = 0; i < A.size(); i++)
1397 for (
int j = i; j < A.size(); j++)
1398 A.ej(i, j) *= alpha;
1399 return std::move(A);
1402 template <
class Row,
class AT1,
class AT2>
1403 inline Matrix<Symmetric, Row, Row, typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Symmetric, Row, Row, AT1> &A,
const AT2 &alpha) {
1404 Matrix<Symmetric, Row, Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), A.size(), NONINIT);
1405 for (
int i = 0; i < A.size(); i++)
1406 for (
int j = i; j < A.size(); j++)
1407 B.ej(i, j) = A.ej(i, j) * alpha;
1411 template <
class Row>
1412 inline Matrix<Symmetric, Row, Row, double> operator*(Matrix<Symmetric, Row, Row, double> &&A,
const double &alpha) {
1413 for (
int i = 0; i < A.size(); i++)
1414 for (
int j = i; j < A.size(); j++)
1415 A.ej(i, j) *= alpha;
1416 return std::move(A);
1419 template <
class AT1,
class AT2>
1420 inline Matrix<Diagonal, Ref, Ref, typename OperatorResult<AT1, AT2>::Type> operator*(
const AT1 &alpha,
const Matrix<Diagonal, Ref, Ref, AT2> &A) {
1421 Matrix<Diagonal, Ref, Ref, typename OperatorResult<AT1, AT2>::Type> B(A.rows(), A.cols(), NONINIT);
1422 for (
int i = 0; i < A.rows(); i++)
1423 B.e(i) = A.e(i) * alpha;
1427 inline Matrix<Diagonal, Ref, Ref, double> operator*(
const double &alpha, Matrix<Diagonal, Ref, Ref, double> &&A) {
1428 for (
int i = 0; i < A.rows(); i++)
1433 template <
class AT1,
class AT2>
1434 inline Matrix<Diagonal, Ref, Ref, typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Diagonal, Ref, Ref, AT1> &A,
const AT2 &alpha) {
1435 Matrix<Diagonal, Ref, Ref, typename OperatorResult<AT1, AT2>::Type> B(A.rows(), A.cols(), NONINIT);
1436 for (
int i = 0; i < A.size(); i++)
1437 B.e(i) = A.e(i) * alpha;
1441 inline Matrix<Diagonal, Ref, Ref, double> operator*(Matrix<Diagonal, Ref, Ref, double> &&A,
const double &alpha) {
1442 for (
int i = 0; i < A.size(); i++)
1447 template <
class Type,
class Row,
class Col,
class AT1,
class AT2>
1448 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> operator/(
const Matrix<Type, Row, Col, AT1> &A,
const AT2 &alpha) {
1450 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> B(A.rows(), A.cols(), NONINIT);
1452 for (
int i = 0; i < A.rows(); i++)
1453 for (
int j = 0; j < A.cols(); j++)
1454 B.e(i, j) = A.e(i, j) / alpha;
1459 template <
class Type,
class Row,
class Col>
1460 Matrix<Type, Row, Col, double> operator/(Matrix<Type, Row, Col, double> &&A,
const double &alpha) {
1461 for (
int i = 0; i < A.rows(); i++)
1462 for (
int j = 0; j < A.cols(); j++)
1464 return std::move(A);
1467 template <
class Row,
class AT1,
class AT2>
1468 inline Matrix<Symmetric, Row, Row, typename OperatorResult<AT1, AT2>::Type> operator/(
const Matrix<Symmetric, Row, Row, AT1> &A,
const AT2 &alpha) {
1469 Matrix<Symmetric, Row, Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), A.size(), NONINIT);
1470 for (
int i = 0; i < A.size(); i++)
1471 for (
int j = i; j < A.size(); j++)
1472 B.ej(i, j) = A.ej(i, j) / alpha;
1476 template <
class Row>
1477 inline Matrix<Symmetric, Row, Row, double> operator/(Matrix<Symmetric, Row, Row, double> &&A,
const double &alpha) {
1478 for (
int i = 0; i < A.size(); i++)
1479 for (
int j = i; j < A.size(); j++)
1480 A.ej(i, j) /= alpha;
1481 return std::move(A);
1484 template <
class Row,
class AT1,
class AT2>
1485 inline Matrix<Diagonal, Row, Row, typename OperatorResult<AT1, AT2>::Type> operator/(
const Matrix<Diagonal, Row, Row, AT1> &A,
const AT2 &alpha) {
1486 Matrix<Diagonal, Row, Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), A.size(), NONINIT);
1487 for (
int i = 0; i < A.size(); i++)
1488 B.e(i) = A.e(i) / alpha;
1492 template <
class Row>
1493 inline Matrix<Diagonal, Row, Row, double> operator/(Matrix<Diagonal, Row, Row, double> &&A,
const double &alpha) {
1494 for (
int i = 0; i < A.size(); i++)
1496 return std::move(A);
1499 template <
class Row,
class AT1,
class AT2>
1500 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> operator*(
const SquareMatrix<Row, AT1> &A,
const AT2 &alpha) {
1502 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), NONINIT);
1504 for (
int i = 0; i < A.size(); i++)
1505 for (
int j = 0; j < A.size(); j++)
1506 B.e(i, j) = A.e(i, j) * alpha;
1511 template <
class Row>
1512 SquareMatrix<Row, double> operator*(SquareMatrix<Row, double> &&A,
const double &alpha) {
1513 for (
int i = 0; i < A.size(); i++)
1514 for (
int j = 0; j < A.size(); j++)
1516 return std::move(A);
1519 template <
class Row,
class AT1,
class AT2>
1520 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> operator*(
const AT1 &alpha,
const SquareMatrix<Row, AT2> &A) {
1522 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), NONINIT);
1524 for (
int i = 0; i < A.size(); i++)
1525 for (
int j = 0; j < A.size(); j++)
1526 B.e(i, j) = A.e(i, j) * alpha;
1531 template <
class Row>
1532 SquareMatrix<Row, double> operator*(
const double &alpha, SquareMatrix<Row, double> &&A) {
1533 for (
int i = 0; i < A.size(); i++)
1534 for (
int j = 0; j < A.size(); j++)
1536 return std::move(A);
1539 template <
class Row,
class AT1,
class AT2>
1540 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> operator/(
const SquareMatrix<Row, AT1> &A,
const AT2 &alpha) {
1542 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), NONINIT);
1544 for (
int i = 0; i < A.size(); i++)
1545 for (
int j = 0; j < A.size(); j++)
1546 B.e(i, j) = A.e(i, j) / alpha;
1551 template <
class Row>
1552 SquareMatrix<Row, double> operator/(SquareMatrix<Row, double> &&A,
const double &alpha) {
1553 for (
int i = 0; i < A.size(); i++)
1554 for (
int j = 0; j < A.size(); j++)
1556 return std::move(A);
1559 template <
class Type,
class Row,
class Col,
class AT1,
class AT2>
1560 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> operator*=(Matrix<Type, Row, Col, AT1> &A,
const AT2 &alpha) {
1561 for (
int i = 0; i < A.rows(); i++)
1562 for (
int j = 0; j < A.cols(); j++)
1568 template <
class Row,
class AT1,
class AT2>
1569 inline Matrix<Symmetric, Row, Row, AT1> operator*=(Matrix<Symmetric, Row, Row, AT1> &A,
const AT2 &alpha) {
1570 for (
int i = 0; i < A.size(); i++)
1571 for (
int j = i; j < A.size(); j++)
1572 A.ej(i, j) *= alpha;
1576 template <
class Row,
class AT1,
class AT2>
1577 inline Matrix<Diagonal, Row, Row, AT1> operator*=(Matrix<Diagonal, Row, Row, AT1> &A,
const AT2 &alpha) {
1578 for (
int i = 0; i < A.size(); i++)
1583 template <
class Type,
class Row,
class Col,
class AT1,
class AT2>
1584 Matrix<Type, Row, Col, AT1> operator/=(Matrix<Type, Row, Col, AT1> &A,
const AT2 &alpha) {
1585 for (
int i = 0; i < A.rows(); i++)
1586 for (
int j = 0; j < A.cols(); j++)
1592 template <
class Row,
class AT1,
class AT2>
1593 inline Matrix<Symmetric, Row, Row, AT1> operator/=(Matrix<Symmetric, Row, Row, AT1> &A,
const AT2 &alpha) {
1594 for (
int i = 0; i < A.size(); i++)
1595 for (
int j = i; j < A.size(); j++)
1596 A.ej(i, j) /= alpha;
1600 template <
class Row,
class AT1,
class AT2>
1601 inline Matrix<Diagonal, Row, Row, AT1> operator/=(Matrix<Diagonal, Row, Row, AT1> &A,
const AT2 &alpha) {
1602 for (
int i = 0; i < A.size(); i++)
1616 template <
class Row,
class AT>
1621 for (
int i = 0; i < x.size(); i++)
1627 template <
class Row>
1628 Vector<Row, double> operator-(Vector<Row, double> &&x) {
1629 for (
int i = 0; i < x.size(); i++)
1631 return std::move(x);
1639 template <
class Col,
class AT>
1644 for (
int i = 0; i < a.size(); i++)
1650 template <
class Col>
1651 RowVector<Col, double> operator-(RowVector<Col, double> &&a) {
1652 for (
int i = 0; i < a.size(); i++)
1654 return std::move(a);
1662 template <
class Row,
class AT>
1667 for (
int i = 0; i < A.size(); i++)
1668 for (
int j = 0; j < A.size(); j++)
1669 B.e(i, j) = -A.e(i, j);
1674 template <
class Row>
1675 SquareMatrix<Row, double> operator-(SquareMatrix<Row, double> &&A) {
1676 for (
int i = 0; i < A.size(); i++)
1677 for (
int j = 0; j < A.size(); j++)
1678 A.e(i, j) = -A.e(i, j);
1679 return std::move(A);
1687 template <
class Type,
class Row,
class Col,
class AT>
1692 for (
int i = 0; i < A.
rows(); i++)
1693 for (
int j = 0; j < A.
cols(); j++)
1694 B.e(i, j) = -A.e(i, j);
1699 template <
class Type,
class Row,
class Col>
1700 Matrix<Type, Row, Col, double> operator-(Matrix<Type, Row, Col, double> &&A) {
1701 for (
int i = 0; i < A.rows(); i++)
1702 for (
int j = 0; j < A.cols(); j++)
1703 A.e(i, j) = -A.e(i, j);
1704 return std::move(A);
1715 template <
class Row,
class AT>
1718 inline RowVector<Var,double>
trans(Vector<Var,double> &&x) {
return std::move(x).T(); }
1727 template <
class Col,
class AT>
1730 inline Vector<Var,double>
trans(RowVector<Var,double> &&x) {
return std::move(x).T(); }
1740 template <
class Type,
class Row,
class Col,
class AT>
1751 template <
class Row,
class AT>
1791 template <
class Row,
class AT>
1792 inline AT nrmInf(
const Vector<Row, AT> &x) {
1794 for (
int i = 0; i < x.size(); i++)
1795 if (c < fabs(x.e(i)))
1800 template <
class Row,
class AT>
1801 inline AT nrmInf(
const RowVector<Row, AT> &x) {
1803 for (
int i = 0; i < x.size(); i++)
1804 if (c < fabs(x.e(i)))
1809 template <
class Row,
class AT>
1810 inline typename OperatorResult<AT, AT>::Type nrm2(
const Vector<Row, AT> &x) {
1811 typename OperatorResult<AT, AT>::Type c=
typename OperatorResult<AT, AT>::Type();
1812 for (
int i = 0; i < x.size(); i++)
1813 c += pow(x.e(i), 2);
1817 template <
class Col,
class AT>
1818 inline typename OperatorResult<AT, AT>::Type nrm2(
const RowVector<Col, AT> &x) {
1819 typename OperatorResult<AT, AT>::Type c=
typename OperatorResult<AT, AT>::Type();
1820 for (
int i = 0; i < x.size(); i++)
1821 c += pow(x.e(i), 2);
1838 template <
class Row,
class AT>
1846 B.e(0, 1) = -x.e(2);
1849 B.e(1, 2) = -x.e(0);
1850 B.e(2, 0) = -x.e(1);
1861 template <
class AT,
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2>
1870 for (
int i = 0; i < A.
rows(); i++)
1871 for (
int j = 0; j < A.
cols(); j++)
1872 if (A(i, j) != B(i, j))
1883 template <
class AT,
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2>
1889 for (
int i = 0; i < A.
rows(); i++)
1890 for (
int j = 0; j < A.
cols(); j++)
1891 if (A(i, j) != B(i, j))
1902 template <
class Row,
class AT>
1905 FMATVEC_ASSERT(x.size() > 0, AT);
1906 AT maximum = x.e(0);
1907 for (
int i = 1; i < x.size(); i++) {
1908 if (x.e(i) > maximum)
1919 template <
class Row,
class AT>
1922 FMATVEC_ASSERT(x.size() > 0, AT);
1923 AT maximum = x.e(0);
1925 for (
int i = 1; i < x.size(); i++) {
1926 if (x.e(i) > maximum) {
1939 template <
class Row,
class AT>
1942 FMATVEC_ASSERT(x.size() > 0, AT);
1943 AT minimum = x.e(0);
1944 for (
int i = 1; i < x.size(); i++) {
1945 if (x.e(i) < minimum)
1956 template <
class Row,
class AT>
1959 FMATVEC_ASSERT(x.size() > 0, AT);
1960 AT minimum = x.e(0);
1962 for (
int i = 1; i < x.size(); i++) {
1963 if (x.e(i) < minimum) {
1981 FMATVEC_ASSERT(A_.
rows() > 0, AT);
1982 FMATVEC_ASSERT(A_.
cols() > 0, AT);
1983 FMATVEC_ASSERT(A_.
cols() > PivotCol, AT);
1988 for (i = 1; i <= N - 1; i++) {
1989 for (j = 0; j < N - 1; j++) {
1990 if (A(j, PivotCol) > A(j + 1, PivotCol)) {
1992 A.set(j, A.row(j + 1));
2006 int i = l - 1, j = r;
2009 int m = l + (r - l) / 2;
2010 if (A(l, PivotCol) > A(m, PivotCol)) {
2015 if (A(l, PivotCol) > A(r, PivotCol)) {
2020 else if (A(r, PivotCol) > A(m, PivotCol)) {
2028 while(A(++i,PivotCol) < A(r,PivotCol));
2029 while(A(--j,PivotCol) > A(r,PivotCol) && j>i);
2061 template <
class Row,
class Col,
class AT>
2062 inline Matrix<Symmetric, Col, Col, AT> JTJ(
const Matrix<General, Row, Col, AT> &A) {
2063 Matrix<Symmetric, Col, Col, AT> S(A.cols(), A.cols(), NONINIT);
2064 for (
int i = 0; i < A.cols(); i++) {
2065 for (
int k = i; k < A.cols(); k++) {
2067 for (
int j = 0; j < A.rows(); j++)
2068 S.ej(i, k) += A.e(j, i) * A.e(j, k);
2074 template <
class Row1,
class Row2,
class Col,
class AT>
2075 inline Matrix<Symmetric, Col, Col, AT> JTMJ(
const Matrix<Symmetric, Row2, Row2, AT> &B,
const Matrix<General, Row1, Col, AT> &A) {
2077 Matrix<Symmetric, Col, Col, AT> S(A.cols(), A.cols(), NONINIT);
2078 Matrix<General, Row1, Col, AT> C = B * A;
2080 for (
int i = 0; i < A.cols(); i++) {
2081 for (
int k = i; k < A.cols(); k++) {
2083 for (
int j = 0; j < A.rows(); j++)
2084 S.ej(i, k) += A.e(j, i) * C.e(j, k);
2090 template <
class Row,
class Col,
class AT>
2091 inline Matrix<Symmetric, Col, Col, AT> JTMJ(
const Matrix<SymmetricSparse, Ref, Ref, AT> &B,
const Matrix<General, Row, Col, AT> &A) {
2093 Matrix<Symmetric, Col, Col, AT> S(A.cols(), A.cols(), NONINIT);
2094 Matrix<General, Row, Col, AT> C = B * A;
2096 for (
int i = 0; i < A.cols(); i++) {
2097 for (
int k = i; k < A.cols(); k++) {
2099 for (
int j = 0; j < A.rows(); j++)
2100 S.ej(i, k) += A.e(j, i) * C.e(j, k);
2106 template <
class Row,
class Col1,
class Col2,
class AT>
2107 inline Matrix<Symmetric, Row, Row, AT> JMJT(
const Matrix<General, Row, Col1, AT> &A,
const Matrix<Symmetric, Col2, Col2, AT> &B) {
2109 Matrix<Symmetric, Row, Row, AT> S(A.rows(), A.rows(), NONINIT);
2110 Matrix<General, Row, Col1, AT> C = A * B;
2112 for (
int i = 0; i < S.size(); i++) {
2113 for (
int k = i; k < S.size(); k++) {
2115 for (
int j = 0; j < A.cols(); j++)
2116 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:1716
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:2053
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:42
int rows() const
Number of rows.
Definition: general_matrix.h:307
void quicksortmedian_intern(Matrix< General, Ref, Ref, AT > &A, int PivotCol, RowVector< Ref, AT > &tmp, int l, int r)
Definition: linear_algebra.h:2003
int minIndex(const Vector< Row, AT > &x)
Index of minimum value.
Definition: linear_algebra.h:1957
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:1304
This is a rowvector class of general shape in dense storage format.
Definition: row_vector.h:36
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:1979
int maxIndex(const Vector< Row, AT > &x)
Index of maximum value.
Definition: linear_algebra.h:1920
int cols() const
Number of columns.
This is a matrix class for general matrices.
Definition: general_matrix.h:42
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:1862
int cols() const
Number of columns.
Definition: general_matrix.h:313
const RowVector< Ref, AT > row(int i) const
Row operator.
Definition: general_matrix.h:525
bool operator!=(const Matrix< Type1, Row1, Col1, AT > &A, const Matrix< Type2, Row2, Col2, AT > &B)
Matrix-matrix comparison.
Definition: linear_algebra.h:1884
double tripleProduct(const Vector< Row, AT > &a, const Vector< Row, AT > &x, const Vector< Row, AT > &y)
Triple product.
Definition: linear_algebra.h:1324
SquareMatrix< Row, AT > tilde(const Vector< Row, AT > &x)
Tilde operator.
Definition: linear_algebra.h:1839
int rows() const
Number of rows.
AT scalarProduct(const Vector< Row, AT > &x, const Vector< Row, AT > &y)
Scalar product.
Definition: linear_algebra.h:1286