1 #ifndef INMOST_DENSE_INCLUDED
2 #define INMOST_DENSE_INCLUDED
3 #include "inmost_common.h"
4 #include "inmost_expression.h"
14 template<
class A,
class B>
struct Promote;
15 template<>
struct ComplexType<INMOST_DATA_INTEGER_TYPE> {
typedef INMOST_DATA_INTEGER_TYPE type; };
16 template<>
struct ComplexType<INMOST_DATA_REAL_TYPE> {
typedef INMOST_DATA_REAL_TYPE type; };
17 template<>
struct ComplexType<INMOST_DATA_CPLX_TYPE> {
typedef INMOST_DATA_REAL_TYPE type; };
18 template<
typename T>
inline typename ComplexType<T>::type real_part(T
const& val) {
return std::real(val); }
19 template<>
struct SelfPromote<INMOST_DATA_INTEGER_TYPE> {
typedef INMOST_DATA_INTEGER_TYPE type; };
20 template<>
struct SelfPromote<INMOST_DATA_REAL_TYPE> {
typedef INMOST_DATA_REAL_TYPE type; };
21 template<>
struct SelfPromote<INMOST_DATA_CPLX_TYPE> {
typedef INMOST_DATA_CPLX_TYPE type; };
22 template<>
struct Promote<INMOST_DATA_INTEGER_TYPE, INMOST_DATA_INTEGER_TYPE> {
typedef INMOST_DATA_INTEGER_TYPE type;};
23 template<>
struct Promote<INMOST_DATA_INTEGER_TYPE, INMOST_DATA_REAL_TYPE> {
typedef INMOST_DATA_REAL_TYPE type;};
24 template<>
struct Promote<INMOST_DATA_INTEGER_TYPE, INMOST_DATA_CPLX_TYPE> {
typedef INMOST_DATA_CPLX_TYPE type;};
25 template<>
struct Promote<INMOST_DATA_REAL_TYPE, INMOST_DATA_INTEGER_TYPE> {
typedef INMOST_DATA_REAL_TYPE type;};
26 template<>
struct Promote<INMOST_DATA_REAL_TYPE, INMOST_DATA_REAL_TYPE> {
typedef INMOST_DATA_REAL_TYPE type;};
27 template<>
struct Promote<INMOST_DATA_REAL_TYPE, INMOST_DATA_CPLX_TYPE> {
typedef INMOST_DATA_CPLX_TYPE type;};
28 template<>
struct Promote<INMOST_DATA_CPLX_TYPE, INMOST_DATA_INTEGER_TYPE> {
typedef INMOST_DATA_CPLX_TYPE type;};
29 template<>
struct Promote<INMOST_DATA_CPLX_TYPE, INMOST_DATA_REAL_TYPE> {
typedef INMOST_DATA_CPLX_TYPE type;};
30 template<>
struct Promote<INMOST_DATA_CPLX_TYPE, INMOST_DATA_CPLX_TYPE> {
typedef INMOST_DATA_CPLX_TYPE type;};
32 template<>
struct Promote<INMOST_DATA_INTEGER_TYPE, float> {
typedef INMOST_DATA_REAL_TYPE type;};
33 template<>
struct Promote<float, INMOST_DATA_INTEGER_TYPE> {
typedef INMOST_DATA_REAL_TYPE type;};
34 template<>
struct Promote<INMOST_DATA_REAL_TYPE, float> {
typedef INMOST_DATA_REAL_TYPE type;};
35 template<>
struct Promote<float, INMOST_DATA_REAL_TYPE> {
typedef INMOST_DATA_REAL_TYPE type;};
36 template<>
struct Promote<INMOST_DATA_CPLX_TYPE, float> {
typedef INMOST_DATA_CPLX_TYPE type;};
37 template<>
struct Promote<float, INMOST_DATA_CPLX_TYPE> {
typedef INMOST_DATA_CPLX_TYPE type;};
38 template<>
struct Promote<float, float> {
typedef float type; };
40 template<>
struct Promote<INMOST_DATA_INTEGER_TYPE, double> {
typedef INMOST_DATA_REAL_TYPE type;};
41 template<>
struct Promote<double, INMOST_DATA_INTEGER_TYPE> {
typedef INMOST_DATA_REAL_TYPE type;};
42 template<>
struct Promote<INMOST_DATA_REAL_TYPE, double> {
typedef INMOST_DATA_REAL_TYPE type;};
43 template<>
struct Promote<double, INMOST_DATA_REAL_TYPE> {
typedef INMOST_DATA_REAL_TYPE type;};
44 template<>
struct Promote<INMOST_DATA_CPLX_TYPE, double> {
typedef INMOST_DATA_CPLX_TYPE type;};
45 template<>
struct Promote<double, INMOST_DATA_CPLX_TYPE> {
typedef INMOST_DATA_CPLX_TYPE type;};
46 template<>
struct Promote<double, double> {
typedef double type; };
48 #if defined(USE_AUTODIFF)
68 template<>
inline typename ComplexType<variable>::type real_part(variable
const& a) {
return a; }
69 template<>
inline typename ComplexType<value_reference>::type real_part(value_reference
const& a) {
return a; }
70 template<>
inline typename ComplexType<multivar_expression_reference>::type real_part(multivar_expression_reference
const& a) {
return a; }
71 template<>
inline typename ComplexType<hessian_multivar_expression_reference>::type real_part(hessian_multivar_expression_reference
const& a) {
return a; }
72 template<>
inline typename ComplexType<hessian_variable>::type real_part(hessian_variable
const& a) {
return a; }
73 template<>
inline typename ComplexType< std::complex<unknown> >::type real_part(std::complex<unknown>
const& a) {
return a.real(); }
74 template<>
inline typename ComplexType< std::complex<variable> >::type real_part(std::complex<variable>
const& a) {
return a.real(); }
75 template<>
inline typename ComplexType< std::complex<value_reference> >::type real_part(std::complex<value_reference>
const& a) {
return a.real(); }
76 template<>
inline typename ComplexType< std::complex<multivar_expression_reference> >::type real_part(std::complex<multivar_expression_reference>
const& a) {
return a.real(); }
77 template<>
inline typename ComplexType< std::complex<hessian_multivar_expression_reference> >::type real_part(std::complex<hessian_multivar_expression_reference>
const& a) {
return a.real(); }
78 template<>
inline typename ComplexType< std::complex<hessian_variable> >::type real_part(std::complex<hessian_variable>
const& a) {
return a.real(); }
95 template<>
struct Promote<INMOST_DATA_CPLX_TYPE,
unknown> {
typedef std::complex<variable> type; };
96 template<>
struct Promote<INMOST_DATA_CPLX_TYPE,
variable> {
typedef std::complex<variable> type; };
97 template<>
struct Promote<INMOST_DATA_CPLX_TYPE,
value_reference> {
typedef std::complex<INMOST_DATA_REAL_TYPE> type; };
153 #if defined(USE_FP64)
168 template<>
struct Promote<double, unknown> {
typedef variable type; };
169 template<>
struct Promote<value_reference, double> {
typedef INMOST_DATA_REAL_TYPE type;};
170 template<>
struct Promote<double, value_reference> {
typedef INMOST_DATA_REAL_TYPE type; };
171 template<>
struct Promote<multivar_expression_reference, double> {
typedef variable type; };
172 template<>
struct Promote<double, multivar_expression_reference> {
typedef variable type; };
173 template<>
struct Promote<variable, double> {
typedef variable type;};
174 template<>
struct Promote<double, variable> {
typedef variable type; };
175 template<>
struct Promote<hessian_multivar_expression_reference, double> {
typedef hessian_variable type; };
176 template<>
struct Promote<double, hessian_multivar_expression_reference> {
typedef hessian_variable type;};
177 template<>
struct Promote<hessian_variable, double> {
typedef hessian_variable type;};
178 template<>
struct Promote<double, hessian_variable> {
typedef hessian_variable type; };
189 template<
typename Var>
194 static Var sign_func(
const Var& a,
const Var& b) {
return (real_part(get_value(b)) >= 0.0 ? fabs(a) : -fabs(a)); }
196 static INMOST_DATA_REAL_TYPE max_func(INMOST_DATA_REAL_TYPE x, INMOST_DATA_REAL_TYPE y) {
return x > y ? x : y; }
198 static Var pythag(
const Var& a,
const Var& b)
200 Var at = fabs(a), bt = fabs(b), ct;
201 if (real_part(get_value(at)) > real_part(get_value(bt))) { ct = bt / at;
return at * sqrt(1.0 + ct * ct); }
202 else if (real_part(get_value(bt)) > 0.0) { ct = at / bt;
return bt * sqrt(1.0 + ct * ct); }
207 typedef unsigned enumerator;
210 virtual enumerator
Rows()
const = 0;
213 virtual enumerator
Cols()
const = 0;
219 virtual Var
compute(enumerator i, enumerator j)
const = 0;
233 const double eps = 1.0e-13;
234 const enumerator n =
Rows();
239 for (enumerator d = 0; d < n; ++d)
244 while(row_visited(r,0) != -1 || fabs(get_value(A(r, d))) < eps)
246 if(r == n-1)
return Var(0);
247 if(row_visited(r,0) == -1) sign *= -1;
250 row_visited(r,0) = d;
251 ret *= sign * A(r, d);
252 for (enumerator i = 0; i < n; ++i)
if(row_visited(i,0) == -1)
254 coef = A(i, d) / A(r, d);
256 for (enumerator j = 0; j < n; ++j)
257 A(i, j) = A(i, j) - coef * A(r, j);
292 template<
typename typeB>
299 template<
typename typeB>
305 template<
typename typeB>
312 template<
typename typeB>
319 template<
typename typeB>
328 template<
typename typeB>
362 template<
typename typeB>
374 template<
typename typeB>
383 for (enumerator i = 0; i <
Rows(); ++i) ret +=
compute(i, i);
389 void Print(INMOST_DATA_REAL_TYPE threshold = 1.0e-10, std::ostream & sout = std::cout)
const
391 for (enumerator k = 0; k <
Rows(); ++k)
393 for (enumerator l = 0; l <
Cols(); ++l)
400 if (fabs(get_value(
compute(k, l))) > threshold)
401 sout << std::setw(12) << get_value(
compute(k, l));
403 sout << std::setw(12) << 0;
414 for (enumerator k = 0; k <
Rows(); ++k)
416 for (enumerator l = k + 1; l <
Rows(); ++l)
426 template<
typename typeB>
433 for (enumerator i = 0; i <
Rows(); ++i)
434 for (enumerator j = 0; j <
Cols(); ++j)
442 template<
typename typeB>
452 for (enumerator i = 0; i <
Rows(); ++i)
453 for (enumerator j = 0; j <
Cols(); ++j)
462 for (enumerator i = 0; i <
Rows(); ++i)
463 for (enumerator j = 0; j <
Cols(); ++j)
464 ret = std::max<Var>(ret,
compute(i, j));
491 Matrix<Var> Root(INMOST_DATA_ENUM_TYPE iter = 25, INMOST_DATA_REAL_TYPE tol = 1.0e-7,
int* ierr = NULL)
const;
502 template<
typename typeB>
543 template<
typename typeB>
547 #if defined(USE_AUTODIFF)
559 template<typename typeB>
563 #if defined(USE_AUTODIFF)
578 template<typename typeB>
583 ret = other.
Solve(*
this);
602 template<
typename VarB>
624 template<
typename VarB>
635 INMOST_DATA_ENUM_TYPE cnt = 0;
636 for (INMOST_DATA_ENUM_TYPE i = 0; i <
Rows(); ++i)
637 for (INMOST_DATA_ENUM_TYPE j = 0; j <
Cols(); ++j)
638 cnt += GetCount(
compute(i, j));
645 template<
typename Var>
658 typedef typename AbstractMatrixReadOnly<Var>::enumerator enumerator;
688 for(enumerator i = 0; i < other.
Rows(); ++i)
689 for(enumerator j = 0; j < other.
Cols(); ++j)
690 assign((*
this)(i,j),other.
get(i,j));
696 template<
typename typeB>
700 for(enumerator i = 0; i < other.
Rows(); ++i)
701 for(enumerator j = 0; j < other.
Cols(); ++j)
702 assign((*
this)(i,j),other.
compute(i,j));
710 for(enumerator i = 0; i <
Rows(); ++i)
711 for(enumerator j = 0; j <
Cols(); ++j)
712 assign((*
this)(i,j),b);
724 virtual const Var &
get(enumerator i, enumerator j)
const = 0;
728 virtual void Resize(enumerator rows, enumerator cols) = 0;
732 for(enumerator i = 0; i <
Rows(); ++i)
733 for(enumerator j = 0; j <
Cols(); ++j)
741 template<
typename typeB>
746 template<
typename typeB>
751 template<
typename typeB>
756 template<
typename typeB>
761 template<
typename typeB>
766 template<
typename typeB>
771 template<
typename typeB>
820 for (enumerator i = 0; i <
Rows(); ++i)
821 for (enumerator j = 0; j <
Cols(); ++j)
822 if (check_nans(
compute(i, j)))
return true;
829 for (enumerator i = 0; i <
Rows(); ++i)
830 for (enumerator j = 0; j <
Cols(); ++j)
831 if (check_infs(
compute(i, j)))
return true;
838 for (enumerator i = 0; i <
Rows(); ++i)
839 for (enumerator j = 0; j <
Cols(); ++j)
840 if (check_nans_infs(
compute(i, j)))
return true;
847 template<
typename typeB>
854 template<
typename typeB>
862 template<
typename typeB>
870 template<
typename typeB>
877 template<
typename typeB>
884 for (enumerator i = 0; i <
Rows(); ++i)
885 for (enumerator j = 0; j <
Cols(); ++j)
886 ret +=
get(i, j) * other.
get(i, j);
893 template<
typename typeB>
900 for (enumerator i = 0; i <
Rows(); ++i)
901 for (enumerator j = 0; j <
Cols(); ++j)
909 template<
typename typeB>
918 template<
typename typeB>
928 for (enumerator i = 0; i <
Rows(); ++i)
929 for (enumerator j = 0; j <
Cols(); ++j)
930 ret += pow(
get(i, j), 2);
938 for (enumerator i = 0; i <
Rows(); ++i)
939 for (enumerator j = 0; j <
Cols(); ++j)
940 ret = std::max<Var>(ret,
get(i, j));
949 for (enumerator i = 0; i <
Rows(); ++i) ret +=
get(i, i);
955 void Print(INMOST_DATA_REAL_TYPE threshold = 1.0e-10, std::ostream& sout = std::cout)
const
957 for (enumerator k = 0; k <
Rows(); ++k)
959 for (enumerator l = 0; l <
Cols(); ++l)
966 if (fabs(get_value(
compute(k, l))) > threshold)
967 sout << std::setw(12) << get_value(
get(k, l));
969 sout << std::setw(12) << 0;
980 for (enumerator k = 0; k <
Rows(); ++k)
982 for (enumerator l = k + 1; l <
Rows(); ++l)
983 if (fabs(
get(k, l) -
get(l, k)) > eps)
997 void MPT(INMOST_DATA_ENUM_TYPE* Perm, INMOST_DATA_REAL_TYPE* SL = NULL, INMOST_DATA_REAL_TYPE* SR = NULL)
const;
1001 INMOST_DATA_ENUM_TYPE cnt = 0;
1002 for (INMOST_DATA_ENUM_TYPE i = 0; i <
Rows(); ++i)
1003 for (INMOST_DATA_ENUM_TYPE j = 0; j <
Cols(); ++j)
1004 cnt += GetCount(
get(i, j));
1012 template<
typename Var,
typename storage_type>
1016 typedef typename AbstractMatrix<Var>::enumerator enumerator;
1026 #if defined(_CPPRTTI) || defined(__GXX_RTTI)
1030 space.swap((*bb).space);
1031 std::swap(n,(*bb).n);
1044 SymmetricMatrix(
const Var * pspace, enumerator pn) : space(pspace,pspace+pn*(pn+1)/2), n(pn) {}
1072 va_start(argptr, pn);
1073 for (enumerator j = 0; j < pn; ++j)
1074 for (enumerator i = j; i < pn; ++i)
1076 Var val = va_arg(argptr, Var);
1100 template<
typename typeB>
1103 assert(other.
Rows() == other.
Cols());
1104 for(enumerator i = 0; i < n; ++i)
1105 for(enumerator j = i; j < n; ++j)
1106 assign((*
this)(i,j),other.
compute(i,j));
1114 template<
typename typeB>
1117 assert(other.
Rows() == other.
Cols());
1118 for (enumerator i = 0; i < n; ++i)
1119 for (enumerator j = i; j < n; ++j)
1120 assign((*
this)(i, j), other.
get(i, j));
1128 void Resize(enumerator nrows, enumerator ncols)
1131 assert(nrows == ncols);
1132 if( space.size() != (nrows+1)*nrows/2 )
1133 space.resize((nrows+1)*nrows/2);
1141 if(
this != &other )
1144 space.resize(other.n*(other.n+1)/2);
1145 for(enumerator i = 0; i < other.n*(other.n+1)/2; ++i)
1146 space[i] = other.space[i];
1156 template<
typename typeB>
1159 assert(other.
Rows() == other.
Cols());
1161 space.resize((other.
Rows() + 1) * other.
Rows() / 2);
1163 for (enumerator i = 0; i < other.
Rows(); ++i)
1164 for (enumerator j = i; j < other.
Cols(); ++j)
1165 assign((*
this)(i, j), other.
get(i, j));
1173 template<
typename typeB>
1176 assert(other.
Rows() == other.
Cols());
1178 space.resize((other.
Rows() + 1) * other.
Rows() / 2);
1180 for (enumerator i = 0; i < other.
Rows(); ++i)
1181 for (enumerator j = i; j < other.
Cols(); ++j)
1182 assign((*
this)(i, j), other.
compute(i, j));
1193 if( i > j ) std::swap(i,j);
1194 return space[j+n*i-i*(i+1)/2];
1200 __INLINE
const Var&
get(enumerator i, enumerator j)
const
1204 if (i > j) std::swap(i, j);
1205 return space[j + n * i - i * (i + 1) / 2];
1212 __INLINE Var
compute(enumerator i, enumerator j)
const
1216 if( i > j ) std::swap(i,j);
1217 return space[j+n*i-i*(i+1)/2];
1222 __INLINE Var *
data() {
return space.data();}
1226 __INLINE
const Var *
data()
const {
return space.data();}
1229 __INLINE enumerator
Rows()
const {
return n;}
1232 __INLINE enumerator
Cols()
const {
return n;}
1235 __INLINE enumerator &
Rows() {
return n;}
1238 __INLINE enumerator &
Cols() {
return n;}
1267 assert(size == 1 || size == 2 || size == 3 || size == 4);
1271 Kc(0,0) = Kc(1,1) = K[0];
1284 else if( matsize == 3 )
1286 assert(size == 1 || size == 3 || size == 6 || size == 9);
1290 Kc(0,0) = Kc(1,1) = Kc(2,2) = K[0];
1307 else if( matsize == 6 )
1309 assert(size == 1 || size == 6 || size == 21 || size == 36);
1313 Kc(0,0) = Kc(1,1) = Kc(2,2) = Kc(3,3) = Kc(4,4) = Kc(5,5) = K[0];
1357 for(enumerator k = 0; k < size; ++k) ret(k,k) = r[k];
1368 for(enumerator k = 0; k < size; ++k) ret(k,k) = 1.0/r[k];
1379 for(enumerator i = 0; i < pn; ++i) ret(i,i) = c;
1432 template<
typename Var,
typename storage_type>
1436 typedef typename AbstractMatrix<Var>::enumerator enumerator;
1444 Var& operator [](enumerator k) {
return space[k]; }
1445 const Var& operator[](enumerator k)
const {
return space[k]; }
1451 for(enumerator k = row+1; k < n; ++k)
1453 for(enumerator l = 0; l < m; ++l)
1454 (*
this)(k-1,l) = (*
this)(k,l);
1456 space.resize((n-1)*m);
1468 assert(first <= last);
1469 enumerator shift = last-first;
1470 for(enumerator k = last; k < n; ++k)
1472 for(enumerator l = 0; l < m; ++l)
1473 (*
this)(k-shift,l) = (*
this)(k,l);
1475 space.resize((n-shift)*m);
1484 for(enumerator k = 0; k < n; ++k)
1486 for(enumerator l = 0; l < col; ++l)
1487 tmp(k,l) = (*this)(k,l);
1488 for(enumerator l = col+1; l < m; ++l)
1489 tmp(k,l-1) = (*this)(k,l);
1502 assert(first <= last);
1503 enumerator shift = last-first;
1505 for(enumerator k = 0; k < n; ++k)
1507 for(enumerator l = 0; l < first; ++l)
1508 tmp(k,l) = (*this)(k,l);
1509 for(enumerator l = last; l < m; ++l)
1510 tmp(k,l-shift) = (*this)(k,l);
1519 void RemoveSubset(enumerator firstrow, enumerator lastrow, enumerator firstcol, enumerator lastcol)
1521 enumerator shiftrow = lastrow-firstrow;
1522 enumerator shiftcol = lastcol-firstcol;
1524 for(enumerator k = 0; k < firstrow; ++k)
1526 for(enumerator l = 0; l < firstcol; ++l)
1527 tmp(k,l) = (*this)(k,l);
1528 for(enumerator l = lastcol; l < m; ++l)
1529 tmp(k,l-shiftcol) = (*this)(k,l);
1531 for(enumerator k = lastrow; k < n; ++k)
1533 for(enumerator l = 0; l < firstcol; ++l)
1534 tmp(k-shiftrow,l) = (*this)(k,l);
1535 for(enumerator l = lastcol; l < m; ++l)
1536 tmp(k-shiftrow,l-shiftcol) = (*this)(k,l);
1543 #if defined(_CPPRTTI) || defined(__GXX_RTTI)
1547 space.swap((*bb).space);
1548 std::swap(n,(*bb).n);
1549 std::swap(m,(*bb).m);
1562 Matrix(
const Var * pspace, enumerator pn, enumerator pm) : space(pspace,pspace+pn*pm), n(pn), m(pm) {}
1570 Matrix(
const storage_type & pspace, enumerator pn, enumerator pm) : space(pspace), n(pn), m(pm) {}
1576 Matrix(
const storage_type & pspace) : space(pspace), n(0), m(0) {}
1581 Matrix(enumerator pn, enumerator pm) : space(pn*pm), n(pn), m(pm) {}
1586 Matrix(enumerator pn, enumerator pm,
const Var & c) : space(pn*pm,c), n(pn), m(pm) {}
1595 va_start(argptr, pm);
1596 for (enumerator i = 0; i < pn; ++i)
1597 for (enumerator j = 0; j < pm; ++j)
1599 Var val = va_arg(argptr, Var);
1616 template<
typename typeB>
1619 for(enumerator i = 0; i < n; ++i)
1620 for(enumerator j = 0; j < m; ++j)
1621 assign((*
this)(i,j),other.
compute(i,j));
1627 template<
typename typeB>
1630 for (enumerator i = 0; i < n; ++i)
1631 for (enumerator j = 0; j < m; ++j)
1632 assign((*
this)(i, j), other.
get(i, j));
1639 void Resize(enumerator nrows, enumerator mcols)
1641 if( space.size() != mcols*nrows )
1642 space.resize(mcols*nrows);
1651 if(
this != &other )
1653 if( n*m != other.n*other.m )
1654 space.resize(other.n*other.m);
1655 for(enumerator i = 0; i < other.n*other.m; ++i)
1656 space[i] = other.space[i];
1665 template<
typename typeB>
1669 space.resize(other.
Cols()*other.
Rows());
1672 for(enumerator i = 0; i < other.
Rows(); ++i)
1673 for(enumerator j = 0; j < other.
Cols(); ++j)
1674 assign((*
this)(i,j),other.
compute(i,j));
1680 template<
typename typeB>
1684 space.resize(other.
Cols() * other.
Rows());
1687 for (enumerator i = 0; i < other.
Rows(); ++i)
1688 for (enumerator j = 0; j < other.
Cols(); ++j)
1689 assign((*
this)(i, j), other.
get(i, j));
1700 assert(i*m+j < n*m);
1701 return space[i*m+j];
1707 __INLINE Var
compute(enumerator i, enumerator j)
const
1711 assert(i*m+j < n*m);
1712 return space[i*m+j];
1719 __INLINE
const Var &
get(enumerator i, enumerator j)
const
1723 assert(i * m + j < n* m);
1724 return space[i * m + j];
1728 __INLINE Var *
data() {
return space.data();}
1732 __INLINE
const Var *
data()
const {
return space.data();}
1735 __INLINE enumerator
Rows()
const {
return n;}
1738 __INLINE enumerator
Cols()
const {
return m;}
1741 __INLINE enumerator &
Rows() {
return n;}
1744 __INLINE enumerator &
Cols() {
return m;}
1758 for(enumerator k = 0; k < size; ++k)
1793 assert(size == 1 || size == 2 || size == 3 || size == 4);
1797 Kc(0,0) = Kc(1,1) = K[0];
1805 Kc(0,1) = Kc(1,0) = K[1];
1816 else if( matsize == 3 )
1818 assert(size == 1 || size == 3 || size == 6 || size == 9);
1822 Kc(0,0) = Kc(1,1) = Kc(2,2) = K[0];
1831 Kc(0,1) = Kc(1,0) = K[1];
1832 Kc(0,2) = Kc(2,0) = K[2];
1834 Kc(1,2) = Kc(2,1) = K[4];
1850 else if( matsize == 6 )
1852 assert(size == 1 || size == 6 || size == 21 || size == 36);
1856 Kc(0,0) = Kc(1,1) = Kc(2,2) = Kc(3,3) = Kc(4,4) = Kc(5,5) = K[0];
1866 Kc(0,1) = Kc(1,0) = K[1];
1867 Kc(0,2) = Kc(2,0) = K[2];
1868 Kc(0,3) = Kc(3,0) = K[3];
1869 Kc(0,4) = Kc(4,0) = K[4];
1870 Kc(0,5) = Kc(5,0) = K[5];
1872 Kc(1,2) = Kc(2,1) = K[7];
1873 Kc(1,3) = Kc(3,1) = K[8];
1874 Kc(1,4) = Kc(4,1) = K[9];
1875 Kc(1,5) = Kc(5,1) = K[10];
1877 Kc(2,3) = Kc(3,2) = K[12];
1878 Kc(2,4) = Kc(4,2) = K[13];
1879 Kc(2,5) = Kc(5,2) = K[14];
1881 Kc(3,4) = Kc(4,3) = K[16];
1882 Kc(3,5) = Kc(5,3) = K[17];
1884 Kc(4,5) = Kc(5,4) = K[19];
1889 for(
int i = 0; i < 6; ++i)
1890 for(
int j = 0; j < 6; ++j)
1913 for(enumerator k = 0; k < size; ++k) ret(k,k) = r[k];
1924 for(enumerator k = 0; k < size; ++k) ret(k,k) = 1.0/r[k];
1992 enumerator N =
Rows();
1998 Var ton, toff, theta, c, s, Ap, Aq, Vp, Vq;
2003 for(enumerator p = 0; p < N-1; ++p)
2005 for(enumerator q = p+1; q < N; ++q)
2007 for(enumerator k = 0; k < M; ++k)
2009 R(0,k) = A(p,p + k*N) - A(q,q + k*N);
2010 R(1,k) = A(p,q + k*N) + A(q,p + k*N);
2013 Var ton = G(0,0) - G(1,1);
2014 Var toff = G(0,1) + G(1,0);
2015 Var theta = 0.5 * atan2( toff, ton + sqrt(ton*ton + toff*toff) );
2018 if( fabs(s) > threshold )
2022 for(enumerator k = 0; k < M; ++k)
2024 for(enumerator i = 0; i < N; ++i)
2028 A(i,p + k*N) = Ap*c + Aq*s;
2029 A(i,q + k*N) = Aq*c - Ap*s;
2032 for(enumerator k = 0; k < M; ++k)
2034 for(enumerator j = 0; j < N; ++j)
2038 A(p,j + k*N) = Ap*c + Aq*s;
2039 A(q,j + k*N) = Aq*c - Ap*s;
2042 for(enumerator i = 0; i < N; ++i)
2046 V(i,p) = Vp*c + Vq*s;
2047 V(i,q) = Vq*c - Vp*s;
2081 template<
typename Var>
2088 typedef typename AbstractMatrix<Var>::enumerator enumerator;
2098 __INLINE enumerator
Rows()
const {
return erow-brow;}
2101 __INLINE enumerator
Cols()
const {
return ecol-bcol;}
2108 SubMatrix(
AbstractMatrix<Var> & rM, enumerator first_row, enumerator last_row, enumerator first_column, enumerator last_column) : M(&rM), brow(first_row), erow(last_row), bcol(first_column), ecol(last_column)
2110 SubMatrix(
const SubMatrix & b) : M(b.M), brow(b.brow), erow(b.erow), bcol(b.bcol), ecol(b.ecol) {}
2114 template<
typename typeB>
2119 for (enumerator i = 0; i < other.
Rows(); ++i)
2120 for (enumerator j = 0; j < other.
Cols(); ++j)
2121 assign((*
this)(i, j), other.
compute(i, j));
2127 template<
typename typeB>
2132 for(enumerator i = 0; i < other.
Rows(); ++i)
2133 for(enumerator j = 0; j < other.
Cols(); ++j)
2134 assign((*
this)(i,j),other.
get(i,j));
2140 template<
typename typeB>
2145 for(enumerator i = 0; i < other.
Rows(); ++i)
2146 for(enumerator j = 0; j < other.
Cols(); ++j)
2147 assign((*
this)(i,j),other.
get(i,j));
2159 return (*M)(i+brow,j+bcol);
2166 __INLINE Var
compute(enumerator i, enumerator j)
const
2171 return (*M)(i+brow,j+bcol);
2178 __INLINE
const Var &
get(enumerator i, enumerator j)
const
2183 return M->
get(i + brow, j + bcol);
2193 for(enumerator i = 0; i <
Rows(); ++i)
2194 for(enumerator j = 0; j <
Cols(); ++j)
2195 ret(i,j) = (*this)(i,j);
2201 void Resize(enumerator rows, enumerator cols)
2203 assert(
Cols() == cols);
2204 assert(
Rows() == rows);
2205 (void)cols; (void)rows;
2210 template<
typename Var>
2215 typedef typename AbstractMatrixReadOnly<Var>::enumerator enumerator;
2225 __INLINE enumerator
Rows()
const {
return erow-brow;}
2228 __INLINE enumerator
Cols()
const {
return ecol-bcol;}
2235 ConstSubMatrix(
const AbstractMatrixReadOnly<Var> & rM, enumerator first_row, enumerator last_row, enumerator first_column, enumerator last_column) : M(&rM), brow(first_row), erow(last_row), bcol(first_column), ecol(last_column)
2244 __INLINE Var
compute(enumerator i, enumerator j)
const
2249 return M->
compute(i+brow,j+bcol);
2259 for(enumerator i = 0; i <
Rows(); ++i)
2260 for(enumerator j = 0; j <
Cols(); ++j)
2261 ret(i,j) = (*this)(i,j);
2267 template<
typename Var>
2273 typedef typename AbstractMatrix<Var>::enumerator enumerator;
2283 __INLINE enumerator
Rows()
const {
return nrows;}
2286 __INLINE enumerator
Cols()
const {
return ncols;}
2293 BlockOfMatrix(
AbstractMatrix<Var> & rM, enumerator num_rows, enumerator num_cols, enumerator offset_row, enumerator offset_col) : M(&rM), nrows(num_rows), ncols(num_cols), orow(offset_row), ocol(offset_col)
2300 template<
typename typeB>
2305 for(enumerator i = orow; i < orow+M->
Rows(); ++i)
2306 for(enumerator j = ocol; j < ocol+M->
Cols(); ++j)
2307 assign((*M)(i-orow,j-ocol),other(i,j));
2313 template<
typename typeB>
2318 for(enumerator i = orow; i < orow+M->
Rows(); ++i)
2319 for(enumerator j = ocol; j < ocol+M->
Cols(); ++j)
2320 assign((*M)(i-orow,j-ocol),other(i,j));
2331 if (i < orow || i >= orow + M->
Rows() || j < ocol || j >= ocol + M->
Cols())
2333 static Var zero(0.0);
2334 assert(zero == 0.0);
2338 return (*M)(i-orow,j-ocol);
2345 __INLINE Var
compute(enumerator i, enumerator j)
const
2349 if (i < orow || i >= orow + M->
Rows() || j < ocol || j >= ocol + M->
Cols())
2352 return M->
compute(i-orow,j-ocol);
2361 __INLINE
const Var &
get(enumerator i, enumerator j)
const
2365 assert(! (i < orow || i >= orow + M->
Rows() || j < ocol || j >= ocol + M->
Cols()) );
2366 return M->
get(i-orow,j-ocol);
2376 for(enumerator i = 0; i <
Rows(); ++i)
2377 for(enumerator j = 0; j <
Cols(); ++j)
2378 ret(i,j) = (*this)(i,j);
2384 void Resize(enumerator rows, enumerator cols)
2386 assert(
Cols() == cols);
2387 assert(
Rows() == rows);
2388 (void)cols; (void)rows;
2393 template<
typename Var>
2398 typedef typename AbstractMatrixReadOnly<Var>::enumerator enumerator;
2408 __INLINE enumerator
Rows()
const {
return nrows;}
2411 __INLINE enumerator
Cols()
const {
return ncols;}
2426 __INLINE Var
compute(enumerator i, enumerator j)
const
2430 if (i < orow || i >= orow + M->
Rows() || j < ocol || j >= ocol + M->
Cols())
2433 return M->
compute(i-orow,j-ocol);
2443 for(enumerator i = 0; i <
Rows(); ++i)
2444 for(enumerator j = 0; j <
Cols(); ++j)
2445 ret(i,j) = (*this)(i,j);
2451 template<
typename Var>
2456 typedef typename AbstractMatrixReadOnly<Var>::enumerator enumerator;
2461 MatrixUnit(enumerator n,
const Var & c = Var(1.0)) :n(n), c(c) {}
2465 __INLINE enumerator
Rows()
const {
return n; }
2468 __INLINE enumerator
Cols()
const {
return n; }
2469 __INLINE Var
compute(enumerator i, enumerator j)
const
2471 return i == j ? c : Var(0.0);
2476 template<
typename Var>
2481 typedef typename AbstractMatrixReadOnly<Var>::enumerator enumerator;
2486 MatrixRow(enumerator n,
const Var& c = Var(1.0)) :n(n), c(c) {}
2490 __INLINE enumerator
Rows()
const {
return 1; }
2493 __INLINE enumerator
Cols()
const {
return n; }
2494 __INLINE Var
compute(enumerator i, enumerator j)
const {
return c; }
2498 template<
typename Var>
2503 typedef typename AbstractMatrixReadOnly<Var>::enumerator enumerator;
2508 MatrixCol(enumerator n,
const Var& c = Var(1.0)) :n(n), c(c) {}
2512 __INLINE enumerator
Rows()
const {
return n; }
2515 __INLINE enumerator
Cols()
const {
return 1; }
2516 __INLINE Var
compute(enumerator i, enumerator j)
const {
return c; }
2520 template<
typename Var>
2525 typedef typename AbstractMatrixReadOnly<Var>::enumerator enumerator;
2530 MatrixDiag(Var* diag, enumerator n) : diag(diag), n(n) {}
2534 __INLINE enumerator
Rows()
const {
return n; }
2537 __INLINE enumerator
Cols()
const {
return n; }
2538 __INLINE Var
compute(enumerator i, enumerator j)
const
2540 return i == j ? diag[i] : Var(0.0);
2544 INMOST_DATA_ENUM_TYPE cnt = 0;
2545 for (enumerator k = 0; k < n; ++k)
2546 cnt += GetCount(diag[k]);
2551 template<
typename VarA,
typename VarB>
2574 MatrixSum(
const MatrixSum& b) : A(b.A), B(b.B) {}
2589 template<
typename VarA,
typename VarB>
2612 MatrixDifference(
const MatrixDifference& b) : A(b.A), B(b.B) {}
2627 template<
typename Var>
2632 typedef typename AbstractMatrixReadOnly<Var>::enumerator enumerator;
2644 ConstMatrixTranspose(
const ConstMatrixTranspose& b) : A(b.A) {}
2654 template<
typename Var>
2659 typedef typename AbstractMatrixReadOnly<Var>::enumerator enumerator;
2672 ConstMatrixConjugateTranspose(
const ConstMatrixConjugateTranspose& b) : A(b.A) {}
2678 __INLINE Var
compute(enumerator i, enumerator j)
const {
return conj(A->
compute(j, i)); }
2684 template<
typename Var>
2689 typedef typename AbstractMatrixReadOnly<Var>::enumerator enumerator;
2702 ConstMatrixConjugate(
const ConstMatrixConjugate& b) : A(b.A) {}
2708 __INLINE Var
compute(enumerator i, enumerator j)
const {
return conj(A->
compute(i, j)); }
2714 template<
typename Var>
2719 typedef typename AbstractMatrixReadOnly<Var>::enumerator enumerator;
2732 MatrixUnaryMinus(
const MatrixUnaryMinus& b) : A(b.A) {}
2744 template<
typename Var>
2750 typedef typename AbstractMatrix<Var>::enumerator enumerator;
2762 MatrixTranspose(
const MatrixTranspose& b) : A(b.A) {}
2774 __INLINE Var&
operator()(enumerator i, enumerator j) {
return (*A)(j, i); }
2780 __INLINE
const Var&
get(enumerator i, enumerator j)
const {
return A->
get(j, i); }
2784 void Resize(enumerator rows, enumerator cols)
2786 assert(
Cols() == cols);
2787 assert(
Rows() == rows);
2788 (void)cols; (void)rows;
2793 template<
typename Var>
2798 typedef typename AbstractMatrixReadOnly<Var>::enumerator enumerator;
2813 ConstMatrixConcatRows(
const ConstMatrixConcatRows& b) : A(b.A), B(b.B) {}
2819 __INLINE Var
compute(enumerator i, enumerator j)
const
2826 template<
typename VarA,
typename VarB,
typename VarR>
2847 ConstMatrixConcatRows2(
const ConstMatrixConcatRows2& b) : A(b.A), B(b.B) {}
2853 __INLINE VarR
compute(enumerator i, enumerator j)
const
2865 template<
typename Var>
2870 typedef typename AbstractMatrix<Var>::enumerator enumerator;
2882 : A(&rA), B(&rB) { assert(A->
Cols() == B->
Cols()); }
2883 MatrixConcatRows(
const MatrixConcatRows& b) : A(b.A), B(b.B) {}
2889 __INLINE Var
compute(enumerator i, enumerator j)
const
2900 return i < A->
Rows() ? (*A)(i, j) : (*B)(i - A->
Rows(), j);
2907 __INLINE
const Var&
get(enumerator i, enumerator j)
const
2914 void Resize(enumerator rows, enumerator cols)
2916 assert(
Cols() == cols);
2917 assert(
Rows() == rows);
2918 (void)cols; (void)rows;
2923 template<
typename Var>
2928 typedef typename AbstractMatrixReadOnly<Var>::enumerator enumerator;
2943 ConstMatrixConcatCols(
const ConstMatrixConcatCols& b) : A(b.A), B(b.B) {}
2949 __INLINE Var
compute(enumerator i, enumerator j)
const
2956 template<
typename VarA,
typename VarB,
typename VarR>
2977 ConstMatrixConcatCols2(
const ConstMatrixConcatCols2& b) : A(b.A), B(b.B) {}
2983 __INLINE VarR
compute(enumerator i, enumerator j)
const
2995 template<
typename Var>
3001 typedef typename AbstractMatrix<Var>::enumerator enumerator;
3013 : A(&rA), B(&rB) { assert(A->
Rows() == B->
Rows()); }
3014 MatrixConcatCols(
const MatrixConcatCols& b) : A(b.A), B(b.B) {}
3020 __INLINE Var
compute(enumerator i, enumerator j)
const
3031 return j < A->
Cols() ? (*A)(i, j) : (*B)(i, j - A->
Cols());
3038 __INLINE
const Var&
get(enumerator i, enumerator j)
const
3045 void Resize(enumerator rows, enumerator cols)
3047 assert(
Cols() == cols);
3048 assert(
Rows() == rows);
3049 (void)cols; (void)rows;
3054 template<
typename Var>
3059 typedef typename AbstractMatrixReadOnly<Var>::enumerator enumerator;
3066 __INLINE enumerator
Rows()
const {
return n; }
3069 __INLINE enumerator
Cols()
const {
return m; }
3071 : A(&rA), n(n), m(m) { assert(A->
Rows() * A->
Cols() == n * m); }
3072 ConstMatrixRepack(
const ConstMatrixRepack& b) : A(b.A), n(b.n), m(b.m) {}
3078 __INLINE Var
compute(enumerator i, enumerator j)
const
3080 enumerator ind = i * m + j;
3086 template<
typename Var>
3092 typedef typename AbstractMatrix<Var>::enumerator enumerator;
3099 __INLINE enumerator
Rows()
const {
return n; }
3102 __INLINE enumerator
Cols()
const {
return m; }
3104 : A(&rA), n(n), m(m) {
3105 assert(A->
Rows() * A->
Cols() == n * m);
3107 MatrixRepack(
const MatrixRepack& b) : A(b.A), n(b.n), m(b.m) {}
3113 __INLINE Var
compute(enumerator i, enumerator j)
const
3115 enumerator p = i * m + j;
3125 enumerator p = i * m + j;
3126 return (*A)(p / A->
Cols(), p % A->
Cols());
3134 __INLINE
const Var&
get(enumerator i, enumerator j)
const
3136 enumerator p = i * m + j;
3143 void Resize(enumerator rows, enumerator cols)
3145 assert(
Cols() == cols);
3146 assert(
Rows() == rows);
3147 (void)cols; (void)rows;
3152 template<
typename VarA,
typename VarB,
typename VarR>
3165 void Resize(enumerator rows, enumerator cols)
3167 assert(
Cols() == cols);
3168 assert(
Rows() == rows);
3169 (void)cols; (void)rows;
3190 static thread_private< Matrix<VarB> > tmpB;
3195 for (enumerator i = 0; i < pA->
Rows(); ++i)
3197 for (enumerator k = 0; k < pB->
Cols(); ++k)
3198 M(i, k) = pA->
get(i, 0) * pB->
get(0, k);
3199 for (enumerator j = 1; j < pA->
Cols(); ++j)
3200 for (enumerator k = 0; k < pB->
Cols(); ++k)
3201 M(i, k) += pA->
get(i, j) * pB->
get(j, k);
3204 MatrixMul(
const MatrixMul& b) : M(b.M) {}
3210 __INLINE VarR
compute(enumerator i, enumerator j)
const {
return M.
get(i, j); }
3215 __INLINE VarR&
operator()(enumerator i, enumerator j) {
return M(i, j); }
3221 __INLINE
const VarR&
get(enumerator i, enumerator j)
const {
return M.
get(i, j); }
3224 #if defined(USE_AUTODIFF)
3237 void Resize(enumerator rows, enumerator cols)
3239 assert(
Cols() == cols);
3240 assert(
Rows() == rows);
3241 (void)cols; (void)rows;
3262 static thread_private< Matrix<variable> > tmpB;
3268 if (cnt >= CNT_USE_MERGER)
3270 merger->Resize(cnt);
3271 for (enumerator i = 0; i < pA->
Rows(); ++i)
3273 for (enumerator j = 0; j < pB->
Cols(); ++j)
3275 INMOST_DATA_REAL_TYPE value = 0.0;
3276 for (enumerator k = 0; k < pA->
Cols(); ++k)
3278 value += pA->
get(i, k) * pB->
get(k, j).GetValue();
3279 merger->AddRow(pA->
get(i, k), pB->
get(k, j).GetRow());
3281 M(i, j).SetValue(value);
3282 merger->RetrieveRow(M(i, j).GetRow());
3289 for (enumerator i = 0; i < pA->
Rows(); ++i)
3291 for (enumerator k = 0; k < pB->
Cols(); ++k)
3292 M(i, k) = pA->
get(i, 0) * pB->
get(0, k);
3293 for (enumerator j = 1; j < pA->
Cols(); ++j)
3294 for (enumerator k = 0; k < pB->
Cols(); ++k)
3295 M(i, k) += pA->
get(i, j) * pB->
get(j, k);
3299 MatrixMul(
const MatrixMul& b) : M(b.M) {}
3307 __INLINE
const variable&
get(enumerator i, enumerator j)
const {
return M.
get(i, j); }
3323 void Resize(enumerator rows, enumerator cols)
3325 assert(
Cols() == cols);
3326 assert(
Rows() == rows);
3327 (void)cols; (void)rows;
3348 static thread_private< Matrix<INMOST_DATA_REAL_TYPE> > tmpB;
3354 if (cnt >= CNT_USE_MERGER)
3356 merger->Resize(cnt);
3357 for (enumerator i = 0; i < pA->
Rows(); ++i)
3359 for (enumerator j = 0; j < pB->
Cols(); ++j)
3361 INMOST_DATA_REAL_TYPE value = 0.0;
3362 for (enumerator k = 0; k < pA->
Cols(); ++k)
3364 value += pA->
get(i, k).GetValue() * pB->
get(k, j);
3365 merger->AddRow(pB->
get(k, j), pA->
get(i, k).GetRow());
3367 M(i, j).SetValue(value);
3368 merger->RetrieveRow(M(i, j).GetRow());
3375 for (enumerator i = 0; i < pA->
Rows(); ++i)
3377 for (enumerator k = 0; k < pB->
Cols(); ++k)
3378 M(i, k) = pA->
get(i, 0) * pB->
get(0, k);
3379 for (enumerator j = 1; j < pA->
Cols(); ++j)
3380 for (enumerator k = 0; k < pB->
Cols(); ++k)
3381 M(i, k) += pA->
get(i, j) * pB->
get(j, k);
3385 MatrixMul(
const MatrixMul& b) : M(b.M) {}
3393 __INLINE
const variable&
get(enumerator i, enumerator j)
const {
return M.
get(i, j); }
3409 void Resize(enumerator rows, enumerator cols)
3411 assert(
Cols() == cols);
3412 assert(
Rows() == rows);
3413 (void)cols; (void)rows;
3434 static thread_private< Matrix<variable> > tmpB;
3439 INMOST_DATA_ENUM_TYPE cnt = 0;
3442 if (cnt >= CNT_USE_MERGER)
3444 merger->Resize(cnt);
3445 for (enumerator i = 0; i < pA->
Rows(); ++i)
3447 for (enumerator j = 0; j < pB->
Cols(); ++j)
3449 INMOST_DATA_REAL_TYPE value = 0.0;
3450 for (enumerator k = 0; k < pA->
Cols(); ++k)
3452 value += pA->
get(i, k).GetValue() * pB->
get(k, j).GetValue();
3453 merger->AddRow(pA->
get(i, k).GetValue(), pB->
get(k, j).GetRow());
3454 merger->AddRow(pB->
get(k, j).GetValue(), pA->
get(i, k).GetRow());
3456 M(i, j).SetValue(value);
3457 merger->RetrieveRow(M(i, j).GetRow());
3464 for (enumerator i = 0; i < pA->
Rows(); ++i)
3466 for (enumerator k = 0; k < pB->
Cols(); ++k)
3467 M(i, k) = pA->
get(i, 0) * pB->
get(0, k);
3468 for (enumerator j = 1; j < pA->
Cols(); ++j)
3469 for (enumerator k = 0; k < pB->
Cols(); ++k)
3470 M(i, k) += pA->
get(i, j) * pB->
get(j, k);
3474 MatrixMul(
const MatrixMul& b) : M(b.M) {}
3482 __INLINE
const variable&
get(enumerator i, enumerator j)
const {
return M.
get(i, j); }
3489 template<
typename VarA,
typename VarB,
typename VarR>
3510 : A(&rA), coef(&rcoef) {}
3511 MatrixMulCoef(
const MatrixMulCoef& b) : A(b.A), coef(b.coef) {}
3517 __INLINE VarR
compute(enumerator i, enumerator j)
const {
return A->
compute(i, j) * (*coef); }
3523 template<
typename VarA,
typename VarB,
typename VarR>
3544 : A(&rA), coef(&rcoef) {}
3545 MatrixDivCoef(
const MatrixDivCoef& b)
3546 : A(b.A), coef(b.coef) {}
3552 __INLINE VarR
compute(enumerator i, enumerator j)
const {
return A->
compute(i, j) / (*coef); }
3557 #if defined(USE_AUTODIFF)
3558 template<
typename VarA,
typename VarB,
typename VarR>
3579 : A(&rA), coef(rcoef) {}
3580 MatrixMulShellCoef(
const MatrixMulShellCoef& b) : A(b.A), coef(b.coef) {}
3586 __INLINE VarR
compute(enumerator i, enumerator j)
const {
return A->
compute(i, j) * coef; }
3592 template<
typename VarA,
typename VarB,
typename VarR>
3613 : A(&rA), coef(rcoef) {}
3614 MatrixDivShellCoef(
const MatrixDivShellCoef& b)
3615 : A(b.A), coef(b.coef) {}
3621 __INLINE VarR
compute(enumerator i, enumerator j)
const {
return (A->
compute(i, j) / coef); }
3627 template<
typename VarA,
typename VarB>
3649 KroneckerProduct(
const KroneckerProduct& b) : A(b.A), B(b.B) {}
3664 template<
typename Var>
3673 template<
typename Var>
3674 template<
typename typeB>
3679 assert(A.
Rows() == 3);
3680 assert(A.
Cols() == 1);
3681 assert(B.
Rows() == 3);
3683 for(
unsigned k = 0; k < B.
Cols(); ++k)
3693 template<
typename Var>
3694 template<
typename typeB>
3699 assert(A.
Rows() == 3);
3700 assert(A.
Cols() == 1);
3701 assert(B.
Rows() == 3);
3703 for (
unsigned k = 0; k < B.
Cols(); ++k)
3705 ret(0, k) = (A.
get(1, 0) * B.
get(2, k) - A.
get(2, 0) * B.
get(1, k));
3706 ret(1, k) = (A.
get(2, 0) * B.
get(0, k) - A.
get(0, 0) * B.
get(2, k));
3707 ret(2, k) = (A.
get(0, 0) * B.
get(1, k) - A.
get(1, 0) * B.
get(0, k));
3712 template<
typename Var>
3713 template<
typename typeB>
3718 assert(A.
Rows() == 3);
3719 assert(A.
Cols() == 1);
3720 assert(B.
Rows() == 3);
3722 for (
unsigned k = 0; k < B.
Cols(); ++k)
3732 template<
typename Var>
3733 template<
typename typeB>
3738 assert(A.
Rows() == 3);
3739 assert(A.
Cols() == 1);
3740 assert(B.
Rows() == 3);
3741 assert(B.
Cols() == 1);
3752 n = 2*l/(x*x+y*y+z*z+w*w);
3754 Q(0,0) = l - (y*y + z*z)*n;
3755 Q(0,1) = (x*y - z*w)*n;
3756 Q(0,2) = (x*z + y*w)*n;
3758 Q(1,0) = (x*y + z*w)*n;
3759 Q(1,1) = l - (x*x + z*z)*n;
3760 Q(1,2) = (y*z - x*w)*n;
3762 Q(2,0) = (x*z - y*w)*n;
3763 Q(2,1) = (y*z + x*w)*n;
3764 Q(2,2) = l - (x*x + y*y)*n;
3771 template<
typename Var>
3772 template<
typename typeB>
3777 assert(A.
Rows() == 3);
3778 assert(A.
Cols() == 1);
3779 assert(B.
Rows() == 3);
3780 assert(B.
Cols() == 1);
3783 var_t x, y, z, w, n, l;
3785 x = -(B.
get(1, 0) * A.
get(2, 0) - B.
get(2, 0) * A.
get(1, 0));
3786 y = -(B.
get(2, 0) * A.
get(0, 0) - B.
get(0, 0) * A.
get(2, 0));
3787 z = -(B.
get(0, 0) * A.
get(1, 0) - B.
get(1, 0) * A.
get(0, 0));
3791 n = 2 * l / (x * x + y * y + z * z + w * w);
3793 Q(0, 0) = l - (y * y + z * z) * n;
3794 Q(0, 1) = (x * y - z * w) * n;
3795 Q(0, 2) = (x * z + y * w) * n;
3797 Q(1, 0) = (x * y + z * w) * n;
3798 Q(1, 1) = l - (x * x + z * z) * n;
3799 Q(1, 2) = (y * z - x * w) * n;
3801 Q(2, 0) = (x * z - y * w) * n;
3802 Q(2, 1) = (y * z + x * w) * n;
3803 Q(2, 2) = l - (x * x + y * y) * n;
3809 template<
typename Var>
3810 template<
typename typeB>
3815 assert(A.
Rows() == 3);
3816 assert(A.
Cols() == 1);
3817 assert(B.
Rows() == 3);
3818 assert(B.
Cols() == 1);
3821 var_t x, y, z, w, n, l;
3829 n = 2 * l / (x * x + y * y + z * z + w * w);
3831 Q(0, 0) = l - (y * y + z * z) * n;
3832 Q(0, 1) = (x * y - z * w) * n;
3833 Q(0, 2) = (x * z + y * w) * n;
3835 Q(1, 0) = (x * y + z * w) * n;
3836 Q(1, 1) = l - (x * x + z * z) * n;
3837 Q(1, 2) = (y * z - x * w) * n;
3839 Q(2, 0) = (x * z - y * w) * n;
3840 Q(2, 1) = (y * z + x * w) * n;
3841 Q(2, 2) = l - (x * x + y * y) * n;
3846 template<
typename Var>
3847 template<
typename typeB>
3854 template<
typename Var>
3855 template<
typename typeB>
3859 assert(Rows() == other.
Rows());
3860 assert(Cols() == other.
Cols());
3861 for (enumerator i = 0; i < Rows(); ++i)
3862 for (enumerator j = 0; j < Cols(); ++j)
3863 assign((*
this)(i, j), (*
this)(i, j) - other.
get(i, j));
3867 template<
typename Var>
3868 template<
typename typeB>
3869 AbstractMatrix<Var> &
3872 assert(Rows() == other.Rows());
3873 assert(Cols() == other.Cols());
3874 for(enumerator i = 0; i < Rows(); ++i)
3875 for(enumerator j = 0; j < Cols(); ++j)
3876 assign((*
this)(i,j),(*
this)(i,j)-other.compute(i,j));
3880 template<
typename Var>
3881 template<
typename typeB>
3882 MatrixSum<Var,typeB>
3888 template<
typename Var>
3889 template<
typename typeB>
3893 assert(Rows() == other.
Rows());
3894 assert(Cols() == other.
Cols());
3895 for (enumerator i = 0; i < Rows(); ++i)
3896 for (enumerator j = 0; j < Cols(); ++j)
3897 assign((*
this)(i, j), (*
this)(i, j) + other.
get(i, j));
3901 template<
typename Var>
3902 template<
typename typeB>
3903 AbstractMatrix<Var> &
3906 assert(Rows() == other.Rows());
3907 assert(Cols() == other.Cols());
3908 for(enumerator i = 0; i < Rows(); ++i)
3909 for(enumerator j = 0; j < Cols(); ++j)
3910 assign((*
this)(i,j),(*
this)(i,j)+other.compute(i,j));
3914 template<
typename Var>
3915 template<
typename typeB>
3916 MatrixMul<Var, typeB, typename Promote<Var, typeB>::type>
3922 #if defined(USE_AUTODIFF)
3928 assert(Cols() == other.
Cols());
3929 assert(Rows() == other.
Rows());
3949 for(enumerator i = 0; i < Rows(); ++i)
3950 for(enumerator j = 0; j < Cols(); ++j)
3951 ret += compute(i, j) * other.
compute(i, j);
3958 __INLINE Promote<variable,INMOST_DATA_REAL_TYPE>::type
3959 AbstractMatrixReadOnly<variable>::DotProduct<INMOST_DATA_REAL_TYPE>(
const AbstractMatrixReadOnly<INMOST_DATA_REAL_TYPE> & other)
const
3961 assert(Cols() == other.Cols());
3962 assert(Rows() == other.Rows());
3963 Promote<variable,INMOST_DATA_REAL_TYPE>::type ret = 0.0;
3982 for(enumerator i = 0; i < Rows(); ++i)
3983 for(enumerator j = 0; j < Cols(); ++j)
3984 ret += compute(i,j)*other.compute(i,j);
3991 __INLINE Promote<variable,variable>::type
3992 AbstractMatrixReadOnly<variable>::DotProduct<variable>(
const AbstractMatrixReadOnly<variable> & other)
const
3994 assert(Cols() == other.Cols());
3995 assert(Rows() == other.Rows());
3996 Promote<variable,variable>::type ret = 0.0;
4016 for(enumerator i = 0; i < Rows(); ++i)
4017 for(enumerator j = 0; j < Cols(); ++j)
4018 ret += compute(i,j)*other.compute(i,j);
4024 template<
typename Var>
4025 template<
typename typeB>
4026 AbstractMatrix<Var> &
4029 (*this) = (*this)*B;
4033 template<
typename Var>
4034 template<
typename typeB>
4035 MatrixMulCoef<Var, typeB, typename Promote<Var, typeB>::type>
4041 #if defined(USE_AUTODIFF)
4042 template<
typename Var>
4043 template<
typename A>
4051 template<
typename Var>
4052 template<
typename typeB>
4056 for(enumerator i = 0; i < Rows(); ++i)
4057 for(enumerator j = 0; j < Cols(); ++j)
4058 assign((*
this)(i,j),(*
this)(i,j)*coef);
4061 #if defined(USE_AUTODIFF)
4062 template<
typename Var>
4063 template<
typename A>
4064 MatrixDivShellCoef<Var, shell_expression<A>,
typename Promote<Var, variable>::type>
4071 template<
typename Var>
4072 template<
typename typeB>
4079 template<
typename Var>
4080 template<
typename typeB>
4084 for(enumerator i = 0; i < Rows(); ++i)
4085 for(enumerator j = 0; j < Cols(); ++j)
4086 assign((*
this)(i,j),(*
this)(i,j)/coef);
4090 template<
typename Var>
4091 template<
typename typeB>
4092 KroneckerProduct<Var,typeB>
4098 template<
typename Var>
4107 template<
typename Var>
4117 template<
typename Var>
4118 template<
typename typeB>
4125 enumerator n = A.
Rows();
4126 enumerator l = B.
Cols();
4159 for(enumerator k = 0; k < n; ++k)
4161 if( real_part((*L)(k,k)) < 0.0 )
4165 if( *ierr == -1 ) std::cout <<
"Negative diagonal pivot " << get_value((*L)(k,k)) <<
" row " << k << std::endl;
4168 else throw MatrixCholeskySolveFail;
4172 (*L)(k,k) = sqrt((*L)(k,k));
4174 if( fabs((*L)(k,k)) < 1.0e-24 )
4178 if( *ierr == -1 ) std::cout <<
"Diagonal pivot is too small " << get_value((*L)(k,k)) <<
" row " << k << std::endl;
4181 else throw MatrixCholeskySolveFail;
4185 for(enumerator i = k+1; i < n; ++i)
4186 (*L)(i,k) /= (*L)(k,k);
4188 for(enumerator j = k+1; j < n; ++j)
4190 for(enumerator i = j; i < n; ++i)
4191 (*L)(i,j) -= (*L)(i,k)*(*L)(j,k);
4196 for(enumerator i = 0; i < n; ++i)
4198 for(enumerator k = 0; k < l; ++k)
4200 for(enumerator j = 0; j < i; ++j)
4201 Y(i,k) -= Y(j,k)*(*L)(j,i);
4202 Y(i,k) /= (*L)(i,i);
4207 for(enumerator it = n; it > 0; --it)
4209 enumerator i = it-1;
4210 for(enumerator k = 0; k < l; ++k)
4212 for(enumerator jt = n; jt > it; --jt)
4214 enumerator j = jt-1;
4215 X(i,k) -= X(j,k)*(*L)(i,j);
4217 X(i,k) /= (*L)(i,i);
4220 if( ierr ) *ierr = 0;
4223 #if defined(USE_AUTODIFF)
4232 enumerator n = A.
Rows();
4233 enumerator l = B.
Cols();
4236 INMOST_DATA_ENUM_TYPE cnt = 0;
4240 if (cnt >= CNT_USE_MERGER)
4243 pmerger = &(*merger);
4246 for(enumerator k = 0; k < n; ++k)
4248 if( L(k,k).GetValue() < 0.0 )
4252 if( *ierr == -1 ) std::cout <<
"Negative diagonal pivot " << get_value(L(k,k)) <<
" row " << k << std::endl;
4255 else throw MatrixCholeskySolveFail;
4259 L(k,k) = sqrt(L(k,k));
4261 if( fabs(L(k,k).GetValue()) < 1.0e-24 )
4265 if( *ierr == -1 ) std::cout <<
"Diagonal pivot is too small " << get_value(L(k,k)) <<
" row " << k << std::endl;
4268 else throw MatrixCholeskySolveFail;
4272 for(enumerator i = k+1; i < n; ++i)
4275 for(enumerator j = k+1; j < n; ++j)
4277 for(enumerator i = j; i < n; ++i)
4278 L(i,j) -= L(i,k)*L(j,k);
4282 Matrix<Promote<variable,variable>::type> & Y = ret;
4283 for(enumerator i = 0; i < n; ++i)
4285 for(enumerator k = 0; k < l; ++k)
4289 INMOST_DATA_REAL_TYPE value = Y(i,k).GetValue();
4290 pmerger->
PushRow(1.0,Y(i,k).GetRow());
4291 for(enumerator j = 0; j < i; ++j)
4293 value -= Y(j,k).GetValue()*L(j,i).GetValue();
4294 pmerger->
AddRow(-Y(j,k).GetValue(),L(j,i).GetRow());
4295 pmerger->
AddRow(-L(j,i).GetValue(),Y(j,k).GetRow());
4297 Y(i,k).SetValue(value);
4303 for(enumerator j = 0; j < i; ++j)
4304 Y(i,k) -= Y(j,k)*L(j,i);
4310 Matrix<Promote<variable,variable>::type> & X = ret;
4311 for(enumerator it = n; it > 0; --it)
4313 enumerator i = it-1;
4314 for(enumerator k = 0; k < l; ++k)
4318 double value = X(i,k).GetValue();
4319 pmerger->
PushRow(1.0,X(i,k).GetRow());
4320 for(enumerator jt = n; jt > it; --jt)
4322 enumerator j = jt-1;
4323 value -= X(j,k).GetValue()*L(i,j).GetValue();
4324 pmerger->
AddRow(-X(j,k).GetValue(),L(i,j).GetRow());
4325 pmerger->
AddRow(-L(i,j).GetValue(),X(j,k).GetRow());
4327 X(i,k).SetValue(value);
4333 for(enumerator jt = n; jt > it; --jt)
4335 enumerator j = jt-1;
4336 X(i,k) -= X(j,k)*L(i,j);
4342 if( ierr ) *ierr = 0;
4349 __INLINE Matrix<Promote<INMOST_DATA_REAL_TYPE,variable>::type>
4352 const AbstractMatrixReadOnly<INMOST_DATA_REAL_TYPE> & A = *
this;
4353 assert(A.Rows() == A.Cols());
4354 assert(A.Rows() == B.Rows());
4355 enumerator n = A.Rows();
4356 enumerator l = B.Cols();
4357 Matrix<Promote<INMOST_DATA_REAL_TYPE,variable>::type> ret(B);
4358 SymmetricMatrix<INMOST_DATA_REAL_TYPE> L(A);
4359 INMOST_DATA_ENUM_TYPE cnt = B.GetMatrixCount();
4360 Sparse::RowMerger* pmerger = NULL;
4361 if (cnt >= CNT_USE_MERGER)
4364 pmerger = &(*merger);
4367 for(enumerator k = 0; k < n; ++k)
4373 if( *ierr == -1 ) std::cout <<
"Negative diagonal pivot " << get_value(L(k,k)) <<
" row " << k << std::endl;
4376 else throw MatrixCholeskySolveFail;
4380 L(k,k) = sqrt(L(k,k));
4382 if( fabs(L(k,k)) < 1.0e-24 )
4386 if( *ierr == -1 ) std::cout <<
"Diagonal pivot is too small " << get_value(L(k,k)) <<
" row " << k << std::endl;
4389 else throw MatrixCholeskySolveFail;
4393 for(enumerator i = k+1; i < n; ++i)
4396 for(enumerator j = k+1; j < n; ++j)
4398 for(enumerator i = j; i < n; ++i)
4399 L(i,j) -= L(i,k)*L(j,k);
4403 Matrix<Promote<variable,variable>::type> & Y = ret;
4404 for(enumerator i = 0; i < n; ++i)
4406 for(enumerator k = 0; k < l; ++k)
4410 double value = Y(i,k).GetValue();
4411 pmerger->PushRow(1.0,Y(i,k).GetRow());
4412 for(enumerator j = 0; j < i; ++j)
4414 value -= Y(j,k).GetValue()*L(j,i);
4415 pmerger->AddRow(-L(j,i),Y(j,k).GetRow());
4417 Y(i,k).SetValue(value);
4418 pmerger->RetrieveRow(Y(i,k).GetRow());
4423 for(enumerator j = 0; j < i; ++j)
4424 Y(i,k) -= Y(j,k)*L(j,i);
4430 Matrix<Promote<variable,variable>::type> & X = ret;
4431 for(enumerator it = n; it > 0; --it)
4433 enumerator i = it-1;
4434 for(enumerator k = 0; k < l; ++k)
4438 double value = X(i,k).GetValue();
4439 pmerger->PushRow(1.0,X(i,k).GetRow());
4440 for(enumerator jt = n; jt > it; --jt)
4442 enumerator j = jt-1;
4443 value -= X(j,k).GetValue()*L(i,j);
4444 pmerger->AddRow(-L(i,j),X(j,k).GetRow());
4446 X(i,k).SetValue(value);
4447 pmerger->RetrieveRow(X(i,k).GetRow());
4452 for(enumerator jt = n; jt > it; --jt)
4454 enumerator j = jt-1;
4455 X(i,k) -= X(j,k)*L(i,j);
4461 if( ierr ) *ierr = 0;
4467 __INLINE Matrix<Promote<variable,INMOST_DATA_REAL_TYPE>::type>
4470 const AbstractMatrixReadOnly<variable> & A = *
this;
4471 assert(A.Rows() == A.Cols());
4472 assert(A.Rows() == B.Rows());
4473 enumerator n = A.Rows();
4474 enumerator l = B.Cols();
4475 Matrix<Promote<variable,INMOST_DATA_REAL_TYPE>::type> ret(B);
4476 SymmetricMatrix<variable> L(A);
4477 INMOST_DATA_ENUM_TYPE cnt = A.GetMatrixCount();
4478 Sparse::RowMerger* pmerger = NULL;
4479 if (cnt >= CNT_USE_MERGER)
4481 merger->Resize(cnt);
4482 pmerger = &(*merger);
4485 for(enumerator k = 0; k < n; ++k)
4487 if( L(k,k).GetValue() < 0.0 )
4491 if( *ierr == -1 ) std::cout <<
"Negative diagonal pivot " << get_value(L(k,k)) <<
" row " << k << std::endl;
4494 else throw MatrixCholeskySolveFail;
4498 L(k,k) = sqrt(L(k,k));
4500 if( fabs(L(k,k).GetValue()) < 1.0e-24 )
4504 if( *ierr == -1 ) std::cout <<
"Diagonal pivot is too small " << get_value(L(k,k)) <<
" row " << k << std::endl;
4507 else throw MatrixCholeskySolveFail;
4511 for(enumerator i = k+1; i < n; ++i)
4514 for(enumerator j = k+1; j < n; ++j)
4516 for(enumerator i = j; i < n; ++i)
4517 L(i,j) -= L(i,k)*L(j,k);
4521 Matrix<Promote<variable,INMOST_DATA_REAL_TYPE>::type> & Y = ret;
4522 for(enumerator i = 0; i < n; ++i)
4524 for(enumerator k = 0; k < l; ++k)
4528 double value = Y(i,k).GetValue();
4529 pmerger->PushRow(1.0,Y(i,k).GetRow());
4530 for(enumerator j = 0; j < i; ++j)
4532 value -= Y(j,k).GetValue()*L(j,i).GetValue();
4533 pmerger->AddRow(-Y(j,k).GetValue(),L(j,i).GetRow());
4534 pmerger->AddRow(-L(j,i).GetValue(),Y(j,k).GetRow());
4536 Y(i,k).SetValue(value);
4537 pmerger->RetrieveRow(Y(i,k).GetRow());
4542 for(enumerator j = 0; j < i; ++j)
4543 Y(i,k) -= Y(j,k)*L(j,i);
4549 Matrix<Promote<variable,INMOST_DATA_REAL_TYPE>::type> & X = ret;
4550 for(enumerator it = n; it > 0; --it)
4552 enumerator i = it-1;
4553 for(enumerator k = 0; k < l; ++k)
4557 double value = X(i,k).GetValue();
4558 pmerger->PushRow(1.0,X(i,k).GetRow());
4559 for(enumerator jt = n; jt > it; --jt)
4561 enumerator j = jt-1;
4562 value -= X(j,k).GetValue()*L(i,j).GetValue();
4563 pmerger->AddRow(-X(j,k).GetValue(),L(i,j).GetRow());
4564 pmerger->AddRow(-L(i,j).GetValue(),X(j,k).GetRow());
4566 X(i,k).SetValue(value);
4567 pmerger->RetrieveRow(X(i,k).GetRow());
4572 for(enumerator jt = n; jt > it; --jt)
4574 enumerator j = jt-1;
4575 X(i,k) -= X(j,k)*L(i,j);
4581 if( ierr ) *ierr = 0;
4585 template<
typename Var>
4586 template<
typename typeB>
4587 Matrix<typename Promote<Var,typeB>::type>
4591 assert(Rows() == B.
Rows());
4593 if( Rows() != Cols() )
4596 return (At * (*
this)).Solve(At * B, ierr);
4600 enumerator l = B.
Cols();
4601 enumerator m = Cols();
4606 assert(l == AtB.
Cols());
4610 std::vector<enumerator> order(m);
4613 INMOST_DATA_REAL_TYPE max,v;
4615 for(enumerator i = 0; i < m; ++i) order[i] = i;
4616 for(enumerator i = 0; i < m; i++)
4618 enumerator maxk = i, maxq = i, temp2;
4619 max = fabs(get_value(AtA(maxk,maxq)));
4623 for(enumerator k = i; k < m; k++)
4625 for(enumerator q = i; q < m; q++)
4627 v = fabs(get_value(AtA(k,q)));
4639 for(enumerator q = 0; q < m; q++)
4643 AtA(maxk,q) = AtA(i,q);
4647 for(enumerator q = 0; q < l; q++)
4650 tempb = AtB(maxk,q);
4651 AtB(maxk,q) = AtB(i,q);
4658 for(enumerator k = 0; k < m; k++)
4662 AtA(k,maxq) = AtA(k,i);
4668 temp2 = order[maxq];
4669 order[maxq] = order[i];
4675 if( fabs(get_value(AtA(i,i))) < 1.0e-54 )
4678 for(enumerator k = 0; k < l; k++)
4680 if( fabs(get_value(AtB(i,k))/1.0e-54) > 1 )
4686 if( ok ) AtA(i,i) = real_part(AtA(i,i)) < 0.0 ? - 1.0e-12 : 1.0e-12;
4693 std::cout <<
"Failed to invert matrix diag " << get_value(AtA(i,i)) << std::endl;
4694 std::cout <<
"rhs:";
4695 for(enumerator k = 0; k < l; k++)
4696 std::cout <<
" " << get_value(AtB(i,k));
4697 std::cout << std::endl;
4701 else throw MatrixSolveFail;
4706 for(enumerator k = i+1; k < m; k++)
4708 AtA(i,k) /= AtA(i,i);
4709 AtA(k,i) /= AtA(i,i);
4712 for(enumerator k = i+1; k < m; k++)
4713 for(enumerator q = i+1; q < m; q++)
4715 AtA(k,q) -= AtA(k,i) * AtA(i,i) * AtA(i,q);
4718 for(enumerator k = 0; k < l; k++)
4720 for(enumerator j = i+1; j < m; j++)
4722 AtB(j,k) -= AtB(i,k) * AtA(j,i);
4724 AtB(i,k) /= AtA(i,i);
4728 for(enumerator k = 0; k < l; k++)
4730 for(enumerator i = m; i-- > 0; )
4731 for(enumerator j = i+1; j < m; j++)
4733 AtB(i,k) -= AtB(j,k) * AtA(i,j);
4735 for(enumerator i = 0; i < m; i++)
4736 ret(order[i],k) = AtB(i,k);
4739 if( ierr ) *ierr = 0;
4743 template<
typename Var>
4747 assert(ibeg < Rows());
4748 assert(iend < Rows());
4749 assert(jbeg < Cols());
4750 assert(jend < Cols());
4752 for(enumerator i = ibeg; i < iend; ++i)
4754 for(enumerator j = jbeg; j < jend; ++j)
4755 ret(i-ibeg,j-jbeg) = (*this)(i,j);
4760 template<
typename Var>
4766 bool success = SVD(U,S,V);
4771 if( *ierr == -1 ) std::cout <<
"Failed to compute Moore-Penrose inverse of the matrix" << std::endl;
4775 else throw MatrixPseudoSolveFail;
4777 for(INMOST_DATA_ENUM_TYPE k = 0; k < S.
Cols(); ++k)
4779 if (get_value(fabs(S(k, k))) > tol)
4780 S(k, k) = 1.0 / S(k, k);
4786 if( ierr ) *ierr = 0;
4790 template<
typename Var>
4794 assert(Rows() == Cols());
4800 for(k = 0; k < Cols(); ++k) ret(k,k) = ret0(k,k) = 1;
4804 ret = 0.5*(ret + (*this)*ret.
Invert());
4805 if( (ret - ret0).FrobeniusNorm() < tol )
return ret;
4809 if( *ierr == -1 ) std::cout <<
"Failed to find square root of matrix by Babylonian method" << std::endl;
4815 template<
typename Var>
4821 bool success = SVD(U,S,V);
4827 std::cout <<
"Failed to compute singular value decomposition of the matrix" << std::endl;
4831 else throw MatrixPseudoSolveFail;
4833 for(INMOST_DATA_ENUM_TYPE k = 0; k < S.
Cols(); ++k)
4834 if( get_value(S(k,k)) ) S(k,k) = pow(S(k,k),n);
4839 if( ierr ) *ierr = 0;
4842 template<
typename Var>
4843 template<
typename typeB>
4849 bool success = SVD(U,S,V);
4854 if( *ierr == -1 ) std::cout <<
"Failed to compute Moore-Penrose inverse of the matrix" << std::endl;
4857 else throw MatrixPseudoSolveFail;
4859 for(
int k = 0; k < (int)S.
Cols(); ++k)
4862 S(k,k) = 1.0/S(k,k);
4867 if( ierr ) *ierr = 0;
4871 template<
typename Var>
4874 return SubMatrix<Var>(*
this,first_row,last_row,first_col,last_col);
4876 template<
typename Var>
4882 template<
typename Var>
4887 template<
typename Var>
4898 __INLINE
static bool compare(INMOST_DATA_REAL_TYPE * a, INMOST_DATA_REAL_TYPE * b)
4906 INMOST_DATA_ENUM_TYPE size_max, size;
4907 std::vector<INMOST_DATA_ENUM_TYPE> heap;
4908 std::vector<INMOST_DATA_ENUM_TYPE> index;
4909 INMOST_DATA_REAL_TYPE * keys;
4911 void swap(INMOST_DATA_ENUM_TYPE i, INMOST_DATA_ENUM_TYPE j)
4913 INMOST_DATA_ENUM_TYPE t = heap[i];
4919 void bubbleUp(INMOST_DATA_ENUM_TYPE k)
4921 while(k > 1 && keys[heap[k/2]] > keys[heap[k]])
4927 void bubbleDown(INMOST_DATA_ENUM_TYPE k)
4932 j = 2*
static_cast<size_t>(k);
4933 if(j < size && keys[heap[j]] > keys[heap[j+1]])
4935 if(keys[heap[k]] <= keys[heap[j]])
4937 swap(k,
static_cast<INMOST_DATA_ENUM_TYPE
>(j));
4938 k =
static_cast<INMOST_DATA_ENUM_TYPE
>(j);
4942 BinaryHeapDense(INMOST_DATA_REAL_TYPE * pkeys, INMOST_DATA_ENUM_TYPE len)
4947 heap.resize(
static_cast<size_t>(size_max)+1);
4948 index.resize(
static_cast<size_t>(size_max)+1);
4949 for(INMOST_DATA_ENUM_TYPE i = 0; i <= size_max; i++)
4950 index[i] = ENUMUNDEF;
4952 void PushHeap(INMOST_DATA_ENUM_TYPE i, INMOST_DATA_REAL_TYPE key)
4960 INMOST_DATA_ENUM_TYPE PopHeap()
4962 if( size == 0 )
return ENUMUNDEF;
4963 INMOST_DATA_ENUM_TYPE min = heap[1];
4966 index[min] = ENUMUNDEF;
4967 heap[
static_cast<size_t>(size)+1] = ENUMUNDEF;
4970 void DecreaseKey(INMOST_DATA_ENUM_TYPE i, INMOST_DATA_REAL_TYPE key)
4977 while( size ) keys[PopHeap()] = std::numeric_limits<INMOST_DATA_REAL_TYPE>::max();
4979 bool Contains(INMOST_DATA_ENUM_TYPE i)
4981 return index[i] != ENUMUNDEF;
4985 template<
typename Var>
4988 const INMOST_DATA_ENUM_TYPE EOL = ENUMUNDEF-1;
4991 INMOST_DATA_REAL_TYPE u, l;
4992 std::vector<INMOST_DATA_REAL_TYPE> Cmax(m,0.0);
4993 std::vector<INMOST_DATA_REAL_TYPE> U(m,std::numeric_limits<INMOST_DATA_REAL_TYPE>::max());
4994 std::vector<INMOST_DATA_REAL_TYPE> V(n,std::numeric_limits<INMOST_DATA_REAL_TYPE>::max());
4995 std::fill(Perm,Perm+m,ENUMUNDEF);
4996 std::vector<INMOST_DATA_ENUM_TYPE> IPerm(std::max(n,m),ENUMUNDEF);
4997 std::vector<INMOST_DATA_ENUM_TYPE> ColumnList(m,ENUMUNDEF);
4998 std::vector<INMOST_DATA_ENUM_TYPE> ColumnPosition(n,ENUMUNDEF);
4999 std::vector<INMOST_DATA_ENUM_TYPE> Parent(n,ENUMUNDEF);
5000 std::vector<INMOST_DATA_REAL_TYPE> Dist(m,std::numeric_limits<INMOST_DATA_REAL_TYPE>::max());
5003 INMOST_DATA_ENUM_TYPE Li, Ui;
5004 INMOST_DATA_ENUM_TYPE ColumnBegin, PathEnd, Trace, IPermPrev;
5005 INMOST_DATA_REAL_TYPE ShortestPath, AugmentPath;
5008 for(
int k = 0; k < n; ++k)
5010 for(
int i = 0; i < m; ++i)
5012 C(k,i) = fabs(get_value(A(k,i)));
5013 if( Cmax[i] < C(k,i) ) Cmax[i] = C(k,i);
5016 for(
int k = 0; k < n; ++k)
5018 for (
int i = 0; i < m; ++i)
5020 if( Cmax[i] == 0 || C(k,i) == 0 )
5021 C(k,i) = std::numeric_limits<INMOST_DATA_REAL_TYPE>::max();
5024 C(k,i) = log(Cmax[i])-log(C(k,i));
5025 if( C(k,i) < U[i] ) U[i] = C(k,i);
5029 for(
int k = 0; k < n; ++k)
5031 for (
int i = 0; i < m; ++i)
5034 if( u < V[k] ) V[k] = u;
5038 for(
int k = 0; k < n; ++k)
5040 for (
int i = 0; i < m; ++i)
5042 u = fabs(C(k,i) - V[k] - U[i]);
5043 if( u < 1.0e-30 && Perm[i] == ENUMUNDEF && IPerm[k] == ENUMUNDEF )
5047 ColumnPosition[k] = i;
5052 for(
int k = 0; k < n; ++k)
5054 if( IPerm[k] == ENUMUNDEF )
5056 for (
int i = 0; i < m && IPerm[k] == ENUMUNDEF; ++i)
5058 u = fabs(C(k,i) - V[k] - U[i]);
5062 assert(Li != ENUMUNDEF);
5064 for (
int Lit = 0; Lit < m; ++Lit)
5066 u = fabs(C(Li,Lit) - V[Li] - U[Lit]);
5067 if( u <= 1.0e-30 && Perm[Lit] == ENUMUNDEF )
5071 ColumnPosition[k] = i;
5074 ColumnPosition[Li] = Lit;
5083 for(
int k = 0; k < n; ++k)
5085 if( IPerm[k] != ENUMUNDEF )
5089 Parent[Li] = ENUMUNDEF;
5090 PathEnd = ENUMUNDEF;
5093 AugmentPath = std::numeric_limits<INMOST_DATA_REAL_TYPE>::max();
5096 for (
int Lit = 0; Lit < m; ++Lit)
5098 if( ColumnList[Lit] != ENUMUNDEF )
continue;
5099 l = ShortestPath + C(Li,Lit) - V[Li] - U[Lit];
5100 if( l < 0.0 && fabs(l) < 1.0e-12 ) l = 0;
5101 if( l < AugmentPath )
5103 if( Perm[Lit] == ENUMUNDEF )
5109 else if( l < Dist[Lit] )
5111 Parent[Perm[Lit]] = Li;
5112 if( Heap.Contains(Lit) )
5113 Heap.DecreaseKey(Lit,l);
5115 Heap.PushHeap(Lit,l);
5120 INMOST_DATA_ENUM_TYPE pop_heap_pos = Heap.PopHeap();
5121 if( pop_heap_pos == ENUMUNDEF )
break;
5124 ShortestPath = Dist[Ui];
5126 if( AugmentPath <= ShortestPath )
5128 Dist[Ui] = std::numeric_limits<INMOST_DATA_REAL_TYPE>::max();
5133 ColumnList[Ui] = ColumnBegin;
5139 if( PathEnd != ENUMUNDEF )
5144 U[Ui] += Dist[Ui] - AugmentPath;
5145 if( Perm[Ui] != ENUMUNDEF ) V[Perm[Ui]] = C(Perm[Ui],ColumnPosition[Perm[Ui]]) - U[Ui];
5146 Dist[Ui] = std::numeric_limits<INMOST_DATA_REAL_TYPE>::max();
5147 Li = ColumnList[Ui];
5148 ColumnList[Ui] = ENUMUNDEF;
5153 while(Trace != ENUMUNDEF)
5155 IPermPrev = IPerm[Trace];
5159 ColumnPosition[Trace] = Ui;
5160 V[Trace] = C(Trace,ColumnPosition[Trace]) - U[Ui];
5163 Trace = Parent[Trace];
5172 for (
int k = 0; k < std::min(n,m); ++k)
5174 l = (V[k] == std::numeric_limits<INMOST_DATA_REAL_TYPE>::max() ? 1 : exp(V[k]));
5175 u = (U[k] == std::numeric_limits<INMOST_DATA_REAL_TYPE>::max() || Cmax[k] == 0 ? 1 : exp(U[k])/Cmax[k]);
5177 if( l*get_value(A(k,Perm[k]))*u < 0.0 ) l *= -1;
5179 if( SL ) SL[Perm[k]] = u;
5182 if( SR )
for(
int k = std::min(n,m); k < n; ++k) SR[k] = 1;
5183 if( SL )
for(
int k = std::min(n,m); k < m; ++k) SL[k] = 1;
5186 std::fill(IPerm.begin(),IPerm.end(),ENUMUNDEF);
5187 std::vector<INMOST_DATA_ENUM_TYPE> gaps;
5188 for(
int k = 0; k < m; ++k)
5190 if( Perm[k] != ENUMUNDEF )
5193 for(
int k = 0; k < m; ++k)
5195 if( IPerm[k] == ENUMUNDEF )
5198 for(
int k = 0; k < m; ++k)
5200 if( Perm[k] == ENUMUNDEF )
5202 Perm[k] = gaps.back();
5208 template<
typename Var>
5217 bool success = ConjugateTranspose().cSVD(V, Sigma, U);
5222 Var cs, eta, f, g, h, q, r, sn, w, x, y, z;
5223 int i, j, k, l, p = 0;
5224 std::vector<Var> t, b, c, s;
5238 for (i = k; i < m; ++i)
5239 z += A(i, k) * conj(A(i, k));
5242 if (fabs(get_value(z)))
5248 if (fabs(get_value(w))) q = A(k, k) / w;
5249 A(k, k) = q * (z + w);
5253 for (j = k + 1; j < n + p; ++j)
5256 for (i = k; i < m; ++i)
5257 q += conj(A(i, k)) * A(i, j);
5258 q = q / (z * (z + w));
5259 for (i = k; i < m; ++i)
5260 A(i, j) -= q * A(i, k);
5263 q = -conj(A(k, k)) / fabs(A(k, k));
5264 for (j = k + 1; j < n + p; ++j)
5269 if (k == n - 1)
break;
5271 for (j = k + 1; j < n; ++j)
5272 z += conj(A(k, j)) * A(k, j);
5275 if (fabs(get_value(z)))
5279 w = fabs(A(k, k + 1));
5281 if (fabs(get_value(w))) q = A(k, k + 1) / w;
5282 A(k, k + 1) = q * (z + w);
5283 for (i = k + 1; i < m; ++i)
5286 for (j = k + 1; j < n; ++j)
5287 q += conj(A(k, j)) * A(i, j);
5288 q = q / (z * (z + w));
5290 for (j = k + 1; j < n; ++j)
5291 A(i, j) -= q * A(k, j);
5294 q = -conj(A(k, k + 1)) / fabs(A(k, k + 1));
5295 for (i = k + 1; i < m; ++i)
5296 A(i, k + 1) = A(i, k + 1) * q;
5300 for (k = 0; k < n; k++)
5308 for(j = 0; j < m; ++j) U(j,j) = 1.0;
5311 for(j = 0; j < n; ++j) V(j,j) = 1.0;
5313 for (k = n - 1; k >= 0; k--)
5319 for (l = k; l >= 0; l--)
5321 if (!fabs(get_value(t[l])))
5326 if (!fabs(get_value(s[l - 1])))
break;
5333 for (i = l; i <= k; ++i)
5337 if (!fabs(get_value(f)))
break;
5339 w = sqrt(f * f + h * h);
5343 for (j = 0; j < n; ++j)
5345 x = real_part(U(j, l - 1));
5346 y = real_part(U(j, i));
5347 U(j, l - 1) = x * cs + y * sn;
5348 U(j, i) = y * cs - x * sn;
5351 if (p == 0)
continue;
5353 for (j = n; j < n + p; ++j)
5357 A(l - 1, j) = q * cs + r * sn;
5358 A(i, j) = r * cs - q * sn;
5370 f = ((y - w) * (y + w) + (g - h) * (g + h)) / (2.0 * h * y);
5371 g = sqrt(f * f + 1.0);
5372 if (real_part(get_value(f)) < 0.0) g = -g;
5373 f = ((x - w) * (x + w) + (y / (f + g) - h) * h) / x;
5377 for (i = l+1; i <= k; ++i)
5383 w = sqrt(h * h + f * f);
5387 f = x * cs + g * sn;
5388 g = g * cs - x * sn;
5391 for (j = 0; j < n; ++j)
5393 x = real_part(V(j, i - 1));
5394 w = real_part(V(j, i));
5395 V(j, i - 1) = x * cs + w * sn;
5396 V(j, i) = w * cs - x * sn;
5398 w = sqrt(h * h + f * f);
5402 f = cs * g + sn * y;
5403 x = cs * y - sn * g;
5404 for (j = 0; j < n; ++j)
5406 y = real_part(U(j, i - 1));
5407 w = real_part(U(j, i));
5408 U(j, i - 1) = y * cs + w * sn;
5409 U(j, i) = w * cs - y * sn;
5412 for (j = n; j < n + p; ++j)
5416 A(i - 1, j) = q * cs + r * sn;
5417 A(i, j) = r * cs - q * sn;
5425 if (real_part(get_value(w)) >= 0.0)
continue;
5427 for (j = 0; j < n; ++j) V(j, k) = -V(j, k);
5430 for (k = 0; k < n; ++k)
5434 for (i = k; i < n; ++i)
5436 if (real_part(get_value(g)) < real_part(get_value(s[i])))
5442 if (j == k)
continue;
5447 for (i = 0; i < n; ++i)
5454 for (i = 0; i < n; ++i)
5461 if (p == 0)
continue;
5462 for (i = n; i < n + p; ++i)
5470 for (k = n - 1; k >= 0; k--)
5472 if (b[k] == 0.0)
continue;
5473 q = -A(k, k) / fabs(A(k, k));
5474 for (j = 0; j < m; ++j)
5476 for (j = 0; j < m; ++j)
5479 for (i = k; i < m; ++i)
5480 q += conj(A(i, k)) * U(i, j);
5481 q = q / (fabs(A(k, k)) * b[k]);
5482 for (i = k; i < m; ++i)
5483 U(i, j) -= q * A(i, k);
5488 for (k = n - 2; k >= 0; k--)
5490 if (c[k+1] == 0.0)
continue;
5491 q = -conj(A(k, k+1)) / fabs(A(k, k+1));
5492 for (j = 0; j < n; ++j)
5495 for (j = 0; j < n; ++j)
5498 for (i = k+1; i < n; ++i)
5499 q += A(k, i) * V(i, j);
5500 q = q / (fabs(A(k, k+1)) * c[k+1]);
5501 for (i = k+1; i < n; ++i)
5502 V(i, j) -= q * conj(A(k, i));
5508 for (i = 0; i < n; ++i)
5513 template<
typename Var>
5516 int flag, i, its, j, jj, k, l, nm;
5535 bool success = Transpose().SVD(V, Sigma, U);
5545 Var c, f, h, s, x, y, z;
5546 Var g = 0.0, scale = 0.0;
5547 INMOST_DATA_REAL_TYPE anorm = 0.0;
5548 std::vector<Var> rv1(m);
5551 for (i = 0; i < n; i++)
5556 g = s = scale = 0.0;
5559 for (k = i; k < m; k++) scale += fabs(U(k, i));
5560 if (fabs(get_value(scale)))
5562 for (k = i; k < m; k++)
5566 s += U(k, i) * conj(U(k, i));
5569 g = -sign_func(sqrt(s), f);
5572 if (i != n - 1 && fabs(get_value(h)))
5574 for (j = l; j < n; j++)
5577 for (s = 0.0, k = i; k < m; k++) s += conj(U(k, i)) * U(k, j);
5579 for (k = i; k < m; k++) U(k, j) += f * U(k, i);
5582 for (k = i; k < m; k++) U(k, i) *= scale;
5585 Sigma(i, i) = scale * g;
5587 g = s = scale = 0.0;
5588 if (i < m && i != n - 1)
5590 for (k = l; k < n; k++) scale += fabs(U(i, k));
5591 if (fabs(get_value(scale)))
5593 for (k = l; k < n; k++)
5595 U(i, k) = U(i, k) / scale;
5597 s += U(i, k) * conj(U(i, k));
5600 g = -sign_func(sqrt(s), f);
5603 for (k = l; k < n; k++) rv1[k] = U(i, k) / h;
5606 for (j = l; j < m; j++)
5608 for (s = 0.0, k = l; k < n; k++) s += conj(U(i, k)) * U(j, k);
5609 for (k = l; k < n; k++) U(j, k) += s * rv1[k];
5612 for (k = l; k < n; k++) U(i, k) *= scale;
5615 anorm = max_func(anorm, fabs(get_value(Sigma(i, i))) + fabs(get_value(rv1[i])));
5619 for (i = n - 1; i >= 0; i--)
5623 if (fabs(get_value(g)))
5625 for (j = l; j < n; j++) V(j, i) = ((U(i, j) / U(i, l)) / g);
5627 for (j = l; j < n; j++)
5629 for (s = 0.0, k = l; k < n; k++) s += U(i, k) * V(k, j);
5630 for (k = l; k < n; k++) V(k, j) += s * V(k, i);
5633 for (j = l; j < n; j++) V(i, j) = V(j, i) = 0.0;
5641 for (i = n - 1; i >= 0; i--)
5646 for (j = l; j < n; j++)
5648 if (fabs(get_value(g)))
5653 for (j = l; j < n; j++)
5655 for (s = 0.0, k = l; k < m; k++) s += conj(U(k, i)) * U(k, j);
5656 f = (s / U(i, i)) * g;
5657 for (k = i; k < m; k++) U(k, j) += f * U(k, i);
5660 for (j = i; j < m; j++) U(j, i) *= g;
5662 else for (j = i; j < m; j++) U(j, i) = 0.0;
5667 for (k = n - 1; k >= 0; k--)
5669 for (its = 0; its < 30; its++)
5672 for (l = k; l >= 0; l--)
5675 if (fabs(get_value(rv1[l])) + anorm == anorm)
5681 if (fabs(get_value(Sigma(nm, nm))) + anorm == anorm)
5688 for (i = l; i <= k; i++)
5691 if (fabs(get_value(f)) + anorm != anorm)
5699 for (j = 0; j < m; j++)
5703 U(j, nm) = (y * c + z * s);
5704 U(j, i) = (z * c - y * s);
5712 if (real_part(get_value(z)) < 0.0 && nonnegative)
5715 for (j = 0; j < n; j++) V(j, k) = -V(j, k);
5721 std::cout <<
"No convergence after " << its <<
" iterations" << std::endl;
5731 f = ((y - z) * (y + z) + (g - h) * (g + h)) / (2.0 * h * y);
5733 f = ((x - z) * (x + z) + h * ((y / (f + sign_func(g, f))) - h)) / x;
5736 for (j = l; j <= nm; j++)
5751 for (jj = 0; jj < n; jj++)
5755 V(jj, j) = (x * c + z * s);
5756 V(jj, i) = (z * c - x * s);
5760 if (fabs(get_value(z)))
5766 f = (c * g) + (s * y);
5767 x = (c * y) - (s * g);
5768 for (jj = 0; jj < m; jj++)
5772 U(jj, j) = (y * c + z * s);
5773 U(jj, i) = (z * c - y * s);
5782 if (order_singular_values)
5785 for (i = 0; i < n; i++)
5788 for (j = i + 1; j < n; ++j)
5789 if (real_part(get_value(Sigma(k, k))) < real_part(get_value(Sigma(j, j)))) k = j;
5790 if (real_part(get_value(Sigma(k, k))) > real_part(get_value(Sigma(i, i))))
5793 Sigma(k, k) = Sigma(i, i);
5796 for (
int j = 0; j < m; ++j)
5803 for (
int j = 0; j < n; ++j)
5843 __INLINE raMatrix raMatrixMake(INMOST_DATA_REAL_TYPE * p, raMatrix::enumerator n, raMatrix::enumerator m) {
return raMatrix(shell<INMOST_DATA_REAL_TYPE>(p,n*m),n,m);}
5844 __INLINE caMatrix caMatrixMake(INMOST_DATA_CPLX_TYPE* p, raMatrix::enumerator n, caMatrix::enumerator m) {
return caMatrix(shell<INMOST_DATA_CPLX_TYPE>(p, n * m), n, m); }
5845 __INLINE iaSymmetricMatrix iaSymmetricMatrixMake(INMOST_DATA_INTEGER_TYPE * p, iaSymmetricMatrix::enumerator n) {
return iaSymmetricMatrix(shell<INMOST_DATA_INTEGER_TYPE>(p,n*(n+1)/2),n);}
5846 __INLINE raSymmetricMatrix raSymmetricMatrixMake(INMOST_DATA_REAL_TYPE * p, raSymmetricMatrix::enumerator n) {
return raSymmetricMatrix(shell<INMOST_DATA_REAL_TYPE>(p,n*(n+1)/2),n);}
5847 __INLINE caSymmetricMatrix caSymmetricMatrixMake(INMOST_DATA_CPLX_TYPE* p, caSymmetricMatrix::enumerator n) {
return caSymmetricMatrix(shell<INMOST_DATA_CPLX_TYPE>(p, n * (n + 1) / 2), n); }
5848 #if defined(USE_AUTODIFF)
5850 typedef Matrix<unknown> uMatrix;
5852 typedef Matrix<variable> vMatrix;
5854 typedef Matrix<hessian_variable> hMatrix;
5856 typedef Matrix<unknown,shell<unknown> > uaMatrix;
5858 typedef Matrix<variable,shell<variable> > vaMatrix;
5860 typedef Matrix<hessian_variable,shell<hessian_variable> > haMatrix;
5862 typedef SymmetricMatrix<unknown,shell<unknown> > uaSymmetricMatrix;
5864 typedef SymmetricMatrix<variable,shell<variable> > vaSymmetricMatrix;
5866 typedef SymmetricMatrix<hessian_variable,shell<hessian_variable> > haSymmetricMatrix;
5870 __INLINE uaMatrix uaMatrixMake(unknown * p, uaMatrix::enumerator n, uaMatrix::enumerator m) {
return uaMatrix(shell<unknown>(p,n*m),n,m);}
5871 __INLINE vaMatrix vaMatrixMake(variable * p, vaMatrix::enumerator n, vaMatrix::enumerator m) {
return vaMatrix(shell<variable>(p,n*m),n,m);}
5872 __INLINE haMatrix vaMatrixMake(hessian_variable * p, haMatrix::enumerator n, haMatrix::enumerator m) {
return haMatrix(shell<hessian_variable>(p,n*m),n,m);}
5873 __INLINE uaSymmetricMatrix uaSymmetricMatrixMake(unknown * p, uaSymmetricMatrix::enumerator n) {
return uaSymmetricMatrix(shell<unknown>(p,n*(n+1)/2),n);}
5874 __INLINE vaSymmetricMatrix vaSymmetricMatrixMake(variable * p, vaSymmetricMatrix::enumerator n) {
return vaSymmetricMatrix(shell<variable>(p,n*(n+1)/2),n);}
5875 __INLINE haSymmetricMatrix vaSymmetricMatrixMake(hessian_variable * p, haSymmetricMatrix::enumerator n) {
return haSymmetricMatrix(shell<hessian_variable>(p,n*(n+1)/2),n);}
5882 template<
typename typeB>
5888 #if defined(USE_AUTODIFF)
5894 template<
typename typeB>
5905 template<
typename typeB>
5917 template<
typename typeB>
5927 template<
class A,
typename typeB>
5935 template<
typename T>
5937 template<
typename T>
5939 template<
typename T>
SelfPromote< Var >::type FrobeniusNorm() const
Computes frobenius norm of the matrix.
Matrix< Var > CholeskyInvert(int *ierr=NULL) const
Inverts symmetric positive-definite matrix using Cholesky decomposition.
Matrix< typename Promote< Var, typeB >::type > operator/(const AbstractMatrixReadOnly< typeB > &other) const
Performs B^{-1}*A, multiplication by inverse matrix from left.
ConstMatrixConcatCols2< Var, VarB, typename Promote< Var, VarB >::type > ConcatCols(const AbstractMatrixReadOnly< VarB > &B) const
Concatenate B matrix as columns of current matrix.
Promote< Var, typeB >::type DotProduct(const AbstractMatrixReadOnly< typeB > &other) const
Computes dot product by summing up multiplication of entries with the same indices in the current and...
virtual __INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
Matrix< Var > Power(INMOST_DATA_REAL_TYPE n, int *ierr=NULL) const
Calcuate A^n, where n is some real value.
MatrixUnaryMinus< Var > operator-() const
Unary minus. Change sign of each element of the matrix.
bool CheckInfs() const
Check all matrix entries for infinity.
MatrixMulShellCoef< Var, shell_expression< A >, typename Promote< Var, variable >::type > operator*(shell_expression< A > const &coef) const
Multiply the matrix by a coefficient.
MatrixDifference< Var, typeB > operator-(const AbstractMatrixReadOnly< typeB > &other) const
Subtract a matrix.
virtual enumerator Cols() const =0
Obtain number of columns.
Var MaxNorm() const
Computes maximum absolute value of the matrix.
virtual Var compute(enumerator i, enumerator j) const =0
Compute element of the matrix by row and column indices without right to change the element.
KroneckerProduct< Var, typeB > Kronecker(const AbstractMatrixReadOnly< typeB > &other) const
Kronecker product, latex symbol \otimes.
ConstMatrixConjugateTranspose< Var > ConjugateTranspose() const
Transpose and conjugate current matrix.
Matrix< Var > Invert(int *ierr=NULL) const
Inverts matrix using Crout-LU decomposition with full pivoting for maximum element.
ConstMatrixConcatCols< Var > ConcatCols(const AbstractMatrixReadOnly< Var > &B) const
Concatenate B matrix as columns of current matrix.
MatrixDivCoef< Var, typeB, typename Promote< Var, typeB >::type > operator/(const typeB &coef) const
Divide the matrix by a coefficient of a different type.
Matrix< Var > PseudoInvert(INMOST_DATA_REAL_TYPE tol=0, int *ierr=NULL) const
Calculates Moore-Penrose pseudo-inverse of the matrix.
ConstSubMatrix< Var > operator()(enumerator first_row, enumerator last_row, enumerator first_col, enumerator last_col) const
Extract submatrix of a matrix for in-place manipulation of elements.
Var Trace() const
Calculate sum of the diagonal elements of the matrix.
Matrix< typename Promote< Var, typeB >::type > CholeskySolve(const AbstractMatrixReadOnly< typeB > &B, int *ierr=NULL) const
Finds X in A*X=B, where A is a square symmetric positive definite matrix.
bool SVD(AbstractMatrix< Var > &U, AbstractMatrix< Var > &Sigma, AbstractMatrix< Var > &V, bool order_singular_values=true, bool nonnegative=true) const
Singular value decomposition.
MatrixMulCoef< Var, typeB, typename Promote< Var, typeB >::type > operator*(const typeB &coef) const
Multiply the matrix by a coefficient.
void Print(INMOST_DATA_REAL_TYPE threshold=1.0e-10, std::ostream &sout=std::cout) const
Output matrix to screen.
bool isSymmetric(double eps=1.0e-7) const
Check if the matrix is symmetric.
ConstMatrixConcatRows< Var > ConcatRows(const AbstractMatrixReadOnly< Var > &B) const
Concatenate B matrix as rows of current matrix.
Promote< Var, typeB >::type operator^(const AbstractMatrixReadOnly< typeB > &other) const
Computes dot product by summing up multiplication of entries with the same indices in the current and...
Matrix< typename Promote< Var, typeB >::type > CrossProduct(const AbstractMatrixReadOnly< typeB > &other) const
Cross-product operation for a vector.
bool cSVD(AbstractMatrix< Var > &U, AbstractMatrix< Var > &Sigma, AbstractMatrix< Var > &V) const
Singular value decomposition.
ConstMatrixTranspose< Var > Transpose() const
Transpose current matrix.
ConstMatrixConjugate< Var > Conjugate() const
Conjugate current matrix.
virtual enumerator Rows() const =0
Obtain number of rows.
Matrix< Var > ExtractSubMatrix(enumerator ibeg, enumerator iend, enumerator jbeg, enumerator jend) const
Extract submatrix of a matrix.
Matrix< typename Promote< Var, typeB >::type > PseudoSolve(const AbstractMatrixReadOnly< typeB > &B, INMOST_DATA_REAL_TYPE tol=0, int *ierr=NULL) const
Solves the system of equations of the form A*X=B, with A and B matrices.
ConstMatrixConcatRows2< Var, VarB, typename Promote< Var, VarB >::type > ConcatRows(const AbstractMatrixReadOnly< VarB > &B) const
Concatenate B matrix as rows of current matrix.
MatrixMul< Var, typeB, typename Promote< Var, typeB >::type > operator*(const AbstractMatrixReadOnly< typeB > &other) const
Multiply the matrix by another matrix.
ConstBlockOfMatrix< Var > BlockOf(enumerator nrows, enumerator ncols, enumerator offset_row, enumerator offset_col) const
Define matrix as a part of a matrix of larger size with in-place manipulation of elements.
virtual ~AbstractMatrixReadOnly()
Destructor.
bool CheckNans() const
Check all matrix entries for not a number.
MatrixSum< Var, typeB > operator+(const AbstractMatrixReadOnly< typeB > &other) const
Add a matrix.
ConstMatrixRepack< Var > Repack(enumerator rows, enumerator cols) const
Change representation of the matrix into matrix of another size.
bool CheckNansInfs() const
Check all matrix entries for not a number and infinity.
Matrix< typename Promote< Var, typeB >::type > Transform(const AbstractMatrixReadOnly< typeB > &other) const
Transformation matrix from current vector to provided vector using shortest arc rotation.
Matrix< typename Promote< Var, typeB >::type > Solve(const AbstractMatrixReadOnly< typeB > &B, int *ierr=NULL) const
Finds X in A*X=B, where A and B are general matrices.
MatrixDivShellCoef< Var, shell_expression< A >, typename Promote< Var, variable >::type > operator/(shell_expression< A > const &coef) const
Divide the matrix by a coefficient of a different type.
Var Det() const
Matrix determinant.
Matrix< Var > Root(INMOST_DATA_ENUM_TYPE iter=25, INMOST_DATA_REAL_TYPE tol=1.0e-7, int *ierr=NULL) const
Calculate square root of A matrix by Babylonian method.
Abstract class for a matrix, used to abstract away all the data storage and access and provide common...
Matrix< typename Promote< Var, typeB >::type > CrossProduct(const AbstractMatrixReadOnly< typeB > &other) const
Cross-product operation for a vector.
void Print(INMOST_DATA_REAL_TYPE threshold=1.0e-10, std::ostream &sout=std::cout) const
Output matrix to screen.
Promote< Var, typeB >::type DotProduct(const AbstractMatrixReadOnly< typeB > &other) const
Computes dot product by summing up multiplication of entries with the same indices in the current and...
Var Trace() const
Calculate sum of the diagonal elements of the matrix.
bool CheckNansInfs() const
Check all matrix entries for not a number and infinity.
BlockOfMatrix< Var > BlockOf(enumerator nrows, enumerator ncols, enumerator offset_row, enumerator offset_col)
Define matrix as a part of a matrix of larger size with in-place manipulation of elements.
MatrixConcatCols< Var > ConcatCols(AbstractMatrix< Var > &B)
Concatenate B matrix as columns of current matrix.
void Zero()
Set all the elements of the matrix to zero.
AbstractMatrix & operator+=(const AbstractMatrixReadOnly< typeB > &other)
Add a matrix and store result in the current.
virtual void Swap(AbstractMatrix< Var > &b)
Exchange contents of two matrices.
virtual Var & operator()(enumerator i, enumerator j)=0
Access element of the matrix by row and column indices.
SelfPromote< Var >::type FrobeniusNorm() const
Computes frobenious norm of the matrix.
virtual const Var & get(enumerator i, enumerator j) const =0
Access element of the matrix by row and column indices.
AbstractMatrix & operator/=(typeB coef)
Divide the matrix by the coefficient of the same type and store the result.
MatrixTranspose< Var > Transpose()
Transpose the current matrix with access to elements.
MatrixConcatRows< Var > ConcatRows(AbstractMatrix< Var > &B)
Concatenate B matrix as rows of current matrix.
Matrix< typename Promote< Var, typeB >::type > Transform(const AbstractMatrix< typeB > &other) const
Transformation matrix from current vector to provided vector using shortest arc rotation.
virtual ~AbstractMatrix()
Destructor.
SubMatrix< Var > operator()(enumerator first_row, enumerator last_row, enumerator first_col, enumerator last_col)
Extract submatrix of a matrix for in-place manipulation of elements.
MatrixRepack< Var > Repack(enumerator rows, enumerator cols)
Change representation of the matrix into matrix of another size.
bool CheckNans() const
Check all matrix entries for not a number.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
Matrix< typename Promote< Var, typeB >::type > Transform(const AbstractMatrixReadOnly< typeB > &other) const
Transformation matrix from current vector to provided vector using shortest arc rotation.
AbstractMatrix & operator+=(const AbstractMatrix< typeB > &other)
Add a matrix and store result in the current.
AbstractMatrix & operator*=(const AbstractMatrixReadOnly< typeB > &B)
Multiply matrix with another matrix in-place.
Promote< Var, typeB >::type DotProduct(const AbstractMatrix< typeB > &other) const
Computes dot product by summing up multiplication of entries with the same indices in the current and...
AbstractMatrix & operator*=(typeB coef)
Multiply the matrix by the coefficient of the same type and store the result.
AbstractMatrix & operator-=(const AbstractMatrixReadOnly< typeB > &other)
Subtract a matrix and store result in the current.
Matrix< typename Promote< Var, typeB >::type > CrossProduct(const AbstractMatrix< typeB > &other) const
Cross-product operation for a vector.
AbstractMatrix()
Construct empty matrix.
bool isSymmetric(double eps=1.0e-7) const
Check if the matrix is symmetric.
AbstractMatrix & operator-=(const AbstractMatrix< typeB > &other)
Subtract a matrix and store result in the current.
Promote< Var, typeB >::type operator^(const AbstractMatrix< typeB > &other) const
Computes dot product by summing up multiplication of entries with the same indices in the current and...
void MPT(INMOST_DATA_ENUM_TYPE *Perm, INMOST_DATA_REAL_TYPE *SL=NULL, INMOST_DATA_REAL_TYPE *SR=NULL) const
Maximum product transversal.
Var MaxNorm() const
Computes maximum absolute value of the matrix.
bool CheckInfs() const
Check all matrix entries for infinity.
virtual void Resize(enumerator rows, enumerator cols)=0
Resize the matrix into different size.
AbstractMatrix & operator=(AbstractMatrix const &other)
Assign matrix of the same type.
This class allows to address a matrix as a block of an empty matrix of larger size.
__INLINE Var & operator()(enumerator i, enumerator j)
Access element of the matrix by row and column indices.
BlockOfMatrix & operator=(AbstractMatrix< typeB > const &other)
Assign matrix of another type to the block of matrix.
__INLINE enumerator Rows() const
Number of rows in submatrix.
::INMOST::Matrix< Var > MakeMatrix()
Convert block of matrix into matrix.
__INLINE enumerator Cols() const
Number of columns in submatrix.
__INLINE Var compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
BlockOfMatrix(AbstractMatrix< Var > &rM, enumerator num_rows, enumerator num_cols, enumerator offset_row, enumerator offset_col)
Create submatrix for a matrix.
void Resize(enumerator rows, enumerator cols)
This is a stub function to fulfill abstract inheritance.
__INLINE const Var & get(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
This class allows to address a matrix as a block of an empty matrix of larger size.
__INLINE Var compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
::INMOST::Matrix< Var > MakeMatrix()
Convert block of matrix into matrix.
__INLINE enumerator Cols() const
Number of columns in submatrix.
ConstBlockOfMatrix(const AbstractMatrixReadOnly< Var > &rM, enumerator num_rows, enumerator num_cols, enumerator offset_row, enumerator offset_col)
Create submatrix for a matrix.
__INLINE enumerator Rows() const
Number of rows in submatrix.
__INLINE VarR compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE enumerator Rows() const
Number of rows.
__INLINE enumerator Cols() const
Number of columns.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE enumerator Rows() const
Number of rows.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE Var compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE enumerator Cols() const
Number of columns.
__INLINE VarR compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE enumerator Cols() const
Number of columns.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE enumerator Rows() const
Number of rows.
__INLINE Var compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE enumerator Cols() const
Number of columns.
__INLINE enumerator Rows() const
Number of rows.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE enumerator Cols() const
Number of columns.
__INLINE Var compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE enumerator Rows() const
Number of rows.
__INLINE Var compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE enumerator Cols() const
Number of columns.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE enumerator Rows() const
Number of rows.
__INLINE Var compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE enumerator Cols() const
Number of columns.
__INLINE enumerator Rows() const
Number of rows.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE Var compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE enumerator Cols() const
Number of columns.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE enumerator Rows() const
Number of rows.
This class allows for in-place operations on submatrix of the matrix elements.
__INLINE Var compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE enumerator Rows() const
Number of rows in submatrix.
__INLINE enumerator Cols() const
Number of columns in submatrix.
::INMOST::Matrix< Var > MakeMatrix()
Convert submatrix into matrix.
ConstSubMatrix(const AbstractMatrixReadOnly< Var > &rM, enumerator first_row, enumerator last_row, enumerator first_column, enumerator last_column)
Create submatrix for a matrix.
__INLINE enumerator Cols() const
Number of columns.
bool TrivialArguments() const
Check that this matrix does not require calculations for element access.
__INLINE enumerator Rows() const
Number of rows.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE Promote< VarA, VarB >::type compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE enumerator Rows() const
Number of rows.
__INLINE Var compute(enumerator i, enumerator j) const
Compute element of the matrix by row and column indices without right to change the element.
__INLINE enumerator Cols() const
Number of columns.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE enumerator Rows() const
Number of rows.
__INLINE const Var & get(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE Var & operator()(enumerator i, enumerator j)
Access element of the matrix by row and column indices without right to change the element.
__INLINE Var compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE enumerator Cols() const
Number of columns.
void Resize(enumerator rows, enumerator cols)
This is a stub function to fulfill abstract inheritance.
__INLINE enumerator Cols() const
Number of columns.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE enumerator Rows() const
Number of rows.
__INLINE Var compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE const Var & get(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE Var & operator()(enumerator i, enumerator j)
Access element of the matrix by row and column indices without right to change the element.
void Resize(enumerator rows, enumerator cols)
This is a stub function to fulfill abstract inheritance.
__INLINE Var compute(enumerator i, enumerator j) const
Compute element of the matrix by row and column indices without right to change the element.
__INLINE enumerator Rows() const
Number of rows.
__INLINE enumerator Cols() const
Number of columns.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE Promote< VarA, VarB >::type compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE enumerator Cols() const
Number of columns.
__INLINE enumerator Rows() const
Number of rows.
__INLINE VarR compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
bool TrivialArguments() const
Check that this matrix does not require calculations for element access.
__INLINE enumerator Cols() const
Number of columns.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE enumerator Rows() const
Number of rows.
__INLINE VarR compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE enumerator Rows() const
Number of rows.
__INLINE enumerator Cols() const
Number of columns.
bool TrivialArguments() const
Check that this matrix does not require calculations for element access.
__INLINE enumerator Rows() const
Number of rows.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
bool TrivialArguments() const
Check that this matrix does not require calculations for element access.
__INLINE enumerator Cols() const
Number of columns.
__INLINE VarR compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE enumerator Cols() const
Number of columns.
bool TrivialArguments() const
Check that this matrix does not require calculations for element access.
__INLINE enumerator Rows() const
Number of rows.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE VarR compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE VarR & operator()(enumerator i, enumerator j)
Access element of the matrix by row and column indices.
__INLINE enumerator Cols() const
Number of columns.
__INLINE const VarR & get(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE enumerator Rows() const
Number of rows.
void Resize(enumerator rows, enumerator cols)
This is a stub function to fulfill abstract inheritance.
__INLINE VarR compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE Var compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE enumerator Rows() const
Number of rows.
void Resize(enumerator rows, enumerator cols)
This is a stub function to fulfill abstract inheritance.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE enumerator Cols() const
Number of columns.
__INLINE const Var & get(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE Var & operator()(enumerator i, enumerator j)
Access element of the matrix by row and column indices.
__INLINE Var compute(enumerator i, enumerator j) const
Compute element of the matrix by row and column indices without right to change the element.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE enumerator Cols() const
Number of columns.
__INLINE enumerator Rows() const
Number of rows.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE Promote< VarA, VarB >::type compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE enumerator Cols() const
Number of columns.
__INLINE enumerator Rows() const
Number of rows.
__INLINE Var compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE Var & operator()(enumerator i, enumerator j)
Access element of the matrix by row and column indices without right to change the element.
void Resize(enumerator rows, enumerator cols)
This is a stub function to fulfill abstract inheritance.
__INLINE const Var & get(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE enumerator Rows() const
Number of rows.
__INLINE enumerator Cols() const
Number of columns.
__INLINE enumerator Rows() const
Number of rows.
__INLINE Var compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE enumerator Cols() const
Number of columns.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE enumerator Rows() const
Number of rows.
__INLINE Var compute(enumerator i, enumerator j) const
Compute element of the matrix by row and column indices without right to change the element.
__INLINE INMOST_DATA_ENUM_TYPE GetMatrixCount() const
Retrieve number of indices of derivatives.
__INLINE enumerator Cols() const
Number of columns.
Class for linear algebra operations on dense matrices.
Matrix(const AbstractMatrix< typeB > &other)
Construct matrix from matrix of different type.
__INLINE Var compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices.
__INLINE enumerator & Cols()
Obtain number of rows.
void RemoveRow(enumerator row)
Erase single row.
static Matrix< Var > Permutation(const INMOST_DATA_ENUM_TYPE *Perm, enumerator size)
Construct row permutation matrix from array of new positions for rows.
__INLINE const Var & get(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
void RemoveRows(enumerator first, enumerator last)
Erase multiple rows.
__INLINE Var & operator()(enumerator i, enumerator j)
Access element of the matrix by row and column indices.
void Resize(enumerator nrows, enumerator mcols)
Resize the matrix into different size.
Matrix(enumerator pn, enumerator pm, const Var &c)
Construct a matrix with provided sizes and fills with value.
static Matrix< Var > FromDiagonal(const Var *r, enumerator size)
Create diagonal matrix from array.
Matrix(const storage_type &pspace)
Construct the matrix with the provided storage and unknown size.
static Matrix< Var > CrossProductMatrix(const Var vec[3])
Cross-product matrix.
Matrix< Var > JointDiagonalization(INMOST_DATA_REAL_TYPE threshold=1.0e-7)
Joint diagonalization algorithm by Cardoso.
Matrix(const Matrix &other)
Copy matrix.
__INLINE enumerator Cols() const
Obtain number of columns.
static Matrix< Var > FromVector(const Var *r, enumerator size)
Create column-vector in matrix form from array.
static Matrix< Var > FromTensor(const Var *K, enumerator size, enumerator matsize=3)
Convert values in array into square matrix.
void RemoveColumns(enumerator first, enumerator last)
Erase multiple columns.
Matrix(enumerator pn, enumerator pm)
Construct a matrix with provided sizes.
Matrix(const AbstractMatrixReadOnly< typeB > &other)
Construct matrix from matrix of different type.
__INLINE enumerator Rows() const
Obtain number of rows.
__INLINE const Var * data() const
Return raw pointer to matrix data without right of change, stored in row-wise format.
__INLINE Var * data()
Return raw pointer to matrix data, stored in row-wise format.
static MatrixRow< Var > Row(enumerator pn, const Var &c=1.0)
Matix with 1 row, Create a matrix of size 1 by pn and fills it with c.
Matrix(const storage_type &pspace, enumerator pn, enumerator pm)
Construct the matrix with the provided storage with known size.
Matrix & operator=(Matrix const &other)
Assign matrix of the same type.
static MatrixUnit< Var > Unit(enumerator pn, const Var &c=1.0)
Unit matrix.
Matrix()
Construct empty matrix.
Matrix(const Var *pspace, enumerator pn, enumerator pm)
Construct the matrix from provided array and sizes.
void Swap(AbstractMatrix< Var > &b)
Exchange contents of two matrices.
void RemoveColumn(enumerator col)
Erase single column.
static Matrix< Var > FromDiagonalInverse(const Var *r, enumerator size)
Create diagonal matrix from array of values that have to be inversed.
static Matrix Make(enumerator pn, enumerator pm,...)
Construct a matrix with provided elements.
void RemoveSubset(enumerator firstrow, enumerator lastrow, enumerator firstcol, enumerator lastcol)
Erase part of the matrix.
static MatrixCol< Var > Col(enumerator pn, const Var &c=1.0)
Matix with 1 column, Create a matrix of size pn by 1 and fills it with c.
__INLINE enumerator & Rows()
Obtain number of rows.
This class may be used to sum multiple sparse rows.
void AddRow(INMOST_DATA_REAL_TYPE coef, const Row &r)
Add a row with a coefficient into non-empty linked list.
void RetrieveRow(Row &r) const
Place entries from linked list into row.
void Resize(INMOST_DATA_ENUM_TYPE size)
Resize linked list for new interval.
void Clear()
Clear linked list.
void PushRow(INMOST_DATA_REAL_TYPE coef, const Row &r)
Add a row with a coefficient into empty linked list.
This class allows for in-place operations on submatrix of the matrix elements.
SubMatrix & operator=(AbstractMatrixReadOnly< typeB > const &other)
Assign matrix of another type to submatrix.
__INLINE enumerator Cols() const
Number of columns in submatrix.
SubMatrix(AbstractMatrix< Var > &rM, enumerator first_row, enumerator last_row, enumerator first_column, enumerator last_column)
Create submatrix for a matrix.
::INMOST::Matrix< Var > MakeMatrix()
Convert submatrix into matrix.
__INLINE Var compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
void Resize(enumerator rows, enumerator cols)
This is a stub function to fulfill abstract inheritance.
__INLINE enumerator Rows() const
Number of rows in submatrix.
__INLINE Var & operator()(enumerator i, enumerator j)
Access element of the matrix by row and column indices.
__INLINE const Var & get(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
__INLINE enumerator Cols() const
Obtain number of columns.
static SymmetricMatrix< Var > FromTensor(const Var *K, enumerator size, enumerator matsize=3)
Convert values in array into square matrix.
SymmetricMatrix(const SymmetricMatrix &other)
Copy matrix.
__INLINE enumerator Rows() const
Obtain number of rows.
__INLINE Var * data()
Return raw pointer to matrix data, stored in row-wise format.
SymmetricMatrix(const AbstractMatrixReadOnly< typeB > &other)
Construct matrix from matrix of different type.
SymmetricMatrix(const storage_type &pspace, enumerator pn)
Construct the matrix with the provided storage with known size.
static SymmetricMatrix Make(enumerator pn,...)
Construct a matrix with provided elements.
SymmetricMatrix(const Var *pspace, enumerator pn)
Construct the matrix from provided array and sizes.
__INLINE enumerator & Rows()
Obtain number of rows.
__INLINE const Var & get(enumerator i, enumerator j) const
Access element of the matrix by row and column indices.
__INLINE enumerator & Cols()
Obtain number of rows.
void Resize(enumerator nrows, enumerator ncols)
Resize the matrix into different size.
SymmetricMatrix(enumerator pn, const Var &c)
Construct a matrix with provided sizes and fills with value.
SymmetricMatrix(const storage_type &pspace)
Construct the matrix with the provided storage and unknown size.
__INLINE const Var * data() const
Return raw pointer to matrix data without right of change, stored in row-wise format.
__INLINE Var & operator()(enumerator i, enumerator j)
Access element of the matrix by row and column indices.
static SymmetricMatrix< Var > FromDiagonal(const Var *r, enumerator size)
Create diagonal matrix from array.
static SymmetricMatrix< Var > FromDiagonalInverse(const Var *r, enumerator size)
Create diagonal matrix from array of values that have to be inversed.
~SymmetricMatrix()
Delete matrix.
__INLINE Var compute(enumerator i, enumerator j) const
Access element of the matrix by row and column indices without right to change the element.
static SymmetricMatrix< Var > Unit(enumerator pn, const Var &c=1.0)
Unit matrix.
void Swap(AbstractMatrix< Var > &b)
Exchange contents of two matrices.
SymmetricMatrix & operator=(SymmetricMatrix const &other)
Assign matrix of the same type.
SymmetricMatrix()
Construct empty matrix.
SymmetricMatrix(enumerator pn)
Construct a matrix with provided sizes.
SymmetricMatrix(const AbstractMatrix< typeB > &other)
Construct matrix from matrix of different type.
A class that represents a variable with multiple first order and second order variations.
A class that represents a variable with multiple first order variations.