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++; }
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;
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>
535 BCHK(
dim !=
a.dim,
MatErr, Different sizes in assignment,
a.dim, *
this );
541 template <
typename T>
550 template <
typename T>
559 template <
typename T>
562 return this->
fill (val);
566 template <
typename T>
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;
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>
858 return (
ts.real_destroy(),
false);
867 ts.real_destroy ();
return false;
874 ts.real_destroy ();
return false;
877 ts.real_destroy ();
return true;
881 template <
typename T>
885 BCHK(
col !=
a.col,
MatErr, number of cols differ in op,
a.col, *
this );
889 template <
typename T>
893 BCHK(
col !=
a.col,
MatErr, number of cols differ in op,
a.col, *
this );
898 template <
typename T>
902 BCHK(
col !=
a.col,
MatErr, number of cols differ in op,
a.col, *
this );
904 a.real_destroy();
return *
this;
906 template <
typename T>
910 BCHK(
col !=
a.col,
MatErr, number of cols differ in op,
a.col, *
this );
912 a.real_destroy();
return *
this;
916 template <
typename T>
919 template <
typename T>
923 template <
typename T>
929 ts.real_destroy ();
return *
this;
931 template <
typename T>
937 ts.real_destroy ();
return *
this;
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)
1089 SWAP(this->mat[r][
c], this->mat[
c][r]);
1099 template<typename T>
1101 {
return tm.fabs (); }
1104 template<typename T>
1106 {
return m.fabs (); }
1117 template <
typename T>
1131 #if 1 //def HAVE_GCC295_FRIEND_BUG 1146 #if 1 //def HAVE_GCC295_FRIEND_BUG 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 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>
1302 template <
typename T>
1311 template <
typename T>
1318 template <
typename T>
1326 template <
typename T>
1334 tm = *
this; tm.
detach ();
1345 template <
typename T>
1353 tm = *
this; tm.
detach ();
1364 template <
typename T>
1372 template <
typename T>
1382 template <typename T>
1390 template <typename T>
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];
1411 c.mat[
i][j] = tmp *
fac;
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);
1429 c.mat[
i][j] = tmp *
fac;
1435 template <
typename T>
1441 for (
unsigned r=0; r<
row; r++) {
1444 el +=
mat[r][
c] * v(
c);
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>
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
1650 {
return this->
resize (d, d); }
1723 {
return !(*
this == m); }
1726 {
Matrix<T> m (tm);
return (*
this == m); }
1728 {
return !(*
this == tm); }
1732 {
return !(*
this ==
ts); }
1742 friend STD__ ostream& operator << FGDT (STD__ ostream&, const 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++)
1830 template <typename T>
1838 template <typename T>
1841 return os << Matrix<T>(
ts);
1848 template <
typename T>
1854 template <
typename T>
1863 template <
typename T>
1870 template <
typename T>
1878 template <
typename T>
1882 template <
typename T>
1889 template <
typename T>
1893 BCHK(this->dim !=
a.dim,
MatErr, Operator + on diff
size matrices,
a.dim, t);
1897 template <
typename T>
1901 BCHK(this->dim !=
a.dim,
MatErr, Operator - on diff
size matrices,
a.dim, t);
1906 template <
typename T>
1913 template <
typename T>
1921 template <
typename T>
1929 template <
typename T>
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, \
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)
1965 template <
typename T>
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>
2006 #ifndef OLD_MAT_MAT_MULT 2010 do_mat_mat_mult <T> (0, this->
row, &
c,
this, &
b);
2015 template <
typename T>
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;
2029 a.real_destroy ();
return c;
2033 template <
typename T>
2040 template <
typename T>
2048 template <
typename T>
2055 template <
typename T>
2063 template <
typename T>
2068 if (
LIKELY(this->vec == m.
vec || this->dim == 0))
2076 template <
typename T>
2079 if (
LIKELY(this->row !=
ts.row || this->col !=
ts.col))
2080 return (
ts.real_destroy(),
false);
2081 if (
LIKELY(this->dim == 0)) {
2088 ts.real_destroy ();
return false;
2095 ts.real_destroy ();
return false;
2098 ts.real_destroy ();
return true;
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>
2290 for (
unsigned c = 0;
c < this->
col;
c++)
2291 (*
this) (r,
c) *= f;
2295 template <
typename T>
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>
2326 return tmat.
mat[idx][j]; }
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;
2345 this->vec =
NEW (
T, this->dim);
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>
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>
2416 template <
typename T>
2420 const unsigned rows = mat.
rows();
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>
2460 const unsigned rows = m.
rows();
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)
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)
const T & operator[](unsigned int j) const
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)
unsigned long size() const
STD__ istream & operator>>(STD__ istream &in, Matrix< T > &m)
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))
double fabssqr(const TMatrix< T > &tm)
TVector< T > transMult(const Vector_Sig< T > &) const
TMatrix< T > operator*(const Matrix< T > &) const
TMatrix< T > operator+(const Matrix< T > &) const
The class BdMatrix is an implementation to store and do operations on sparse Matrices with a band str...
INST(template< typename T > class TMatrix friend void do_mat_mat_mult(const unsigned, const unsigned, TMatrix< T > *, const Matrix< T > *, const Matrix< T > *);) template< typename T > inline void job_mat_mat_mult(struct thr_ctrl *tc)
void real_destroy()
real destructor
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 *))
TVector< T > get_col(const unsigned int) const
Column vector.
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)
const T * getrowptr(const unsigned r) const
Helpers for matvecmul.
TSMatrix< T > operator/(const T &)
tbci_traits< T >::const_refval_type get(const unsigned long i) const
T & setval(const unsigned r, const unsigned c)
NAMESPACE_TBCI char gaussj(Matrix< T > &a, Matrix< T > &b)
Common interface definition (signature) for all Matrices.
TMatrix< T > & transpose()
void set_row_partial(const Vector< T > &, const unsigned int, const unsigned int)
Fill partial row.
const unsigned TMatrix< T > * res
NAMESPACE_END NAMESPACE_CSTD double fabs(const TBCI__ TMatrix< T > &tm)
T operator()(const unsigned int r, const unsigned int c) HOT
TMatrix< T > transposed_copy() const
Inefficient! Use transMult if possible.
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)
#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)
bool operator==(const Matrix< T > &m) const
BVector< T > & bvfillm(BVector< T > &bv, const Matrix< T > &m)
TSMatrix< T > operator/(const T &) const
#define REALLOC(v, os, t, s)
Matrix< T > & setunit(const T &f=(T) 1)
TMatrix< T > LU_invert(const BdMatrix< T > &lu)
return the inverse Matrix for an already LU decomposed BdMatrix
TSMatrix< T > & operator/=(const T &f)
unsigned long size() const
#define STD_SMP_TEMPLATE4C(oper, dm, a1, a2, a3, a4)
T & setval(const T &val, const unsigned int r, const unsigned int c)
unsigned long size() const
number of elements
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)
bool operator!=(const Matrix< T > &m) const
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)
Matrix< T > & fill(const T &v=(T) 0)
TVector(const unsigned long d=0)
T(* fn)(const unsigned i1, const unsigned i2, void *par)
Matrix(const TMatrix< T > &tm) HOT
alias
unsigned int columns() const
number of columns
TSMatrix(const Matrix< T > &m, const T &f=(T) 1)
TSMatrix(const TMatrix< T > &tm, const T &f=(T) 1)
TMatrix< T > operator-() const
Tensor class including arithmetics.
unsigned long size() const
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)
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)
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 &)
TMatrix< T > transpose(const TMatrix< T > &tm)
bool operator==(const Matrix< T > &m)
Comparison.
int numa_optimize(const Matrix< T > &m, bool fault_in)
Matrix(const TSMatrix< T > &ts)
unsigned int rows() const
number of rows
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 = ...
const T & getcref(const unsigned r, const unsigned c) const
TMatrix< T > & operator=(const Matrix< T > &) HOT
assignment, non-resizing
#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.
#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)
T & set(const T &val, const unsigned long i) const
TSMatrix(const TSMatrix< T > &ts)
TVector< T > get_row(const unsigned int) const
Row vector.
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)
#define TBCICLEAR(n, t, s)
unsigned int rows() const
#define TBCIDELETE(t, v, sz)
Temporary Base Class Idiom: Class TVector is used for temporary variables.
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()
void(* thr_job_t)(struct thr_ctrl *)
Before the double inclusion guard on purpose!
double fabssqr() const
Sum over all squared elements.
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
TSMatrix< T > & operator-()
Implementation of fixed sized Vectors (template argument) which is favorable for small Vectors...
TVector< T > LU_solve(const BdMatrix< T > &lu, const Vector< T > &b)
Solve the equation Ax = b where A IS already LU decomposed.
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)
void mark_destroy() const
mark destructible
unsigned int do_exactsum()
Mat_Brack< T > operator[](const unsigned int i) const
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,...)
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.
TSMatrix< T > & eval(TMatrix< T > *=0)
TMatrix< T > & alias(const TMatrix< T > &m)
#define STD_SMP_TEMPLATE4V(oper, dm, a1, a2, a3, a4)