15 #include "tbci/basics.h"
16 #include "tbci/vector.h"
18 #include "tbci/matrix_sig.h"
25 #if !defined(NO_GD) && !defined(AUTO_DECL)
26 # include "tbci/matrix_gd.h"
32 #ifdef HAVE_GCC295_FRIEND_BUG
33 # define _VEC getvec()
34 # define _ENDVEC getendvec()
37 # define _COL columns()
38 # define _FAC getfac()
41 # define _ENDVEC endvec
49 #ifndef TBCI_DISABLE_EXCEPT
57 :
NumErr(
"Error in Matrix library") {}
67 # pragma interface "matrix.h"
72 template <
typename T>
class Matrix;
73 template <
typename T>
class TMatrix;
76 template <
typename T>
class BdMatrix;
77 template <
typename T>
class Tensor;
95 #if defined(SMP) && !defined(SMP_MATSLICE)
96 # define SMP_MATSLICE 4096
99 # define SMP_MATSLICE2 (SMP_MATSLICE/sizeof(T))
108 template <
typename T>
124 #if 1 //defined(HAVE_GCC295_FRIEND_BUG) || defined(HAVE_PROMOTION_BUG)
152 friend void FRIEND_TBCI2__ do_mat_vec_transmult_exact
FGD (
const unsigned start,
const unsigned end,
162 explicit TMatrix (
const unsigned = 0);
164 TMatrix (
const unsigned,
const unsigned);
166 TMatrix (
const T&,
const unsigned,
const unsigned);
180 static const
char*
mat_info () {
return (
"TMatrix"); }
187 #ifndef HAVE_PROMOTION_BUG
188 # ifndef HAVE_GCC295_TMPLFRNDCLS_BUG
190 template <
typename U>
friend class Matrix;
198 while (t <
endvec) *t++ = *u++; }
205 while (t <
endvec) *t++ = *u++; }
212 TMatrix<T>& operator = (const T&);
218 TMatrix<T>& operator += (const T&);
222 TMatrix<T>& operator -= (const T&);
234 TMatrix<T>& operator + (const T&);
238 TMatrix<T>& operator - (const T&);
249 {
Matrix<T> m (*
this);
return (m * tv); }
251 {
Matrix<T> m (*
this);
return (m * tsv); }
254 #ifndef HAVE_GCC295_FRIEND_BUG
274 #ifndef TBCI_NEW_BRACKET
281 T&
setval(
const T& val,
const unsigned int r,
const unsigned int c)
282 {
return mat[r][
c] = val; }
284 {
return mat[r][
c]; }
287 typename tbci_traits<T>::const_refval_type
288 get (
const unsigned r,
const unsigned c)
const
289 {
return mat[r][
c]; }
290 T&
set (
const T& val,
const unsigned r,
const unsigned c)
291 {
return mat[r][
c] = val; }
292 const T&
getcref(
const unsigned r,
const unsigned c)
const
293 {
return mat[r][
c]; }
302 {
return !(*
this == m); }
305 {
Matrix<T> m (tm);
return (*
this == m); }
307 {
return !(*
this == tm); }
311 {
return !(*
this ==
ts); }
340 void set_row_indexed (
const Vector<T>&,
const unsigned int,
344 void set_row_indexed (
const Vector<T>&,
const unsigned int,
348 const unsigned int,
const unsigned int);
352 template <
unsigned long dim>
393 template <
typename T>
401 template <
typename T>
408 template <
typename T>
424 const unsigned int ROW =
row;
425 const unsigned int COL =
col;
428 for (
REGISTER unsigned i = 0; i < ROW; ++
i)
429 MAT[i] = VEC + i*COL;
444 template <
typename T>
453 template <
typename T>
461 template <
typename T>
471 template <
typename T>
483 template <
typename T>
495 template <
typename T>
503 template <
typename T>
513 template <
typename T>
522 template <
typename T>
532 template <
typename T>
541 template <
typename T>
550 template <
typename T>
559 template <
typename T>
562 return this->
fill (val);
566 template <
typename T>
574 for (
REGISTER unsigned i = 0; i < iend; i++)
579 template <
typename T>
588 template <
typename T>
596 template <
typename T>
598 const unsigned int r,
const unsigned off)
605 template <
typename T>
610 const unsigned ROW =
row;
611 for (
REGISTER unsigned r = 0; r < ROW; ++r)
615 template <
typename T>
617 const unsigned int c,
const unsigned off)
621 const unsigned ROW = v.
dim;
622 for (
REGISTER unsigned r = 0; r < ROW; ++r)
626 template <
typename T>
629 const unsigned ROW =
row;
632 for (
REGISTER unsigned j = 0; j < ROW; ++j)
639 template <
typename T>
648 template <
typename T>
654 template <
typename T>
662 unsigned long dd =
dim;
663 dim = ((
unsigned long)r)*
c;
677 template <
typename T>
682 dim = ((
unsigned long)r)*
col;
695 for (
REGISTER unsigned i=0; i<r; i++) {
706 template <
typename T>
711 unsigned long olddim =
dim;
744 template <
typename T>
755 dim = ((
unsigned long)r)*
c;
767 template <
typename T>
791 template <
typename T>
796 BCHK (nr >
row,
MatErr, cheapdownsize does not upsize, nr, *
this);
799 dim = ((
unsigned long)nr) *
col;
804 template <
typename T>
811 template <
typename T>
821 template <
typename T>
832 template <
typename T>
839 template <
typename T>
853 template <
typename T>
881 template <
typename T>
889 template <
typename T>
898 template <
typename T>
906 template <
typename T>
916 template <
typename T>
919 template <
typename T>
923 template <
typename T>
931 template <
typename T>
941 template <
typename T>
947 template <
typename T>
954 template <
typename T>
958 template <
typename T>
966 template <
typename T>
969 template <
typename T>
973 template <
typename T>
976 template <
typename T>
980 template <
typename T>
983 template <
typename T>
987 template <
typename T>
991 template <
typename T>
1002 template <typename T>
1009 template <typename T>
1017 template <typename T>
1025 template <typename T>
1033 template <typename T>
1042 template <typename T>
1049 template <
typename T>
1053 template <
typename T>
1060 template <
typename T>
1064 for (
unsigned r = 0; r < this->
row; ++r)
1065 for (
unsigned c = 0;
c < this->
col; ++
c)
1066 trm.
mat[
c][r] = this->mat[r][
c];
1067 this->mark_destroy();
1072 template <typename T>
1078 template <
typename T>
1081 if (this->
col != this->
row) {
1084 return this->
swap(transmat);
1087 for (
unsigned r = 1; r < this->
row; ++r)
1088 for (
unsigned c = 0;
c < r; ++
c)
1099 template<typename T>
1101 {
return tm.fabs (); }
1104 template<typename T>
1106 {
return m.fabs (); }
1117 template <
typename T>
1130 void clone (
bool =
false, TMatrix<T>* = 0);
1131 #if 1 //def HAVE_GCC295_FRIEND_BUG
1134 void detach (TMatrix<T>* = 0);
1146 #if 1 //def HAVE_GCC295_FRIEND_BUG
1157 TSMatrix (
const TMatrix<T>& tm,
const T& f = (
T)1)
1160 TSMatrix (
const Matrix<T>& m,
const T& f = (
T)1)
1168 static const char*
mat_info () {
return (
"TSMatrix"); }
1183 fac = (
T)1;
mut =
true;
return *
this; }
1189 #ifndef HAVE_GCC295_FRIEND_BUG
1204 #ifndef HAVE_GCC295_FRIEND_BUG
1221 bool operator == (TMatrix<T>& tm) { Matrix<T> m(tm);
return (*
this == m); }
1230 template <
typename T>
1238 template <
typename T>
1245 dim = 0;
mat = (
T**)0;
return;
1259 template <
typename T>
1264 T* oldv =
vec;
T** oldm =
mat;
bool omut = mut;
1266 if (evl &&
fac != (
T)1) {
1279 template <
typename T>
1294 template <
typename T>
1300 ts.
fac = (
T)1;
return TMatrix<T> (
ts);
1302 template <
typename T>
1308 ts.
fac = (
T)1;
return TMatrix<T> (
ts);
1311 template <
typename T>
1318 template <
typename T>
1326 template <
typename T>
1334 tm = *
this; tm.
detach ();
1342 return TMatrix<T> (tm);
1345 template <
typename T>
1353 tm = *
this; tm.
detach ();
1361 return TMatrix<T> (tm);
1364 template <
typename T>
1369 ts.
fac = (
T)1;
return TMatrix<T> (
ts);
1372 template <
typename T>
1377 ts.
fac = (
T)1;
return TMatrix<T> (
ts);
1382 template <typename T>
1387 tm._FAC = (
T)1;
return TMatrix<T> (tm);
1390 template <typename T>
1395 tm._FAC = (
T)1;
return TMatrix<T> (tm);
1399 template <
typename T>
1406 for (
unsigned i=0; i<
row; i++) {
1407 for (
unsigned j=0; j<m.
col; j++) {
1408 tmp =
mat[
i][0] * m.
mat[0][j];
1410 tmp +=
mat[i][l] * m.
mat[l][j];
1417 template <
typename T>
1424 for (
unsigned i=0; i<
row; i++) {
1425 for (
unsigned j=0; j<tm.
col; j++) {
1426 tmp =
mat[
i][0] * tm.
get(0,j);
1428 tmp +=
mat[i][l] * tm.
get(l,j);
1435 template <
typename T>
1441 for (
unsigned r=0; r<
row; r++) {
1450 template <
typename T>
1456 for (
unsigned r=0; r<
row; r++) {
1466 template <
typename T>
1492 template <
typename T>
1524 template <typename T>
1526 { ts._FAC = f * ts._FAC;
return ts; }
1529 template <
typename T>
1534 do_vec_fabssqr_exact (
dim,
vec, res);
1536 do_vec_fabssqr_quick (
dim,
vec, res);
1542 template <
typename T>
1553 template <typename T>
1555 {
return ts.fabs (); }
1573 template <
typename T>
1593 Matrix (
const T& v,
const unsigned r,
const unsigned c)
1616 #ifndef HAVE_PROMOTION_BUG
1618 template <
typename U>
1622 template <
typename U>
1630 typename tbci_traits<T>::const_refval_type
1647 Matrix<T>&
resize (
const unsigned r,
const unsigned c)
1650 {
return this->
resize (d, d); }
1651 Matrix<T>&
resize (
const T& v,
const unsigned r,
const unsigned c)
1696 TMatrix<T>
operator + (
const Matrix<T>&)
const;
1697 TMatrix<T>
operator - (
const Matrix<T>&)
const;
1698 TMatrix<T>
operator * (
const Matrix<T>&)
const;
1721 bool operator == (const
Matrix<
T>& m) const;
1723 {
return !(*
this == m); }
1726 { Matrix<T> m (tm);
return (*
this == m); }
1728 {
return !(*
this == tm); }
1732 {
return !(*
this ==
ts); }
1737 Matrix<T>&
mult_row (
const T&,
const unsigned);
1738 Matrix<T>&
div_row (
const T&,
const unsigned);
1742 friend STD__ ostream& operator << FGDT (STD__ ostream&, const Matrix<T>&);
1743 friend STD__ istream&
operator >>
FGDT (
STD__ istream&, Matrix<T>&);
1758 template <
typename T>
1765 unsigned int tcol = this->
col; this->
col = m.
col; m.
col = tcol;
1773 template <
typename T>
1774 inline typename tbci_traits<T>::const_refval_type
1779 return this->
mat[
i][j];
1782 template <
typename T>
1787 return this->
mat[
i][j];
1790 template <
typename T>
1800 template <
typename T>
1801 STD__ ostream& operator << (STD__ ostream& os, const Matrix<T>& m)
1803 for (
unsigned r=0; r<m.row; r++)
1808 for (
unsigned c=0;
c<m.col;
c++)
1809 os << m(r,
c) <<
" ";
1816 template <
typename T>
1821 for (
unsigned i=0; i<m.
row; i++)
1829 INST(template <typename T>
class TMatrix friend STD__ ostream&
operator << (
STD__ ostream& os, TMatrix<T> tm);)
1830 template <typename T>
1837 INST(template <typename T>
class TSMatrix friend STD__ ostream&
operator << (
STD__ ostream& os,
const TSMatrix<T>& ts);)
1838 template <typename T>
1839 STD__ ostream&
operator << (
STD__ ostream& os,
const TSMatrix<T>& ts)
1841 return os << Matrix<T>(
ts);
1848 template <
typename T>
1854 template <
typename T>
1863 template <
typename T>
1866 TMatrix<T> t (this->
row, this->
col);
1870 template <
typename T>
1873 TMatrix<T> t (this->
row, this->
col);
1878 template <
typename T>
1880 {
return TSMatrix<T> (*
this,
a); }
1882 template <
typename T>
1885 BCHK (a==(
T)0,
MatErr, Divide Mat by 0, 0, *
this);
1886 return TSMatrix<T> (*
this, (
T)1/a);
1889 template <
typename T>
1892 TMatrix<T> t (this->
row, this->
col);
1897 template <
typename T>
1900 TMatrix<T> t (this->
row, this->
col);
1906 template <
typename T>
1913 template <
typename T>
1921 template <
typename T>
1925 TSMatrix<T> tm (ts); tm.
detach ();
1927 tm.
fac = (
T)1;
return TMatrix<T> (tm);
1929 template <
typename T>
1933 TSMatrix<T> tm (ts); tm.
detach ();
1935 tm.
fac = (
T)1;
return TMatrix<T> (tm);
1939 #define COST_MATMAT_OLD(ra,ca,cb) (ra*cb*(COST_UNIT_STORE+COST_LOOP \
1940 +ca*(3*COST_UNIT_LOAD+COST_NU_LOAD+COST_MULT+COST_ADD+COST_LOOP)))
1941 #define COST_MATMAT_NEW(ra,ca,cb) (ra*cb*COST_MEMSET+ra*ca*(2*COST_UNIT_LOAD+COST_LOOP \
1942 +cb*(3*COST_UNIT_LOAD+COST_UNIT_STORE+COST_ADD+COST_MULT+COST_LOOP)))
1943 #ifdef OLD_MAT_MAT_MULT
1944 # define COST_MATMAT(ra,ca,cb) COST_MATMAT_OLD(ra,ca,cb)
1946 # define COST_MATMAT(ra,ca,cb) COST_MATMAT_NEW(ra,ca,cb)
1950 INST(template <typename T>
class TMatrix friend void do_mat_mat_mult (
const unsigned,
const unsigned, \
1951 TMatrix<T> *,
const Matrix<T> *,
const Matrix<T> *);)
1953 #include
"matrix_kernels.h"
1955 #
if defined(SMP) && !defined(NOSMP_MATVEC)
1957 template <typename
T>
1958 inline
void job_mat_mat_mult (struct
thr_ctrl *tc)
1960 do_mat_mat_mult (tc->t_off, tc->t_size,
1961 (TMatrix<T>*)(tc->t_par[0]), (
const Matrix<T>*)(tc->t_par[1]),
1962 (
const Matrix<T>*)(tc->t_par[2]));
1965 template <
typename T>
1968 TMatrix<T>
c(this->
row, b.
col);
1971 update_n_thr(n_thr);
1972 #ifndef OLD_MAT_MAT_MULT
1977 do_mat_mat_mult<T> (0UL, this->
row, &
c,
this, &
b);
1982 const unsigned long first = slice_offset(1, n_thr, this->row, (
T*)0);
1983 unsigned long st, en = first;
1985 for (
unsigned t = 0; t < n_thr-1; ++t) {
1986 st = en; en = slice_offset(t+2, n_thr, this->row, (
T*)0);
1988 st, en, &c,
this, &b, (
void*)0);
1991 do_mat_mat_mult<T> (0UL, first, &
c,
this, &
b);
1994 for (
unsigned s = 0; s < n_thr-1; ++s)
2002 template <
typename T>
2005 TMatrix<T>
c(this->
row, b.
col);
2006 #ifndef OLD_MAT_MAT_MULT
2010 do_mat_mat_mult <T> (0, this->
row, &
c,
this, &
b);
2015 template <
typename T>
2018 TMatrix<T>
c(this->
row, a.
col);
2021 for (
unsigned i=0; i<this->
row; i++) {
2022 for (
unsigned j=0; j<a.
col; j++) {
2023 tmp = this->
mat[
i][0] * a.
mat[0][j];
2025 tmp += this->
mat[i][l] * a.
mat[l][j];
2026 c.
mat[i][j] = tmp * a.
fac;
2033 template <
typename T>
2036 TMatrix<T>
c (this->
operator * (Matrix<T> (a)));
2040 template <
typename T>
2043 Matrix<T> m (*
this);
2048 template <
typename T>
2051 Matrix<T> m (*
this);
2052 return (m * (Matrix<T> (a)));
2055 template <
typename T>
2058 Matrix<T> m (*
this);
2063 template <
typename T>
2076 template <
typename T>
2101 template <
typename T>
2106 do_vec_fabssqr_exact (this->
dim, this->
vec, res);
2108 do_vec_fabssqr_quick (this->
dim, this->
vec, res);
2112 template <
typename T>
2123 template<
typename T>
2127 return (*
this * cn);
2131 #if defined(SMP) && !defined(NOSMP_MATVEC)
2133 template <
typename T>
2141 template <
typename T>
2150 template <
typename T>
2156 update_n_thr(n_thr);
2160 do_mat_vec_mult<T> (0, this->
row, &tv,
this, &v);
2165 const unsigned long first = slice_offset(1, n_thr, this->
row, (
T*)0);
2166 unsigned long st, en = first;
2168 for (
unsigned t = 0; t < n_thr-1; ++t) {
2169 st = en; en = slice_offset(t+2, n_thr, this->
row, (
T*)0);
2171 st, en, &tv,
this, &v, (
void*)0);
2174 do_mat_vec_mult<T> (0, first, &tv,
this, &
v);
2177 for (
unsigned s = 0; s < n_thr-1; ++s)
2183 template<
typename T>
2188 update_n_thr(n_thr);
2191 do_mat_vec_transmult<T> (0, this->
col, &tv,
this, &v);
2194 const unsigned long first = slice_offset(1, n_thr, this->
col, (
T*)0);
2196 unsigned long st, en = first;
2197 for (
unsigned t = 0; t < n_thr-1; ++t) {
2201 st = en; en = slice_offset(t+2, n_thr, this->
col, (
T*)0);
2203 st, en, &tv,
this, &v, (
void*)0);
2205 do_mat_vec_transmult<T> (0, first, &tv,
this, &
v);
2207 for (
unsigned s = 0; s < n_thr-1; ++s)
2215 template <
typename T>
2224 template<
typename T>
2229 do_mat_vec_transmult<T> (0, this->
col, &tv,
this, &
v);
2237 template <
typename T>
2247 template <
typename T>
2260 template <
typename T>
2264 for (
unsigned r = 0; r < this->
row; r++)
2267 for (
unsigned c = 0;
c < this->
col;
c++)
2268 this->
operator() (r,
c) *= fac;
2273 template <
typename T>
2277 for (
unsigned r = 0; r < this->
row; r++)
2279 T fac = (
T)1.0 / v (r);
2280 for (
unsigned c = 0;
c < this->
col;
c++)
2281 (*
this) (r,
c) *= fac;
2286 template <
typename T>
2289 BCHK (r>this->
row, MatErr, mult_row: wrong
index, r, *
this);
2290 for (
unsigned c = 0;
c < this->
col;
c++)
2291 (*
this) (r,
c) *= f;
2295 template <
typename T>
2298 BCHK (r>this->
row, MatErr, mult_row: wrong
index, r, *
this);
2299 BCHK (d == (
T)0, MatErr, div_row by zero, r, *
this);
2301 for (
unsigned c = 0;
c < this->
col;
c++)
2302 (*
this) (r,
c) *= f;
2309 template <
typename T>
2313 const TMatrix<T> & tmat;
2320 Mat_Brack (
const TMatrix<T> &tm,
unsigned int ix) : tmat(tm), idx (ix) {}
2325 {
EXPCHK(j >= tmat.col, MatErr, Idx2 out of range, j, tmat.mat[idx][0]);
2326 return tmat.mat[idx][j]; }
2328 {
EXPCHK(j >= tmat.col, MatErr, Idx2 out of range, j, tmat.mat[idx][0]);
2329 return tmat.mat[idx][j]; }
2332 template <
typename T>
2335 this->
vec = mb.tmat.mat[mb.idx];
2336 this->
dim = (
unsigned long)mb.tmat.col; this->keep =
true;
2339 template <
typename T>
2342 this->
dim = (
unsigned long)mb.tmat.col;
2347 TBCICOPY (this->
vec, mb.tmat.mat[mb.idx],
T, this->dim);
2351 this->
dim = 0; this->
vec = (
T*)0;
2353 #ifndef TBCI_NEW_BRACKET
2354 template <
typename T>
2361 template <
typename T>
2364 EXPCHK(ix >=
row, MatErr, Idx1 out of range, ix, (
T*)0);
2378 #if defined(__GNUC__) && __GNUC__ >= 5 && __GNUC__ < 8 && (defined(__x86_64__) || defined(__i386__))
2379 # define NOFMA __attribute__((target("no-fma")))
2387 template <typename
T>
2390 T (*fn)(
const unsigned i1,
const unsigned i2,
void* par);
2395 template <
typename T>
2399 const unsigned cols = mat->
columns();
2401 for (
unsigned r = firstrow; r < lastrow; ++r)
2403 (*mat)(r,
c) = fn.
fn(r,
c, par);
2407 template <
typename T>
2411 (Matrix<T>*)(tc->
t_par[0]),
2416 template <
typename T>
2422 update_n_thr(n_thr);
2425 do_fill_mat<T> (0,
rows, &
mat, fn, par);
2428 const unsigned long first = slice_offset(1, n_thr, rows, (
T*)0);
2429 unsigned long st, en = first;
2431 for (
unsigned t = 0; t < n_thr-1; ++t) {
2432 st = en; en = slice_offset(t+2, n_thr, rows, (
T*)0);
2434 st, en, &mat, (
void*)&fn, par, (
void*)0);
2437 do_fill_mat<T> (0, first, &
mat, fn, par);
2440 for (
unsigned s = 0; s < n_thr-1; ++s)
2446 template <
typename T>
2449 do_fill_mat<T> (0, mat.
rows(), &
mat, fn, par);
2453 #if defined(SMP) && defined(HAVE_LIBNUMA)
2454 template <
typename T>
2472 const unsigned first = slice_offset(1, n_thr, rows, (
T*)0);
2473 unsigned long st, en = first;
2475 unsigned long res = 0;
2476 for (
unsigned t = 0; t < n_thr-1; ++t) {
2477 st = en; en = slice_offset(t+2, n_thr, rows, (
T*)0);
2489 for (
unsigned t = 0; t < n_thr-1; ++t) {
2499 template <
typename T>
#define TBCICOPY(n, o, t, s)
TVector< T > transMult(const Vector_Sig< T > &) const
BdMatrix< T > transpose(BdMatrix< T > &mat)
TSMatrix< T > operator*=(const T &)
T ** mat
C storage layout: mat[row][col].
#define BCHKNR(cond, exc, txt, ind)
Matrix< T > & resize(const unsigned r, const unsigned c)
void do_mat_tsv_mult(const unsigned start, const unsigned end, TVector< T > *res, const Matrix< T > *mat, const TSVector< T > *vec)
void detach(TMatrix< T > *=0)
#define STD_SMP_TEMPLATE3VV(oper, dm, a1, a2, a3)
Matrix< T > & operator*=(const T &a)
T aligned_value_type TALIGN(MIN_ALIGN2)
void do_mat_vec_mult(const unsigned start, const unsigned end, TVector< T > *res, const Matrix< T > *mat, const Vector< T > *vec)
Matrix< T > & operator-=(const Matrix< T > &a)
void job_mat_vec_transmult(struct thr_ctrl *tc)
TSMatrix< T > & operator*=(const T &f)
bool operator!=(const Matrix< T > &m)
TMatrix< T > & operator+=(TMatrix< T >)
arithmetics ...
Matrix(const Matrix< T > &m)
copy, does a real copy, as TM(M) is invoked (not TM(TM))
TMatrix< T > operator-() const
The class BdMatrix is an implementation to store and do operations on sparse Matrices with a band str...
STD__ istream & operator>>(STD__ istream &istr, BdMatrix< T > &mat)
void real_destroy()
real destructor
bool operator==(const Matrix< T > &m) const
TVector< T > get_col(const unsigned int) const
Column vector.
void set_row(const Vector< T > &, const unsigned int)
Fill complete row.
TSMatrix< T > & operator=(const TSMatrix< T > &ts)
mat_fill_fn(T(*f)(const unsigned, const unsigned, void *))
const T & getcref(const unsigned r, const unsigned c) const
TMatrix(const TMatrix< U > &tm)
bool operator==(const Matrix< T > &)
exception base class for the TBCI NumLib
F_TMatrix< double > lu_solve(const F_Matrix< double > &A, const F_Matrix< double > &B, int overwriteA=0)
TSMatrix< T > operator/(const T &)
TVector< T > get_row(const unsigned int) const
Row vector.
T & setval(const unsigned r, const unsigned c)
unsigned int rows() const
NAMESPACE_TBCI char gaussj(Matrix< T > &a, Matrix< T > &b)
Common interface definition (signature) for all Matrices.
tbci_traits< T >::const_refval_type get(const unsigned long i) const
TMatrix< T > & transpose()
void set_row_partial(const Vector< T > &, const unsigned int, const unsigned int)
Fill partial row.
T operator()(const unsigned int r, const unsigned int c) HOT
bool operator!=(const Matrix< T > &m) const
Matrix(const unsigned r, const unsigned c)
TMatrix< T > & resize(const unsigned int, const unsigned int)
Resize Matrix, specifying rows and columns.
#define STD_SMP_TEMPLATE5(oper, dm, a1, a2, a3, a4, a5)
void mark_destroy() const
mark destructible
TSMatrix< T > operator/(const T &) const
#define BCHK(cond, exc, txt, ind, rtval)
void par_fill(Matrix< T > &mat, mat_fill_fn< T > fn, void *par)
tbci_traits< T >::const_refval_type operator()(const unsigned int, const unsigned int) const HOT
ro element access
Vector(const unsigned long d=0)
#define NAMESPACE_CSTD_END
Matrix(const T &v, const unsigned r, const unsigned c)
Matrix< T > & resize(const Matrix< T > &m)
#define TBCIFILL(n, v, t, s)
BVector< T > & bvfillm(BVector< T > &bv, const Matrix< T > &m)
#define REALLOC(v, os, t, s)
Matrix< T > & setunit(const T &f=(T) 1)
void(* thr_job_t)(struct thr_ctrl *)
Before the double inclusion guard on purpose!
unsigned long size() const
number of elements
TMatrix< T > LU_invert(const BdMatrix< T > &lu)
return the inverse Matrix for an already LU decomposed BdMatrix
TSMatrix< T > & operator/=(const T &f)
T & set(const T &val, const unsigned long i) const
#define STD_SMP_TEMPLATE4C(oper, dm, a1, a2, a3, a4)
T & setval(const T &val, const unsigned int r, const unsigned int c)
bool operator!=(const Matrix< T > &m)
static const char * mat_info()
void job_fill_mat(struct thr_ctrl *tc)
Matrix< T > & div_row(const T &, const unsigned)
double fabssqr() const
Sum over all squared elements.
struct thr_struct * threads
TMatrix< T > operator+(const Matrix< T > &)
void set_col(const Vector< T > &, const unsigned int)
Fill complete column.
int lu_decomp(Matrix< T > &) HOT
LU decomposes the TBCI::Matrix mat.
void job_mat_vec_mult(struct thr_ctrl *tc)
TMatrix< T > & clear()
Clear matrix (fill with 0)
#define PREFETCH_R(addr, loc)
In case gcc does not yet support __builtin_prefetch(), we have handcoded assembly with gcc for a few ...
Matrix(const Vector< T > &v, const enum rowcolvec r=colvec)
T(* fn)(const unsigned i1, const unsigned i2, void *par)
Matrix< T > & fill(const T &v=(T) 0)
TVector(const unsigned long d=0)
unsigned int columns() const
number of columns
Matrix(const TMatrix< T > &tm) HOT
alias
Tensor class including arithmetics.
Matrix(const unsigned d=0)
TMatrix< T > & operator-()
Matrix< T > & mult_row(const T &, const unsigned)
TMatrix< T > & cheapdownsizerow(const unsigned)
Resize number of rows without actually freeing memory (efficiency)
TMatrix< T > transposed_copy() const
Inefficient! Use transMult if possible.
long int Vector< T > & index
TVector< T > transMult(const Vector< T > &) const HOT
friend NOINST TMatrix< T > LU_solve FGD(const BdMatrix< T > &, const Matrix< T > &)
TMatrix(const Matrix< U > &m)
void set_col_partial(const Vector< T > &, const unsigned int, const unsigned int)
Fill partial column.
T aligned_value_type TALIGN(MIN_ALIGN2)
unsigned long size() const
Matrix< T > & fill(const Vector< T > &v)
void do_mat_vec_transmult(const unsigned start, const unsigned end, TVector< T > *res, const Matrix< T > *mat, const Vector< T > *vec)
T aligned_value_type TALIGN(MIN_ALIGN2)
TSMatrix< T > operator*(const T &)
TSMatrix< T > & operator/(const T &f)
Matrix< T > & resize(const unsigned d)
Matrix< T > & operator+=(const Matrix< T > &a)
void clone(bool=false, TMatrix< T > *=0)
TSMatrix< T > operator/=(const T &)
bool operator==(const Matrix< T > &m)
Comparison.
Matrix(const TSMatrix< T > &ts)
void do_fill_mat(const unsigned firstrow, const unsigned lastrow, Matrix< T > *mat, mat_fill_fn< T > fn, void *par)
TMatrix< T > & operator-=(TMatrix< T >)
void SWAP(T &a, T &b)
SWAP function Note: We could implement a swap function without temporaries: a -= b b += a a -= b a = ...
TMatrix< T > & operator=(const Matrix< T > &) HOT
assignment, non-resizing
unsigned long size() const
#define STD_SMP_TEMPLATE2C(oper, dm, a1, a2)
MatErr(const char *t, const long i=0)
Matrix< T > & operator=(const Matrix< T > &m)
Assignment, non-resizing.
TMatrix< T > & operator+(TMatrix< T >)
Matrix(const TMatrix< U > &tm)
#define PREFETCH_W(addr, loc)
static const char * mat_info()
Matrix(const Matrix< U > &m)
TMatrix< T > & fill(const T &=(T) 0)
Fill matrix.
TMatrix< T > operator*(const Matrix< T > &) const
#define EXPCHK(cond, exc, txt, ind, rtval)
Matrix< T > & operator/=(const T &a)
T * getrowptr(const unsigned r)
TMatrix< T > & row_expand(const unsigned int r)
Set new numbers of rows to matrix (expansion only)
const T & operator[](unsigned int j) const
TSMatrix(const TSMatrix< T > &ts)
TSMatrix< T > & operator*(const T &f)
T operator()(const unsigned int, const unsigned int) const HOT
Element access (desctructive for TMatrix!)
#define STD_SMP_TEMPLATE2V(oper, dm, a1, a2)
TMatrix< T > operator+(const Matrix< T > &) const
#define TBCICLEAR(n, t, s)
#define TBCIDELETE(t, v, sz)
Temporary Base Class Idiom: Class TVector is used for temporary variables.
unsigned long size() const
void thread_wait(const int thr_no, struct job_output *out)
#define STD_SMP_TEMPLATE3VC(oper, dm, a1, a2, a3)
TMatrix< T > & swap(TMatrix< T > &)
static const char * mat_info()
TSMatrix< T > & operator-()
Implementation of fixed sized Vectors (template argument) which is favorable for small Vectors...
Mat_Brack< T > operator[](const unsigned int i) const
TVector< T > LU_solve(const BdMatrix< T > &lu, const Vector< T > &b)
Solve the equation Ax = b where A IS already LU decomposed.
const Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > long int res
double fabssqr(const double a)
TMatrix< T > & setunit(const T &=(T) 1)
Set to unit matrix (optionally scaled)
#define TBCICOMP(n, o, t, s)
friend BVector< T > &FRIEND_TBCI2__ bvfillm FGD(BVector< T > &, const Matrix< T > &m)
const T * getrowptr(const unsigned r) const
Helpers for matvecmul.
T & set(const T &val, const unsigned r, const unsigned c)
unsigned int do_exactsum()
int numa_optimize(const BdMatrix< T > &bm, bool fault_in)
const unsigned TMatrix< T > const Matrix< T > * a
Matrix< T > & div_rows(const Vector< T > &)
void thread_start_off(const int thr_no, thr_job_t job, const unsigned long off, const unsigned long sz,...)
const Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > long int int char v
< find minimun of func on grid with resolution res
TMatrix< T > lu_invert(BdMatrix< T > &mat)
return the inverse Matrix for a BdMatrix by doing an LU decomposition
TMatrix< T > & resize(const unsigned int d)
Resize Matrix to square shape.
Matrix< T > & resize(const T &v, const unsigned r, const unsigned c)
#define LIKELY(expr)
branch prediction note that we sometimes on purpose mark the unlikely possibility likely and vice ver...
Matrix< T > & mult_rows(const Vector< T > &)
Elementwise ops.
tbci_traits< T >::const_refval_type get(const unsigned r, const unsigned c) const
get, set and getcref are used internally and not for public consumption
unsigned int rows() const
number of rows
TSMatrix< T > & eval(TMatrix< T > *=0)
TMatrix< T > & alias(const TMatrix< T > &m)
#define STD_SMP_TEMPLATE4V(oper, dm, a1, a2, a3, a4)