22#ifndef linear_algebra_h
23#define linear_algebra_h
24#if defined(_WIN32) && !defined(NOMINMAX)
28#include "square_matrix.h"
30#include "row_vector.h"
31#include "fixed_square_matrix.h"
32#include "fixed_vector.h"
33#include "fixed_row_vector.h"
34#include "fixed_symmetric_matrix.h"
35#include "var_square_matrix.h"
36#include "var_symmetric_matrix.h"
37#include "var_vector.h"
38#include "var_row_vector.h"
39#include "var_fixed_general_matrix.h"
40#include "fixed_var_general_matrix.h"
41#include "diagonal_matrix.h"
42#include "sparse_matrix.h"
43#include "symmetric_sparse_matrix.h"
47 #include <boost/stacktrace.hpp>
53 template<
class T> std::complex<T> operator+(
const std::complex<T> &x,
int y);
54 template<
class T> std::complex<T> operator-(
const std::complex<T> &x,
int y);
55 template<
class T> std::complex<T> operator*(
const std::complex<T> &x,
int y);
56 template<
class T> std::complex<T> operator/(
const std::complex<T> &x,
int y);
57 template<
class T> std::complex<T> operator+(
int x,
const std::complex<T> &y);
58 template<
class T> std::complex<T> operator-(
int x,
const std::complex<T> &y);
59 template<
class T> std::complex<T> operator*(
int x,
const std::complex<T> &y);
60 template<
class T> std::complex<T> operator/(
int x,
const std::complex<T> &y);
65 template <
class Row1,
class Row2,
class Row3,
class AT1,
class AT2,
class AT3>
66 inline void add(
const Vector<Row1, AT1> &a1,
const Vector<Row2, AT2> &a2, Vector<Row3, AT3> &a3) {
67 FMATVEC_ASSERT(a1.size() == a2.size(), AT3);
68 for (
int i = 0; i < a1.size(); i++)
69 a3.e(i) = a1.e(i) + a2.e(i);
72 template <
class Row1,
class Row2,
class AT>
73 inline void add(Vector<Row1, AT> &a1,
const Vector<Row2, AT> &a2) {
74 FMATVEC_ASSERT(a1.size() == a2.size(), AT);
75 for (
int i = 0; i < a1.size(); i++)
79 template <
class Row1,
class Row2,
class Row3,
class AT1,
class AT2>
81 FMATVEC_ASSERT(a1.size() == a2.size(), AT2);
82 for (
int i = 0; i < a1.size(); i++)
83 a3.e(i) = a1.e(i) - a2.e(i);
86 template <
class Row1,
class Row2,
class AT1,
class AT2>
87 inline void sub(Vector<Row1, AT1> &a1,
const Vector<Row2, AT2> &a2) {
88 FMATVEC_ASSERT(a1.size() == a2.size(), AT2);
89 for (
int i = 0; i < a1.size(); i++)
94 template <
class AT1,
class AT2,
class Row1,
class Row2>
95 inline Vector<Var, typename OperatorResult<AT1, AT2>::Type> operator+(
const Vector<Row1, AT1> &a,
const Vector<Row2, AT2> &b) {
96 Vector<Var, typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
100 template <
class AT1,
class AT2,
class Row>
101 inline Vector<Row, typename OperatorResult<AT1, AT2>::Type> operator+(
const Vector<Row, AT1> &a,
const Vector<Row, AT2> &b) {
102 Vector<Row, typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
106 template <
class AT1,
class AT2,
int M,
class Row>
107 inline Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Vector<Fixed<M>, AT1> &a,
const Vector<Row, AT2> &b) {
108 Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
112 template <
class AT1,
class AT2,
int M>
113 inline Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const Vector<Fixed<M>, AT1> &a,
const Vector<Fixed<M>, AT2> &b) {
114 Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
119 template <
class Row1,
class Row2>
120 inline Vector<Row2, double> operator+(Vector<Row1, double> &&a, Vector<Row2, double> &&b) {
124 template <
class Row1,
class Row2>
125 inline Vector<Row1, double> operator+(Vector<Row1, double> &&a,
const Vector<Row2, double> &b) {
129 template <
class Row1,
class Row2>
130 inline Vector<Row2, double> operator+(
const Vector<Row1, double> &a, Vector<Row2, double> &&b) {
134 template <
class AT,
class Row1,
class Row2>
135 inline Vector<Row1, AT> operator+=(Vector<Row1, AT> &a,
const Vector<Row2, AT> &b) {
141 template <
class AT1,
class AT2,
class Row1,
class Row2>
142 inline Vector<Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Vector<Row1, AT1> &a,
const Vector<Row2, AT2> &b) {
143 Vector<Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
147 template <
class AT1,
class AT2,
class Row>
148 inline Vector<Row, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const Vector<Row, AT1> &a,
const Vector<Row, AT2> &b) {
149 Vector<Row, typename fmatvec::OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
153 template <
class AT1,
class AT2,
int M,
class Row2>
159 template <
class AT1,
class AT2,
int M>
166 template <
class Row1,
class Row2,
class AT>
167 inline Vector<Row2, AT> operator-(Vector<Row1, AT> &&a, Vector<Row2, AT> &&b) {
171 template <
class Row1,
class Row2,
class AT>
172 inline Vector<Row1, AT> operator-(Vector<Row1, AT> &&a,
const Vector<Row2, AT> &b) {
176 template <
class Row1,
class Row2,
class AT>
177 inline Vector<Row2, AT> operator-(
const Vector<Row1, AT> &a, Vector<Row2, AT> &&b) {
181 template <
class AT,
class Row1,
class Row2>
182 inline Vector<Row1, AT> operator-=(Vector<Row1, AT> &a,
const Vector<Row2, AT> &b) {
188 template <
class Col1,
class Col2,
class Col3,
class AT>
189 inline void add(
const RowVector<Col1, AT> &a1,
const RowVector<Col2, AT> &a2, RowVector<Col3, AT> &a3) {
190 FMATVEC_ASSERT(a1.size() == a2.size(), AT);
191 for (
int i = 0; i < a1.size(); i++)
192 a3.e(i) = a1.e(i) + a2.e(i);
195 template <
class Col1,
class Col2,
class AT>
196 inline void add(RowVector<Col1, AT> &a1,
const RowVector<Col2, AT> &a2) {
197 FMATVEC_ASSERT(a1.size() == a2.size(), AT);
198 for (
int i = 0; i < a1.size(); i++)
202 template <
class Col1,
class Col2,
class Col3,
class AT1,
class AT2>
204 FMATVEC_ASSERT(a1.size() == a2.size(), AT2);
205 for (
int i = 0; i < a1.size(); i++)
206 a3.e(i) = a1.e(i) - a2.e(i);
209 template <
class Col1,
class Col2,
class AT1,
class AT2>
210 inline void sub(RowVector<Col1, AT1> &a1,
const RowVector<Col2, AT2> &a2) {
211 FMATVEC_ASSERT(a1.size() == a2.size(), AT2);
212 for (
int i = 0; i < a1.size(); i++)
217 template <
class AT1,
class AT2,
class Col1,
class Col2>
218 inline RowVector<Var, typename OperatorResult<AT1, AT2>::Type> operator+(
const RowVector<Col1, AT1> &a,
const RowVector<Col2, AT2> &b) {
219 RowVector<Var, typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
223 template <
class AT1,
class AT2,
class Col>
224 inline RowVector<Col, typename OperatorResult<AT1, AT2>::Type> operator+(
const RowVector<Col, AT1> &a,
const RowVector<Col, AT2> &b) {
225 RowVector<Col, typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
229 template <
class AT1,
class AT2,
int N,
class Col2>
230 inline RowVector<Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const RowVector<Fixed<N>, AT1> &a,
const RowVector<Col2, AT2> &b) {
231 RowVector<Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
235 template <
class AT1,
class AT2,
int N>
236 inline RowVector<Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator+(
const RowVector<Fixed<N>, AT1> &a,
const RowVector<Fixed<N>, AT2> &b) {
237 RowVector<Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
242 template <
class Row1,
class Row2>
243 inline RowVector<Row2, double> operator+(RowVector<Row1, double> &&a, RowVector<Row2, double> &&b) {
247 template <
class Row1,
class Row2>
248 inline RowVector<Row1, double> operator+(RowVector<Row1, double> &&a,
const RowVector<Row2, double> &b) {
252 template <
class Row1,
class Row2>
253 inline RowVector<Row2, double> operator+(
const RowVector<Row1, double> &a, RowVector<Row2, double> &&b) {
257 template <
class AT,
class Col1,
class Col2>
258 inline RowVector<Col1, AT> operator+=(RowVector<Col1, AT> &a,
const RowVector<Col2, AT> &b) {
264 template <
class AT1,
class AT2,
class Col1,
class Col2>
265 inline RowVector<Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const RowVector<Col1, AT1> &a,
const RowVector<Col2, AT2> &b) {
266 RowVector<Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
270 template <
class AT1,
class AT2,
class Col>
271 inline RowVector<Col, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const RowVector<Col, AT1> &a,
const RowVector<Col, AT2> &b) {
272 RowVector<Col, typename fmatvec::OperatorResult<AT1, AT2>::Type> c(a.size(), NONINIT);
276 template <
class AT1,
class AT2,
int N,
class Col2>
282 template <
class AT1,
class AT2,
int N>
289 template <
class Row1,
class Row2,
class AT>
290 inline RowVector<Row2, AT> operator-(RowVector<Row1, AT> &&a, RowVector<Row2, AT> &&b) {
294 template <
class Row1,
class Row2,
class AT>
295 inline RowVector<Row1, AT> operator-(RowVector<Row1, AT> &&a,
const RowVector<Row2, AT> &b) {
299 template <
class Row1,
class Row2,
class AT>
300 inline RowVector<Row2, AT> operator-(
const RowVector<Row1, AT> &a, RowVector<Row2, AT> &&b) {
304 template <
class AT,
class Col1,
class Col2>
305 inline RowVector<Col1, AT> operator-=(RowVector<Col1, AT> &a,
const RowVector<Col2, AT> &b) {
311 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>
312 inline void add(
const Matrix<Type1, Row1, Col1, AT1> &A1,
const Matrix<Type2, Row2, Col2, AT2> &A2, Matrix<Type3, Row3, Col3, AT3> &A3) {
313 FMATVEC_ASSERT(A1.rows() == A2.rows(), AT3);
314 FMATVEC_ASSERT(A1.cols() == A2.cols(), AT3);
315 for (
int i = 0; i < A1.rows(); i++)
316 for (
int j = 0; j < A2.cols(); j++)
317 A3.e(i, j) = A1.e(i, j) + A2.e(i, j);
320 template <
class Row1,
class Row2,
class Row3,
class AT>
321 inline void add(
const Matrix<Symmetric, Row1, Row1, AT> &A1,
const Matrix<Symmetric, Row2, Row2, AT> &A2, Matrix<Symmetric, Row3, Row3, AT> &A3) {
322 FMATVEC_ASSERT(A1.size() == A2.size(), AT);
323 for (
int i = 0; i < A1.size(); i++)
324 for (
int j = i; j < A2.size(); j++)
325 A3.ej(i, j) = A1.ej(i, j) + A2.ej(i, j);
328 template <
class Row1,
class Row2,
class Row3,
class AT>
329 inline void add(
const Matrix<Diagonal, Row1, Row1, AT> &A1,
const Matrix<Diagonal, Row2, Row2, AT> &A2, Matrix<Diagonal, Row3, Row3, AT> &A3) {
330 FMATVEC_ASSERT(A1.size() == A2.size(), AT);
331 for (
int i = 0; i < A3.size(); i++)
332 A3.e(i) = A1.e(i) + A2.e(i);
335 template <
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2,
class AT>
336 inline void add(Matrix<Type1, Row1, Col1, AT> &A1,
const Matrix<Type2, Row2, Col2, AT> &A2) {
337 FMATVEC_ASSERT(A1.rows() == A2.rows(), AT);
338 FMATVEC_ASSERT(A1.cols() == A2.cols(), AT);
339 for (
int i = 0; i < A1.rows(); i++)
340 for (
int j = 0; j < A2.cols(); j++)
341 A1.e(i, j) += A2.e(i, j);
344 template <
class Row1,
class Row2,
class AT>
345 inline void add(Matrix<Symmetric, Row1, Row1, AT> &A1,
const Matrix<Symmetric, Row2, Row2, AT> &A2) {
346 FMATVEC_ASSERT(A1.size() == A2.size(), AT);
347 for (
int i = 0; i < A1.size(); i++)
348 for (
int j = i; j < A2.size(); j++)
349 A1.ej(i, j) += A2.ej(i, j);
352 template <
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2,
class Type3,
class Row3,
class Col3,
class AT1,
class AT2>
353 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) {
354 FMATVEC_ASSERT(A1.rows() == A2.rows(), AT2);
355 FMATVEC_ASSERT(A1.cols() == A2.cols(), AT2);
356 for (
int i = 0; i < A1.rows(); i++)
357 for (
int j = 0; j < A2.cols(); j++)
358 A3.e(i, j) = A1.e(i, j) - A2.e(i, j);
361 template <
class Row1,
class Row2,
class Row3,
class AT1,
class AT2>
362 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) {
363 FMATVEC_ASSERT(A1.size() == A2.size(), AT2);
364 for (
int i = 0; i < A1.size(); i++)
365 for (
int j = i; j < A2.size(); j++)
366 A3.ej(i, j) = A1.ej(i, j) - A2.ej(i, j);
369 template <
class Row1,
class Row2,
class Row3,
class AT1,
class AT2>
370 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) {
371 FMATVEC_ASSERT(A1.size() == A2.size(), AT2);
372 for (
int i = 0; i < A3.size(); i++)
373 A3.e(i) = A1.e(i) - A2.e(i);
376 template <
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2,
class AT1,
class AT2>
377 inline void sub(Matrix<Type1, Row1, Col1, AT1> &A1,
const Matrix<Type2, Row2, Col2, AT2> &A2) {
378 FMATVEC_ASSERT(A1.rows() == A2.rows(), AT2);
379 FMATVEC_ASSERT(A1.cols() == A2.cols(), AT2);
380 for (
int i = 0; i < A1.rows(); i++)
381 for (
int j = 0; j < A2.cols(); j++)
382 A1.e(i, j) -= A2.e(i, j);
385 template <
class Row1,
class Row2,
class AT1,
class AT2>
386 inline void sub(Matrix<Symmetric, Row1, Row1, AT1> &A1,
const Matrix<Symmetric, Row2, Row2, AT2> &A2) {
387 FMATVEC_ASSERT(A1.size() == A2.size(), AT2);
388 for (
int i = 0; i < A1.size(); i++)
389 for (
int j = i; j < A2.size(); j++)
390 A1.ej(i, j) -= A2.ej(i, j);
395 template <
class AT1,
class AT2,
class Type1,
class Type2,
class Row1,
class Col1,
class Row2,
class Col2>
396 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) {
397 Matrix<General, Var, Var, typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
401 template <
class AT1,
class AT2,
class Type1,
class Type2,
class Row,
class Col>
402 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) {
403 Matrix<General, Row, Col, typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
407 template <
class AT1,
class AT2,
int M,
class Type1,
class Type2,
class Row,
class Col>
408 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) {
409 Matrix<General, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
413 template <
class AT1,
class AT2,
int M,
class Type1,
class Type2>
414 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) {
415 Matrix<General, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
419 template <
class AT1,
class AT2,
int N,
class Type1,
class Type2,
class Row,
class Col>
420 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) {
421 Matrix<General, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
425 template <
class AT1,
class AT2,
int N,
class Type1,
class Type2>
426 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) {
427 Matrix<General, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
431 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2,
class Row,
class Col>
432 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) {
433 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
437 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
438 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) {
439 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
443 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
444 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) {
445 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
449 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
450 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) {
451 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
455 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2,
class Row,
class Col>
456 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) {
457 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
461 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
462 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) {
463 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
467 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
468 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) {
469 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
474 template <
class AT1,
class AT2,
class Type,
class Row1,
class Col1,
class Row2,
class Col2>
475 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) {
476 Matrix<Type, Var, Var, typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
480 template <
class AT1,
class AT2,
class Type,
class Row,
class Col>
481 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) {
482 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
486 template <
class AT1,
class AT2,
int M,
class Type,
class Row,
class Col>
487 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) {
488 Matrix<Type, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
492 template <
class AT1,
class AT2,
int M,
class Type>
493 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) {
494 Matrix<Type, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
498 template <
class AT1,
class AT2,
int N,
class Type,
class Row,
class Col>
499 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) {
500 Matrix<Type, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
504 template <
class AT1,
class AT2,
int N,
class Type>
505 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) {
506 Matrix<Type, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
510 template <
class AT1,
class AT2,
int M,
int N,
class Type,
class Row,
class Col>
511 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) {
512 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
516 template <
class AT1,
class AT2,
int M,
int N,
class Type>
517 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) {
518 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
522 template <
class AT1,
class AT2,
int M,
int N,
class Type>
523 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) {
524 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
528 template <
class AT1,
class AT2,
int M,
int N,
class Type>
529 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) {
530 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
534 template <
class AT1,
class AT2,
int M,
int N,
class Type,
class Row,
class Col>
535 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) {
536 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
540 template <
class AT1,
class AT2,
int M,
int N,
class Type>
541 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) {
542 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
546 template <
class AT1,
class AT2,
int M,
int N,
class Type>
547 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) {
548 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
553 template <
class Type1,
class Type2,
class Row1,
class Row2,
class Col1,
class Col2>
554 inline Matrix<Type2, Row2, Col2, double> operator+(Matrix<Type1, Row1, Col1, double> &&a, Matrix<Type2, Row2, Col2, double> &&b) {
558 template <
class Type1,
class Type2,
class Row1,
class Row2,
class Col1,
class Col2>
559 inline Matrix<Type1, Row1, Col1, double> operator+(Matrix<Type1, Row1, Col1, double> &&a,
const Matrix<Type2, Row2, Col2, double> &b) {
563 template <
class Type1,
class Type2,
class Row1,
class Row2,
class Col1,
class Col2>
564 inline Matrix<Type2, Row2, Col2, double> operator+(
const Matrix<Type1, Row1, Col1, double> &a, Matrix<Type2, Row2, Col2, double> &&b) {
568 template <
class AT,
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2>
569 inline Matrix<Type1, Row1, Col1, AT>& operator+=(Matrix<Type1, Row1, Col1, AT> &A,
const Matrix<Type2, Row2, Col2, AT> &B) {
576 template <
class AT1,
class AT2,
class Type1,
class Type2,
class Row1,
class Col1,
class Row2,
class Col2>
577 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) {
578 Matrix<General, Var, Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
582 template <
class AT1,
class AT2,
class Type1,
class Type2,
class Row,
class Col>
583 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) {
584 Matrix<General, Row, Col, typename fmatvec::OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
588 template <
class AT1,
class AT2,
int M,
class Type1,
class Type2,
class Row,
class Col>
589 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) {
594 template <
class AT1,
class AT2,
int M,
class Type1,
class Type2>
595 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) {
600 template <
class AT1,
class AT2,
int N,
class Type1,
class Type2,
class Row,
class Col>
601 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) {
606 template <
class AT1,
class AT2,
int N,
class Type1,
class Type2>
607 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) {
612 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2,
class Row,
class Col>
613 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) {
618 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
619 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) {
624 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
625 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) {
630 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
631 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) {
636 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2,
class Row,
class Col>
637 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) {
642 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
643 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) {
648 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2>
649 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) {
655 template <
class AT1,
class AT2,
class Type,
class Row1,
class Col1,
class Row2,
class Col2>
656 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) {
657 Matrix<Type, Var, Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
661 template <
class AT1,
class AT2,
class Type,
class Row,
class Col>
662 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) {
663 Matrix<Type, Row, Col, typename fmatvec::OperatorResult<AT1, AT2>::Type> C(A.rows(), A.cols(), NONINIT);
667 template <
class AT1,
class AT2,
int M,
class Type,
class Row,
class Col>
668 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) {
673 template <
class AT1,
class AT2,
int M,
class Type>
674 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) {
679 template <
class AT1,
class AT2,
int N,
class Type,
class Row,
class Col>
680 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) {
685 template <
class AT1,
class AT2,
int N,
class Type>
686 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) {
691 template <
class AT1,
class AT2,
int M,
int N,
class Type,
class Row,
class Col>
692 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) {
697 template <
class AT1,
class AT2,
int M,
int N,
class Type>
698 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) {
703 template <
class AT1,
class AT2,
int M,
int N,
class Type>
704 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) {
709 template <
class AT1,
class AT2,
int M,
int N,
class Type>
710 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) {
715 template <
class AT1,
class AT2,
int M,
int N,
class Type,
class Row,
class Col>
716 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) {
721 template <
class AT1,
class AT2,
int M,
int N,
class Type>
722 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) {
727 template <
class AT1,
class AT2,
int M,
int N,
class Type>
728 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) {
734 template <
class Type1,
class Type2,
class Row1,
class Row2,
class Col1,
class Col2,
class AT>
735 inline Matrix<Type2, Row2, Col2, AT> operator-(Matrix<Type1, Row1, Col1, AT> &&a, Matrix<Type2, Row2, Col2, AT> &&b) {
739 template <
class Type1,
class Type2,
class Row1,
class Row2,
class Col1,
class Col2,
class AT>
740 inline Matrix<Type1, Row1, Col1, AT> operator-(Matrix<Type1, Row1, Col1, AT> &&a,
const Matrix<Type2, Row2, Col2, AT> &b) {
744 template <
class Type1,
class Type2,
class Row1,
class Row2,
class Col1,
class Col2,
class AT>
745 inline Matrix<Type2, Row2, Col2, AT> operator-(
const Matrix<Type1, Row1, Col1, AT> &a, Matrix<Type2, Row2, Col2, AT> &&b) {
749 template <
class AT,
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2>
750 inline Matrix<Type1, Row1, Col1, AT>& operator-=(Matrix<Type1, Row1, Col1, AT> &A,
const Matrix<Type2, Row2, Col2, AT> &B) {
756 template <
class AT1,
class AT2,
class Row1,
class Row2>
757 inline SquareMatrix<Var, typename OperatorResult<AT1, AT2>::Type> operator+(
const SquareMatrix<Row1, AT1> &A1,
const SquareMatrix<Row2, AT2> &A2) {
758 SquareMatrix<Var, typename OperatorResult<AT1, AT2>::Type> A3(A1.size(), NONINIT);
762 template <
class AT1,
class AT2,
class Row>
763 inline SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> operator+(
const SquareMatrix<Row, AT1> &A1,
const SquareMatrix<Row, AT2> &A2) {
764 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> A3(A1.size(), NONINIT);
769 template <
class Row1,
class Row2>
770 inline SquareMatrix<Row1, double> operator+(SquareMatrix<Row1, double> &&A1, SquareMatrix<Row2, double> &&A2) {
772 return std::move(A1);;
774 template <
class Row1,
class Row2>
775 inline SquareMatrix<Row1, double> operator+(SquareMatrix<Row1, double> &&A1,
const SquareMatrix<Row2, double> &A2) {
777 return std::move(A1);;
779 template <
class Row1,
class Row2>
780 inline SquareMatrix<Row2, double> operator+(
const SquareMatrix<Row1, double> &A1, SquareMatrix<Row2, double> &&A2) {
782 return std::move(A2);
786 template <
class AT1,
class AT2,
class Row1,
class Row2>
787 inline SquareMatrix<Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const SquareMatrix<Row1, AT1> &A1,
const SquareMatrix<Row2, AT2> &A2) {
788 SquareMatrix<Var, typename fmatvec::OperatorResult<AT1, AT2>::Type> A3(A1.size(), NONINIT);
792 template <
class AT1,
class AT2,
class Row>
793 inline SquareMatrix<Row, typename fmatvec::OperatorResult<AT1, AT2>::Type> operator-(
const SquareMatrix<Row, AT1> &A1,
const SquareMatrix<Row, AT2> &A2) {
794 SquareMatrix<Row, typename fmatvec::OperatorResult<AT1, AT2>::Type> A3(A1.size(), NONINIT);
799 template <
class Row1,
class Row2,
class AT>
800 inline SquareMatrix<Row1, AT> operator-(SquareMatrix<Row1, AT> &&A1, SquareMatrix<Row2, AT> &&A2) {
802 return std::move(A1);;
804 template <
class Row1,
class Row2,
class AT>
805 inline SquareMatrix<Row1, AT> operator-(SquareMatrix<Row1, AT> &&A1,
const SquareMatrix<Row2, AT> &A2) {
807 return std::move(A1);;
809 template <
class Row1,
class Row2,
class AT>
810 inline SquareMatrix<Row2, AT> operator-(
const SquareMatrix<Row1, AT> &A1, SquareMatrix<Row2, AT> &&A2) {
812 return std::move(A2);
820 template <
class Type1,
class Row1,
class Col1,
class Row2,
class Row3,
class AT1,
class AT2>
822 FMATVEC_ASSERT(A.cols() == x.size(), AT2);
823 for (
int i = 0; i < y.size(); i++) {
825 for (
int j = 0; j < x.size(); j++)
826 y.e(i) += A.e(i, j) * x.e(j);
830 template <
class Row1,
class Row2,
class Row3,
class AT1,
class AT2>
832 FMATVEC_ASSERT(A.cols() == x.size(), AT2);
833 for (
int i = 0; i < y.size(); i++) {
835 for (
int j = 0; j < i; j++)
836 y.e(i) += A.ei(i, j) * x.e(j);
837 for (
int j = i; j < x.size(); j++)
838 y.e(i) += A.ej(i, j) * x.e(j);
842 template <
class Row2,
class Row3,
class AT1,
class AT2>
844 FMATVEC_ASSERT(A.cols() == x.size(), AT2);
845 for (
int i = 0; i < y.size(); i++) {
847 for (
int j = A.Ip()[i]; j < A.Ip()[i+1]; j++)
848 y.e(i) += A()[j]*x.e(A.Jp()[j]);
852 template <
class Row2,
class Row3,
class AT1,
class AT2>
854 FMATVEC_ASSERT(A.cols() == x.size(), AT2);
855 for (
int i = 0; i < y.size(); i++)
856 y.e(i) = A()[A.Ip()[i]]*x.e(A.Jp()[A.Ip()[i]]);
857 for (
int i = 0; i < y.size(); i++) {
858 for (
int j = A.Ip()[i]+1; j < A.Ip()[i+1]; j++) {
859 y.e(i) += A()[j]*x.e(A.Jp()[j]);
860 y.e(A.Jp()[j]) += A()[j]*x.e(i);
866 template <
class AT1,
class AT2,
class Type1,
class Row1,
class Col1,
class Row2>
867 inline Vector<Var, typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type1, Row1, Col1, AT1> &A,
const Vector<Row2, AT2> &x) {
868 Vector<Var, typename OperatorResult<AT1, AT2>::Type> y(A.rows(), NONINIT);
872 template <
class AT1,
class AT2,
class Type1,
class Row,
class Col>
873 inline Vector<Row, typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type1, Row, Col, AT1> &A,
const Vector<Row, AT2> &x) {
874 Vector<Row, typename OperatorResult<AT1, AT2>::Type> y(A.rows(), NONINIT);
878 template <
class AT1,
class AT2,
int M,
class Type1,
class Col1,
class Row2>
879 inline Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type1, Fixed<M>, Col1, AT1> &A,
const Vector<Row2, AT2> &x) {
880 Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> y(A.rows(), NONINIT);
884 template <
class AT1,
class AT2,
int M,
class Type1>
885 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) {
886 Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> y(A.rows(), NONINIT);
890 template <
class AT1,
class AT2,
int M,
int N,
class Type,
class Row2>
891 inline Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Type, Fixed<M>, Fixed<N>, AT1> &A,
const Vector<Row2, AT2> &x) {
892 Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> y(A.rows(), NONINIT);
896 template <
class AT1,
class AT2,
int M,
int N,
class Type>
897 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) {
898 Vector<Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> y(A.rows(), NONINIT);
904 template <
class Col1,
class Type2,
class Row2,
class Col2,
class Type3,
class Col3,
class AT1,
class AT2>
906 FMATVEC_ASSERT(x.size() == A.rows(), AT2);
907 for (
int i = 0; i < y.size(); i++) {
909 for (
int j = 0; j < x.size(); j++)
910 y.e(i) += x.e(j) * A.e(j, i);
914 template <
class Col1,
class Row2,
class Col3,
class AT1,
class AT2>
916 FMATVEC_ASSERT(x.size() == A.rows(), AT2);
917 for (
int i = 0; i < y.size(); i++) {
919 for (
int j = 0; j < i; j++)
920 y.e(i) += x.e(j) * A.ej(j, i);
921 for (
int j = i; j < x.size(); j++)
922 y.e(i) += x.e(j) * A.ei(j, i);
926 template <
class AT1,
class AT2,
class Type2,
class Col2,
class Row1,
class Col1>
927 inline RowVector<Var, typename OperatorResult<AT1, AT2>::Type> operator*(
const RowVector<Col2, AT1> &x,
const Matrix<Type2, Row1, Col1, AT2> &A) {
928 RowVector<Var, typename OperatorResult<AT1, AT2>::Type> y(A.cols(), NONINIT);
932 template <
class AT1,
class AT2,
class Type2,
class Row,
class Col>
933 inline RowVector<Col, typename OperatorResult<AT1, AT2>::Type> operator*(
const RowVector<Col, AT1> &x,
const Matrix<Type2, Row, Col, AT2> &A) {
934 RowVector<Col, typename OperatorResult<AT1, AT2>::Type> y(A.cols(), NONINIT);
938 template <
class AT1,
class AT2,
int N,
class Type2,
class Col1,
class Row2>
939 inline RowVector<Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> operator*(
const RowVector<Col1, AT1> &x,
const Matrix<Type2, Row2, Fixed<N>, AT2> &A) {
940 RowVector<Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> y(A.cols(), NONINIT);
944 template <
class AT1,
class AT2,
int N,
class Type2>
945 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) {
946 RowVector<Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> y(A.cols(), NONINIT);
952 template <
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2,
class Type3,
class Row3,
class Col3,
class AT1,
class AT2>
953 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) {
954 FMATVEC_ASSERT(A1.cols() == A2.rows(), AT2);
955 for (
int i = 0; i < A3.rows(); i++) {
956 for (
int k = 0; k < A3.cols(); k++) {
958 for (
int j = 0; j < A1.cols(); j++)
959 A3.e(i, k) += A1.e(i, j) * A2.e(j, k);
963 template <
class Row1,
class Type2,
class Row2,
class Col2,
class Type3,
class Row3,
class Col3,
class AT1,
class AT2>
964 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) {
965 FMATVEC_ASSERT(A1.size() == A2.rows(), AT2);
966 for (
int i = 0; i < A3.rows(); i++) {
967 for (
int k = 0; k < A3.cols(); k++) {
969 for (
int j = 0; j < i; j++)
970 A3.e(i, k) += A1.ei(i, j) * A2.e(j, k);
971 for (
int j = i; j < A1.cols(); j++)
972 A3.e(i, k) += A1.ej(i, j) * A2.e(j, k);
976 template <
class Row1,
class Row2,
class Row3,
class AT1,
class AT2>
977 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) {
978 FMATVEC_ASSERT(A1.size() == A2.size(), AT2);
979 for (
int i = 0; i < A3.size(); i++)
980 A3.e(i) = A1.e(i) * A2.e(i);
983 template <
class Type2,
class Row2,
class Col2,
class Type3,
class Row3,
class Col3,
class AT1,
class AT2>
984 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) {
985 FMATVEC_ASSERT(A1.cols() == A2.rows(), AT2);
986 for (
int i = 0; i < A3.rows(); i++) {
987 for (
int k = 0; k < A3.cols(); k++) {
989 for (
int j = A1.Ip()[i]; j < A1.Ip()[i+1]; j++)
990 A3.e(i, k) += A1()[j]*A2.e(A1.Jp()[j], k);
995 template <
class Type2,
class Row2,
class Col2,
class Type3,
class Row3,
class Col3,
class AT1,
class AT2>
996 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) {
997 FMATVEC_ASSERT(A1.size() == A2.rows(), AT2);
998 for (
int i = 0; i < A3.rows(); i++) {
999 for (
int k = 0; k < A3.cols(); k++)
1000 A3.e(i, k) = A1()[A1.Ip()[i]]*A2.e(A1.Jp()[A1.Ip()[i]], k);
1002 for (
int i = 0; i < A3.rows(); i++) {
1003 for (
int k = 0; k < A3.cols(); k++) {
1004 for (
int j = A1.Ip()[i]+1; j < A1.Ip()[i+1]; j++) {
1005 A3.e(i, k) += A1()[j]*A2.e(A1.Jp()[j], k);
1006 A3.e(A1.Jp()[j], k) += A1()[j]*A2.e(i, k);
1012 template <
class AT1,
class AT2,
class Type1,
class Type2,
class Row1,
class Col1,
class Row2,
class Col2>
1013 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) {
1014 Matrix<General, Var, Var, typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1018 template <
class AT1,
class AT2,
class Type1,
class Type2,
class Row,
class Col>
1019 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) {
1020 Matrix<General, Row, Col, typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1024 template <
class AT1,
class AT2,
int M,
class Type1,
class Type2,
class Col1,
class Row2,
class Col2>
1025 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) {
1026 Matrix<General, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1030 template <
class AT1,
class AT2,
int N,
class Type1,
class Row1,
class Col1,
class Type2,
class Row2>
1031 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) {
1032 Matrix<General, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1036 template <
class AT1,
class AT2,
int M,
int N,
class Type1,
class Type2,
class Col1,
class Row2>
1037 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) {
1038 Matrix<General, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1042 template <
class AT1,
class AT2,
int M,
class Type1,
class Type2>
1043 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) {
1044 Matrix<General, Fixed<M>, Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1048 template <
class AT1,
class AT2,
class Type,
class Row1,
class Col1,
class Row2,
class Col2>
1049 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) {
1050 Matrix<Type, Var, Var, typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1054 template <
class AT1,
class AT2,
class Type,
class Row,
class Col>
1055 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) {
1056 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1060 template <
class AT1,
class AT2,
int M,
class Type,
class Col1,
class Row2,
class Col2>
1061 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) {
1062 Matrix<Type, Fixed<M>, Var,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1066 template <
class AT1,
class AT2,
int N,
class Type,
class Row1,
class Col1,
class Row2>
1067 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) {
1068 Matrix<Type, Var, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1072 template <
class AT1,
class AT2,
int M,
int N,
class Type,
class Col1,
class Row2>
1073 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) {
1074 Matrix<Type, Fixed<M>, Fixed<N>,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1078 template <
class AT1,
class AT2,
int M,
class Type>
1079 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) {
1080 Matrix<Type, Fixed<M>, Fixed<M>,
typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1086 template <
class AT1,
class AT2,
class Row1,
class Row2>
1087 inline SquareMatrix<Var, typename OperatorResult<AT1, AT2>::Type> operator*(
const SquareMatrix<Row1, AT1> &A1,
const SquareMatrix<Row2, AT2> &A2) {
1088 SquareMatrix<Var, typename OperatorResult<AT1, AT2>::Type> A3(A1.size(), NONINIT);
1092 template <
class AT1,
class AT2,
class Row>
1093 inline SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> operator*(
const SquareMatrix<Row, AT1> &A1,
const SquareMatrix<Row, AT2> &A2) {
1094 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> A3(A1.size(), NONINIT);
1100 template <
class AT1,
class AT2,
class Row1,
class Row2>
1101 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) {
1102 Matrix<General, Var, Var, typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1106 template <
class AT1,
class AT2,
class Row>
1107 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) {
1108 Matrix<General, Row, Row, typename OperatorResult<AT1, AT2>::Type> A3(A1.rows(), A2.cols(), NONINIT);
1121 template <
class Row,
class AT1,
class AT2>
1126 for (
int i = 0; i < x.size(); i++)
1127 y.e(i) = x.e(i) * alpha;
1132 template <
class Row>
1133 Vector<Row, double> operator*(Vector<Row, double> &&x,
const double& alpha) {
1134 for (
int i = 0; i < x.size(); i++)
1136 return std::move(x);
1143 template <
class Row,
class AT1,
class AT2>
1148 for (
int i = 0; i < x.size(); i++)
1149 y.e(i) = x.e(i) * alpha;
1154 template <
class Row>
1155 Vector<Row, double> operator*(
const double& alpha, Vector<Row, double> &&x) {
1156 for (
int i = 0; i < x.size(); i++)
1158 return std::move(x);
1161 template <
class Row,
class AT1,
class AT2>
1162 inline Vector<Row, AT1> operator*=(Vector<Row, AT1> &x,
const AT2 &alpha) {
1163 for (
int i = 0; i < x.size(); i++)
1168 template <
class Row,
class AT1,
class AT2>
1169 inline Vector<Row, typename OperatorResult<AT1, AT2>::Type> operator/(
const Vector<Row, AT1> &x,
const AT2 &alpha) {
1170 Vector<Row, typename OperatorResult<AT1, AT2>::Type> y(x.size(), NONINIT);
1171 for (
int i = 0; i < x.size(); i++)
1172 y.e(i) = x.e(i) / alpha;
1176 template <
class Row>
1177 inline Vector<Row, double> operator/(Vector<Row, double> &&x,
const double &alpha) {
1178 for (
int i = 0; i < x.size(); i++)
1180 return std::move(x);
1183 template <
class Row,
class AT1,
class AT2>
1184 inline Vector<Row, AT1> operator/=(Vector<Row, AT1> &x,
const AT2 &alpha) {
1185 for (
int i = 0; i < x.size(); i++)
1195 template <
class Col,
class AT1,
class AT2>
1200 for (
int i = 0; i < x.size(); i++)
1201 y.e(i) = x.e(i) * alpha;
1206 template <
class Col>
1207 RowVector<Col, double> operator*(RowVector<Col, double> &&x,
const double& alpha) {
1208 for (
int i = 0; i < x.size(); i++)
1210 return std::move(x);
1217 template <
class Col,
class AT1,
class AT2>
1222 for (
int i = 0; i < x.size(); i++)
1223 y.e(i) = x.e(i) * alpha;
1228 template <
class Col>
1229 RowVector<Col, double> operator*(
const double &alpha, RowVector<Col, double> &&x) {
1230 for (
int i = 0; i < x.size(); i++)
1232 return std::move(x);
1235 template <
class Col,
class AT1,
class AT2>
1236 inline RowVector<Col, AT1> operator*=(RowVector<Col, AT1> &x,
const AT2 &alpha) {
1237 for (
int i = 0; i < x.size(); i++)
1242 template <
class Col,
class AT1,
class AT2>
1243 inline RowVector<Col, typename OperatorResult<AT1, AT2>::Type> operator/(
const RowVector<Col, AT1> &x,
const AT2 &a) {
1244 RowVector<Col, typename OperatorResult<AT1, AT2>::Type> y(x.size(), NONINIT);
1245 for (
int i = 0; i < x.size(); i++)
1246 y.e(i) = x.e(i) / a;
1250 template <
class Col>
1251 inline RowVector<Col, double> operator/(RowVector<Col, double> &&x,
const double &a) {
1252 for (
int i = 0; i < x.size(); i++)
1254 return std::move(x);
1257 template <
class Col,
class AT1,
class AT2>
1258 inline RowVector<Col, AT1> operator/=(RowVector<Col, AT1> &x,
const AT2 &a) {
1259 for (
int i = 0; i < x.size(); i++)
1274 template <
class Col,
class Row,
class AT1,
class AT2>
1277 FMATVEC_ASSERT(x.size() == y.size(), AT2);
1281 for (
int i = 0; i < x.size(); i++)
1282 res += x.e(i) * y.e(i);
1292 template <
class Row,
class AT>
1295 FMATVEC_ASSERT(x.size() == y.size(), AT);
1299 for (
int i = 0; i < x.size(); i++)
1300 res += x.e(i) * y.e(i);
1310 template <
class Row1,
class Row2,
class AT1,
class AT2>
1313 FMATVEC_ASSERT(x.size() == 3, AT2);
1314 FMATVEC_ASSERT(y.size() == 3, AT2);
1318 z.e(0) = x.e(1) * y.e(2) - x.e(2) * y.e(1);
1319 z.e(1) = x.e(2) * y.e(0) - x.e(0) * y.e(2);
1320 z.e(2) = x.e(0) * y.e(1) - x.e(1) * y.e(0);
1330 template <
class Row,
class AT>
1333 FMATVEC_ASSERT(a.size() == 3, AT);
1334 FMATVEC_ASSERT(x.size() == 3, AT);
1335 FMATVEC_ASSERT(y.size() == 3, AT);
1337 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));
1352 template <
class Type,
class Row,
class Col,
class AT1,
class AT2>
1357 for (
int i = 0; i < A.
rows(); i++)
1358 for (
int j = 0; j < A.
cols(); j++)
1359 B.e(i, j) = A.e(i, j) * alpha;
1364 template <
class Type,
class Row,
class Col>
1365 Matrix<Type, Row, Col, double> operator*(Matrix<Type, Row, Col, double> &&A,
const double &alpha) {
1366 for (
int i = 0; i < A.rows(); i++)
1367 for (
int j = 0; j < A.cols(); j++)
1369 return std::move(A);
1372 template <
class Type,
class Row,
class Col,
class AT1,
class AT2>
1373 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> operator*(
const AT1 &alpha,
const Matrix<Type, Row, Col, AT2> &A) {
1375 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> B(A.rows(), A.cols(), NONINIT);
1377 for (
int i = 0; i < A.rows(); i++)
1378 for (
int j = 0; j < A.cols(); j++)
1379 B.e(i, j) = A.e(i, j) * alpha;
1384 template <
class Type,
class Row,
class Col>
1385 Matrix<Type, Row, Col, double> operator*(
const double &alpha, Matrix<Type, Row, Col, double> &&A) {
1386 for (
int i = 0; i < A.rows(); i++)
1387 for (
int j = 0; j < A.cols(); j++)
1389 return std::move(A);
1392 template <
class Row,
class AT1,
class AT2>
1393 inline Matrix<Symmetric, Row, Row, typename OperatorResult<AT1, AT2>::Type> operator*(
const AT1 &alpha,
const Matrix<Symmetric, Row, Row, AT2> &A) {
1394 Matrix<Symmetric, Row, Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), A.size(), NONINIT);
1395 for (
int i = 0; i < A.size(); i++)
1396 for (
int j = i; j < A.size(); j++)
1397 B.ej(i, j) = A.ej(i, j) * alpha;
1401 template <
class Row>
1402 inline Matrix<Symmetric, Row, Row, double> operator*(
const double &alpha, Matrix<Symmetric, Row, Row, double> &&A) {
1403 for (
int i = 0; i < A.size(); i++)
1404 for (
int j = i; j < A.size(); j++)
1405 A.ej(i, j) *= alpha;
1406 return std::move(A);
1409 template <
class Row,
class AT1,
class AT2>
1410 inline Matrix<Symmetric, Row, Row, typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Symmetric, Row, Row, AT1> &A,
const AT2 &alpha) {
1411 Matrix<Symmetric, Row, Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), A.size(), NONINIT);
1412 for (
int i = 0; i < A.size(); i++)
1413 for (
int j = i; j < A.size(); j++)
1414 B.ej(i, j) = A.ej(i, j) * alpha;
1418 template <
class Row>
1419 inline Matrix<Symmetric, Row, Row, double> operator*(Matrix<Symmetric, Row, Row, double> &&A,
const double &alpha) {
1420 for (
int i = 0; i < A.size(); i++)
1421 for (
int j = i; j < A.size(); j++)
1422 A.ej(i, j) *= alpha;
1423 return std::move(A);
1426 template <
class AT1,
class AT2>
1427 inline Matrix<Diagonal, Ref, Ref, typename OperatorResult<AT1, AT2>::Type> operator*(
const AT1 &alpha,
const Matrix<Diagonal, Ref, Ref, AT2> &A) {
1428 Matrix<Diagonal, Ref, Ref, typename OperatorResult<AT1, AT2>::Type> B(A.rows(), A.cols(), NONINIT);
1429 for (
int i = 0; i < A.rows(); i++)
1430 B.e(i) = A.e(i) * alpha;
1434 inline Matrix<Diagonal, Ref, Ref, double> operator*(
const double &alpha, Matrix<Diagonal, Ref, Ref, double> &&A) {
1435 for (
int i = 0; i < A.rows(); i++)
1440 template <
class AT1,
class AT2>
1441 inline Matrix<Diagonal, Ref, Ref, typename OperatorResult<AT1, AT2>::Type> operator*(
const Matrix<Diagonal, Ref, Ref, AT1> &A,
const AT2 &alpha) {
1442 Matrix<Diagonal, Ref, Ref, typename OperatorResult<AT1, AT2>::Type> B(A.rows(), A.cols(), NONINIT);
1443 for (
int i = 0; i < A.size(); i++)
1444 B.e(i) = A.e(i) * alpha;
1448 inline Matrix<Diagonal, Ref, Ref, double> operator*(Matrix<Diagonal, Ref, Ref, double> &&A,
const double &alpha) {
1449 for (
int i = 0; i < A.size(); i++)
1454 template <
class Type,
class Row,
class Col,
class AT1,
class AT2>
1455 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> operator/(
const Matrix<Type, Row, Col, AT1> &A,
const AT2 &alpha) {
1457 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> B(A.rows(), A.cols(), NONINIT);
1459 for (
int i = 0; i < A.rows(); i++)
1460 for (
int j = 0; j < A.cols(); j++)
1461 B.e(i, j) = A.e(i, j) / alpha;
1466 template <
class Type,
class Row,
class Col>
1467 Matrix<Type, Row, Col, double> operator/(Matrix<Type, Row, Col, double> &&A,
const double &alpha) {
1468 for (
int i = 0; i < A.rows(); i++)
1469 for (
int j = 0; j < A.cols(); j++)
1471 return std::move(A);
1474 template <
class Row,
class AT1,
class AT2>
1475 inline Matrix<Symmetric, Row, Row, typename OperatorResult<AT1, AT2>::Type> operator/(
const Matrix<Symmetric, Row, Row, AT1> &A,
const AT2 &alpha) {
1476 Matrix<Symmetric, Row, Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), A.size(), NONINIT);
1477 for (
int i = 0; i < A.size(); i++)
1478 for (
int j = i; j < A.size(); j++)
1479 B.ej(i, j) = A.ej(i, j) / alpha;
1483 template <
class Row>
1484 inline Matrix<Symmetric, Row, Row, double> operator/(Matrix<Symmetric, Row, Row, double> &&A,
const double &alpha) {
1485 for (
int i = 0; i < A.size(); i++)
1486 for (
int j = i; j < A.size(); j++)
1487 A.ej(i, j) /= alpha;
1488 return std::move(A);
1491 template <
class Row,
class AT1,
class AT2>
1492 inline Matrix<Diagonal, Row, Row, typename OperatorResult<AT1, AT2>::Type> operator/(
const Matrix<Diagonal, Row, Row, AT1> &A,
const AT2 &alpha) {
1493 Matrix<Diagonal, Row, Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), A.size(), NONINIT);
1494 for (
int i = 0; i < A.size(); i++)
1495 B.e(i) = A.e(i) / alpha;
1499 template <
class Row>
1500 inline Matrix<Diagonal, Row, Row, double> operator/(Matrix<Diagonal, Row, Row, double> &&A,
const double &alpha) {
1501 for (
int i = 0; i < A.size(); i++)
1503 return std::move(A);
1506 template <
class Row,
class AT1,
class AT2>
1507 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> operator*(
const SquareMatrix<Row, AT1> &A,
const AT2 &alpha) {
1509 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), NONINIT);
1511 for (
int i = 0; i < A.size(); i++)
1512 for (
int j = 0; j < A.size(); j++)
1513 B.e(i, j) = A.e(i, j) * alpha;
1518 template <
class Row>
1519 SquareMatrix<Row, double> operator*(SquareMatrix<Row, double> &&A,
const double &alpha) {
1520 for (
int i = 0; i < A.size(); i++)
1521 for (
int j = 0; j < A.size(); j++)
1523 return std::move(A);
1526 template <
class Row,
class AT1,
class AT2>
1527 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> operator*(
const AT1 &alpha,
const SquareMatrix<Row, AT2> &A) {
1529 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), NONINIT);
1531 for (
int i = 0; i < A.size(); i++)
1532 for (
int j = 0; j < A.size(); j++)
1533 B.e(i, j) = A.e(i, j) * alpha;
1538 template <
class Row>
1539 SquareMatrix<Row, double> operator*(
const double &alpha, SquareMatrix<Row, double> &&A) {
1540 for (
int i = 0; i < A.size(); i++)
1541 for (
int j = 0; j < A.size(); j++)
1543 return std::move(A);
1546 template <
class Row,
class AT1,
class AT2>
1547 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> operator/(
const SquareMatrix<Row, AT1> &A,
const AT2 &alpha) {
1549 SquareMatrix<Row, typename OperatorResult<AT1, AT2>::Type> B(A.size(), NONINIT);
1551 for (
int i = 0; i < A.size(); i++)
1552 for (
int j = 0; j < A.size(); j++)
1553 B.e(i, j) = A.e(i, j) / alpha;
1558 template <
class Row>
1559 SquareMatrix<Row, double> operator/(SquareMatrix<Row, double> &&A,
const double &alpha) {
1560 for (
int i = 0; i < A.size(); i++)
1561 for (
int j = 0; j < A.size(); j++)
1563 return std::move(A);
1566 template <
class Type,
class Row,
class Col,
class AT1,
class AT2>
1567 Matrix<Type, Row, Col, typename OperatorResult<AT1, AT2>::Type> operator*=(Matrix<Type, Row, Col, AT1> &A,
const AT2 &alpha) {
1568 for (
int i = 0; i < A.rows(); i++)
1569 for (
int j = 0; j < A.cols(); j++)
1575 template <
class Row,
class AT1,
class AT2>
1576 inline Matrix<Symmetric, Row, Row, AT1> operator*=(Matrix<Symmetric, Row, Row, AT1> &A,
const AT2 &alpha) {
1577 for (
int i = 0; i < A.size(); i++)
1578 for (
int j = i; j < A.size(); j++)
1579 A.ej(i, j) *= alpha;
1583 template <
class Row,
class AT1,
class AT2>
1584 inline Matrix<Diagonal, Row, Row, AT1> operator*=(Matrix<Diagonal, Row, Row, AT1> &A,
const AT2 &alpha) {
1585 for (
int i = 0; i < A.size(); i++)
1590 template <
class Type,
class Row,
class Col,
class AT1,
class AT2>
1591 Matrix<Type, Row, Col, AT1> operator/=(Matrix<Type, Row, Col, AT1> &A,
const AT2 &alpha) {
1592 for (
int i = 0; i < A.rows(); i++)
1593 for (
int j = 0; j < A.cols(); j++)
1599 template <
class Row,
class AT1,
class AT2>
1600 inline Matrix<Symmetric, Row, Row, AT1> operator/=(Matrix<Symmetric, Row, Row, AT1> &A,
const AT2 &alpha) {
1601 for (
int i = 0; i < A.size(); i++)
1602 for (
int j = i; j < A.size(); j++)
1603 A.ej(i, j) /= alpha;
1607 template <
class Row,
class AT1,
class AT2>
1608 inline Matrix<Diagonal, Row, Row, AT1> operator/=(Matrix<Diagonal, Row, Row, AT1> &A,
const AT2 &alpha) {
1609 for (
int i = 0; i < A.size(); i++)
1623 template <
class Row,
class AT>
1628 for (
int i = 0; i < x.size(); i++)
1634 template <
class Row,
class AT>
1635 Vector<Row, AT> operator-(Vector<Row, AT> &&x) {
1636 for (
int i = 0; i < x.size(); i++)
1638 return std::move(x);
1646 template <
class Col,
class AT>
1651 for (
int i = 0; i < a.size(); i++)
1657 template <
class Col,
class AT>
1658 RowVector<Col, AT> operator-(RowVector<Col, AT> &&a) {
1659 for (
int i = 0; i < a.size(); i++)
1661 return std::move(a);
1669 template <
class Row,
class AT>
1674 for (
int i = 0; i < A.size(); i++)
1675 for (
int j = 0; j < A.size(); j++)
1676 B.e(i, j) = -A.e(i, j);
1681 template <
class Row,
class AT>
1682 SquareMatrix<Row, AT> operator-(SquareMatrix<Row, AT> &&A) {
1683 for (
int i = 0; i < A.size(); i++)
1684 for (
int j = 0; j < A.size(); j++)
1685 A.e(i, j) = -A.e(i, j);
1686 return std::move(A);
1694 template <
class Type,
class Row,
class Col,
class AT>
1699 for (
int i = 0; i < A.
rows(); i++)
1700 for (
int j = 0; j < A.
cols(); j++)
1701 B.e(i, j) = -A.e(i, j);
1706 template <
class Type,
class Row,
class Col,
class AT>
1707 Matrix<Type, Row, Col, AT> operator-(Matrix<Type, Row, Col, AT> &&A) {
1708 for (
int i = 0; i < A.rows(); i++)
1709 for (
int j = 0; j < A.cols(); j++)
1710 A.e(i, j) = -A.e(i, j);
1711 return std::move(A);
1722 template <
class Row,
class AT>
1725 inline RowVector<Var,double>
trans(Vector<Var,double> &&x) {
return std::move(x).T(); }
1734 template <
class Col,
class AT>
1737 inline Vector<Var,double>
trans(RowVector<Var,double> &&x) {
return std::move(x).T(); }
1747 template <
class Type,
class Row,
class Col,
class AT>
1758 template <
class Row,
class AT>
1798 template <
class Row,
class AT>
1799 inline AT nrmInf(
const Vector<Row, AT> &x) {
1801 for (
int i = 0; i < x.size(); i++)
1802 if (c < fabs(x.e(i)))
1807 template <
class Row,
class AT>
1808 inline AT nrmInf(
const RowVector<Row, AT> &x) {
1810 for (
int i = 0; i < x.size(); i++)
1811 if (c < fabs(x.e(i)))
1816 template <
class Row,
class AT>
1817 inline typename OperatorResult<AT, AT>::Type nrm2(
const Vector<Row, AT> &x) {
1818 typename OperatorResult<AT, AT>::Type c=
typename OperatorResult<AT, AT>::Type();
1819 for (
int i = 0; i < x.size(); i++)
1820 c += pow(x.e(i), 2);
1824 template <
class Col,
class AT>
1825 inline typename OperatorResult<AT, AT>::Type nrm2(
const RowVector<Col, AT> &x) {
1826 typename OperatorResult<AT, AT>::Type c=
typename OperatorResult<AT, AT>::Type();
1827 for (
int i = 0; i < x.size(); i++)
1828 c += pow(x.e(i), 2);
1845 template <
class Row,
class AT>
1847 assert(x.size()==3);
1854 B.e(0, 1) = -x.e(2);
1857 B.e(1, 2) = -x.e(0);
1858 B.e(2, 0) = -x.e(1);
1864 FMATVEC_EXPORT
extern double tildeEPS;
1880 template <
class Row,
class AT>
1882 FMATVEC_ASSERT(T.rows()==3, AT);
1891 if(std::abs(T.e(0, 0)) >= tol ||
1892 std::abs(T.e(1, 1)) >= tol ||
1893 std::abs(T.e(2, 2)) >= tol ||
1894 std::abs(x.e(0) + T.e(1, 2)) >= tol ||
1895 std::abs(x.e(1) + T.e(2, 0)) >= tol ||
1896 std::abs(x.e(2) + T.e(0, 1)) >= tol) {
1897 std::cerr<<
"fmatvec::tilde called with a none screw symmetric matrix:"<<std::endl
1899 <<boost::stacktrace::stacktrace()<<std::endl;
1912 template <
class AT,
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2>
1921 for (
int i = 0; i < A.
rows(); i++)
1922 for (
int j = 0; j < A.
cols(); j++)
1923 if (A(i, j) != B(i, j))
1934 template <
class AT,
class Type1,
class Row1,
class Col1,
class Type2,
class Row2,
class Col2>
1940 for (
int i = 0; i < A.
rows(); i++)
1941 for (
int j = 0; j < A.
cols(); j++)
1942 if (A(i, j) != B(i, j))
1953 template <
class Row,
class AT>
1956 FMATVEC_ASSERT(x.size() > 0, AT);
1957 AT maximum = x.e(0);
1958 for (
int i = 1; i < x.size(); i++) {
1959 if (x.e(i) > maximum)
1970 template <
class Row,
class AT>
1973 FMATVEC_ASSERT(x.size() > 0, AT);
1974 AT maximum = x.e(0);
1976 for (
int i = 1; i < x.size(); i++) {
1977 if (x.e(i) > maximum) {
1990 template <
class Row,
class AT>
1993 FMATVEC_ASSERT(x.size() > 0, AT);
1994 AT minimum = x.e(0);
1995 for (
int i = 1; i < x.size(); i++) {
1996 if (x.e(i) < minimum)
2007 template <
class Row,
class AT>
2010 FMATVEC_ASSERT(x.size() > 0, AT);
2011 AT minimum = x.e(0);
2013 for (
int i = 1; i < x.size(); i++) {
2014 if (x.e(i) < minimum) {
2032 FMATVEC_ASSERT(A_.
rows() > 0, AT);
2033 FMATVEC_ASSERT(A_.
cols() > 0, AT);
2034 FMATVEC_ASSERT(A_.
cols() > PivotCol, AT);
2039 for (i = 1; i <= N - 1; i++) {
2040 for (j = 0; j < N - 1; j++) {
2041 if (A(j, PivotCol) > A(j + 1, PivotCol)) {
2043 A.set(j, A.
row(j + 1));
2057 int i = l - 1, j = r;
2060 int m = l + (r - l) / 2;
2061 if (A(l, PivotCol) > A(m, PivotCol)) {
2066 if (A(l, PivotCol) > A(r, PivotCol)) {
2071 else if (A(r, PivotCol) > A(m, PivotCol)) {
2079 while(A(++i,PivotCol) < A(r,PivotCol));
2080 while(A(--j,PivotCol) > A(r,PivotCol) && j>i);
2112 template <
class Row,
class Col,
class AT>
2113 inline Matrix<Symmetric, Col, Col, AT> JTJ(
const Matrix<General, Row, Col, AT> &A) {
2114 Matrix<Symmetric, Col, Col, AT> S(A.cols(), A.cols(), NONINIT);
2115 for (
int i = 0; i < A.cols(); i++) {
2116 for (
int k = i; k < A.cols(); k++) {
2118 for (
int j = 0; j < A.rows(); j++)
2119 S.ej(i, k) += A.e(j, i) * A.e(j, k);
2125 template <
class Row1,
class Row2,
class Col,
class AT>
2126 inline Matrix<Symmetric, Col, Col, AT> JTMJ(
const Matrix<Symmetric, Row2, Row2, AT> &B,
const Matrix<General, Row1, Col, AT> &A) {
2128 Matrix<Symmetric, Col, Col, AT> S(A.cols(), A.cols(), NONINIT);
2129 Matrix<General, Row1, Col, AT> C = B * A;
2131 for (
int i = 0; i < A.cols(); i++) {
2132 for (
int k = i; k < A.cols(); k++) {
2134 for (
int j = 0; j < A.rows(); j++)
2135 S.ej(i, k) += A.e(j, i) * C.e(j, k);
2141 template <
class Row,
class Col,
class AT>
2142 inline Matrix<Symmetric, Col, Col, AT> JTMJ(
const Matrix<SymmetricSparse, Ref, Ref, AT> &B,
const Matrix<General, Row, Col, AT> &A) {
2144 Matrix<Symmetric, Col, Col, AT> S(A.cols(), A.cols(), NONINIT);
2145 Matrix<General, Row, Col, AT> C = B * A;
2147 for (
int i = 0; i < A.cols(); i++) {
2148 for (
int k = i; k < A.cols(); k++) {
2150 for (
int j = 0; j < A.rows(); j++)
2151 S.ej(i, k) += A.e(j, i) * C.e(j, k);
2157 template <
class Row,
class Col1,
class Col2,
class AT>
2158 inline Matrix<Symmetric, Row, Row, AT> JMJT(
const Matrix<General, Row, Col1, AT> &A,
const Matrix<Symmetric, Col2, Col2, AT> &B) {
2160 Matrix<Symmetric, Row, Row, AT> S(A.rows(), A.rows(), NONINIT);
2161 Matrix<General, Row, Col1, AT> C = A * B;
2163 for (
int i = 0; i < S.size(); i++) {
2164 for (
int k = i; k < S.size(); k++) {
2166 for (
int j = 0; j < A.cols(); j++)
2167 S.ej(i, k) += C.e(k, j) * A.e(i, j);
This is a matrix class for general matrices.
Definition: general_matrix.h:42
int cols() const
Number of columns.
Definition: general_matrix.h:313
int rows() const
Number of rows.
Definition: general_matrix.h:307
const RowVector< Ref, AT > row(int i) const
Row operator.
Definition: general_matrix.h:525
This is the basic matrix class for arbitrary matrices.
Definition: matrix.h:52
int rows() const
Number of rows.
int cols() const
Number of columns.
This is a rowvector class of general shape in dense storage format.
Definition: row_vector.h:36
Namespace fmatvec.
Definition: _memory.cc:28
int maxIndex(const Vector< Row, AT > &x)
Index of maximum value.
Definition: linear_algebra.h:1971
void quicksortmedian_intern(Matrix< General, Ref, Ref, AT > &A, int PivotCol, RowVector< Ref, AT > &tmp, int l, int r)
Definition: linear_algebra.h:2054
RowVector< Row, AT > trans(const Vector< Row, AT > &x)
Transpose of a vector.
Definition: linear_algebra.h:1723
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:2104
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:2030
SquareMatrix< Row, AT > tilde(const Vector< Row, AT > &x)
Tilde operator.
Definition: linear_algebra.h:1846
AT scalarProduct(const Vector< Row, AT > &x, const Vector< Row, AT > &y)
Scalar product.
Definition: linear_algebra.h:1293
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:1311
int minIndex(const Vector< Row, AT > &x)
Index of minimum value.
Definition: linear_algebra.h:2008
bool operator!=(const Matrix< Type1, Row1, Col1, AT > &A, const Matrix< Type2, Row2, Col2, AT > &B)
Matrix-matrix comparison.
Definition: linear_algebra.h:1935
double tripleProduct(const Vector< Row, AT > &a, const Vector< Row, AT > &x, const Vector< Row, AT > &y)
Triple product.
Definition: linear_algebra.h:1331
bool operator==(const Matrix< Type1, Row1, Col1, AT > &A, const Matrix< Type2, Row2, Col2, AT > &B)
Matrix-matrix comparison.
Definition: linear_algebra.h:1913