15 #ifndef OHMMS_PETE_MATRIX_H 16 #define OHMMS_PETE_MATRIX_H 19 #include <type_traits> 26 template<
class T,
typename Alloc = std::allocator<T>>
61 template<
typename CONTAINER>
101 static_assert(std::is_same<value_type, typename Alloc::value_type>::value,
102 "Matrix and Alloc data types must agree!");
126 template<
typename CONTAINER>
135 template<
typename Allocator = Alloc,
typename = IsHostSafe<Allocator>>
142 template<
typename Allocator = Alloc,
typename = IsHostSafe<Allocator>>
154 template<
class T_FROM,
typename ALLOC_FROM>
157 auto& this_ref = *
this;
160 for (
int i = 0; i <
rows; ++i)
161 for (
int j = 0; j <
cols; ++j)
162 this_ref(i, j) = from(i, j);
174 template<
class RHS,
typename Allocator = Alloc,
typename = IsHostSafe<Allocator>>
177 return assign(*
this, rhs);
187 template<
typename Allocator = Alloc,
typename = IsDualSpace<Allocator>>
192 template<
typename Allocator = Alloc,
typename = IsDualSpace<Allocator>>
221 template<
typename Allocator = Alloc,
typename = IsHostSafe<Allocator>>
228 template<
typename Allocator = Alloc,
typename = IsHostSafe<Allocator>>
235 template<
typename Allocator = Alloc,
typename = IsHostSafe<Allocator>>
238 return X[i *
D2 + j];
242 template<
typename Allocator = Alloc,
typename = IsHostSafe<Allocator>>
245 return X[i *
D2 + j];
248 template<
typename Allocator = Alloc,
typename = IsHostSafe<Allocator>>
251 for (
int col = 0; col <
D2; col++)
253 Type_t tmp = (*this)(r1, col);
254 (*this)(r1, col) = (*
this)(r2, col);
255 (*this)(r2, col) = tmp;
259 template<
typename Allocator = Alloc,
typename = IsHostSafe<Allocator>>
262 for (
int row = 0; row <
D1; row++)
264 Type_t tmp = (*this)(row, c1);
265 (*this)(row, c1) = (*
this)(row, c2);
266 (*this)(row, c2) = tmp;
270 template<
class IT,
typename Allocator = Alloc,
typename = IsHostSafe<Allocator>>
276 template<
class IT,
typename Allocator = Alloc,
typename = IsHostSafe<Allocator>>
280 for (
int i = 0; i <
D1; i++, ii +=
D2)
284 template<
class IT,
typename Allocator = Alloc,
typename = IsHostSafe<Allocator>>
288 for (
int i = 0; i <
D1; i++, ii +=
D2)
299 template<
class T1,
typename Allocator = Alloc,
typename = IsHostSafe<Allocator>>
303 for (
int i = 0; i < d1; i++)
305 int kk = (i0 + i) *
D2 + j0;
306 for (
int j = 0; j < d2; j++)
308 X[kk++] += sub[ii++];
313 template<
class T1,
typename Allocator = Alloc,
typename = IsHostSafe<Allocator>>
319 int kk = (i0 + i) *
D2 + j0;
322 X[kk++] += phi * sub[ii++];
327 template<
class SubMat_t,
typename Allocator = Alloc,
typename = IsHostSafe<Allocator>>
328 inline void add(
const SubMat_t& sub,
unsigned int i0,
unsigned int j0)
331 for (
size_type i = 0; i < sub.rows(); i++)
333 int kk = (i0 + i) *
D2 + j0;
334 for (
size_type j = 0; j < sub.cols(); j++)
336 X[kk++] += sub(ii++);
341 template<
typename Allocator = Alloc,
typename = IsHostSafe<Allocator>>
342 inline void add(
const This_t& sub,
unsigned int i0,
unsigned int j0)
347 int kk = (i0 + i) *
D2 + j0;
350 X[kk++] += sub[ii++];
355 template<
class Msg,
typename Allocator = Alloc,
typename = IsHostSafe<Allocator>>
362 template<
class Msg,
typename Allocator = Alloc,
typename = IsHostSafe<Allocator>>
370 template<
typename Allocator = Alloc,
typename = IsDualSpace<Allocator>>
375 template<
typename Allocator = Alloc,
typename = IsDualSpace<Allocator>>
387 template<
class T,
class Alloc>
393 for (
int i = 0; i < rhs.
size(); i++)
394 if (lhs(i) != rhs(i))
402 template<
class T,
class Alloc>
406 return !(lhs == rhs);
411 template<
class T,
typename Alloc>
412 std::ostream& operator<<(std::ostream& out, const Matrix<T, Alloc>& rhs)
416 for (size_type i = 0; i < rhs.rows(); i++)
418 for (size_type j = 0; j < rhs.cols(); j++)
419 out << rhs(ii++) <<
" ";
426 template<
class T,
typename Alloc>
430 for (size_type i = 0; i < rhs.
size(); i++)
440 template<
class T,
typename Alloc>
477 template<
class T,
typename Alloc>
502 template<
class T,
typename Alloc>
513 template<
class T,
typename Alloc,
class Op,
class RHS>
520 for (
int i = 0; i < lhs.
rows(); ++i)
522 for (
int j = 0; j < lhs.
cols(); ++j)
530 throw std::runtime_error(
"Error in evaluate: LHS and RHS don't conform in OhmmsMatrix.");
537 #endif // OHMMS_PETE_MATRIX_H void resize(size_type n, Type_t val=Type_t())
Resize the container.
Container_t::iterator begin(int i)
void add(const This_t &sub, unsigned int i0, unsigned int j0)
Type_t operator()(size_type i) const
Container_t::iterator begin()
const Type_t * data(size_type i) const
Container_t::const_iterator begin() const
This_t & operator=(const RHS &rhs)
static bool apply(const Matrix< T, Alloc > &v, const SizeLeaf2 &s)
helper functions for EinsplineSetBuilder
static Type_t apply(const Matrix< T, Alloc > &mat, const EvalLeaf2 &f)
void attachReference(const CONTAINER &other, T *ref, size_type n, size_type m)
Attach to pre-allocated memory and propagate the allocator of the owning container.
typename Container_t::size_type size_type
const_pointer first_address() const
static bool apply(const Scalar< T > &, const SizeLeaf2 &)
Matrix(const CONTAINER &other, T *ref, size_type n, size_type m)
This allows construction of a Matrix on another containers owned memory that is using a dualspace all...
ForEach< Expr, FTag, CTag >::Type_t forEach(const Expr &e, const FTag &f, const CTag &c)
Matrix(size_type n, size_type m)
pointer device_data()
Return the device_ptr matching X if this is a vector attached or owning dual space memory...
void add(const T1 *sub, size_type d1, size_type d2, size_type i0, size_type j0, const T &phi)
void updateFrom(size_type size=0, std::ptrdiff_t offset=0)
void swap_rows(int r1, int r2)
void updateFrom(size_type size=0, std::ptrdiff_t offset=0)
bool operator==(const Matrix< T, Alloc > &lhs, const Matrix< T, Alloc > &rhs)
Container_t::const_iterator end() const
void resize(size_type n, size_type m)
Resize the container.
SizeLeaf2(size_type s, size_type p)
Type_t * operator[](size_type i)
returns a pointer of i-th row, g++ iterator problem
SizeLeaf2(const SizeLeaf2 &model)
Container_t::const_iterator begin(int i) const
Type_t * data(size_type i)
returns a pointer of i-th row, g++ iterator problem
void copy(const This_t &rhs)
const Type_t * operator[](size_type i) const
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
size_type extent(int i) const
void swap_cols(int c1, int c2)
void attachReference(T *ref, size_type n)
void updateTo(size_type size=0, std::ptrdiff_t offset=0)
bool operator()(size_type s, size_type p) const
void assignUpperLeft(const Matrix< T_FROM, ALLOC_FROM > &from)
This assigns from a matrix with larger row size (used for alignment) to whatever the rowsize is here...
Type_t & operator()(size_type i, size_type j)
void replaceRow(IT first, size_type i)
const ST * const_iterator
static Leaf_t make(const Matrix< T, Alloc > &a)
Matrix< T1, C1 > & assign(Matrix< T1, C1 > &lhs, const RHS &rhs)
typename Container_t::iterator iterator
Matrix(T *ref, size_type n, size_type m)
constructor with an initialized ref
const_pointer device_data() const
This_t & operator=(const This_t &rhs)
template class analogous to std::allocator_traits.
Matrix(const This_t &rhs)
const_pointer data() const
void attachReference(T *ref)
Declaraton of Vector<T,Alloc> Manage memory through Alloc directly and allow referencing an existing ...
const Type_t * last_address() const
void attachReference(T *ref, size_type n, size_type m)
const Type_t & operator()(size_type i, size_type j) const
void evaluate(Matrix< T, Alloc > &lhs, const Op &op, const Expression< RHS > &rhs)
void updateTo(size_type size=0, std::ptrdiff_t offset=0)
void add(const T1 *sub, size_type d1, size_type d2, size_type i0, size_type j0)
std::istream & operator>>(std::istream &is, Matrix< T, Alloc > &rhs)
void add(const SubMat_t &sub, unsigned int i0, unsigned int j0)
Container_t::iterator end()
typename Alloc::size_type size_type
void replaceColumn(IT first, size_type j)
size_type size(int i) const
Type_t & operator()(size_type i)
bool operator!=(const Matrix< T, Alloc > &lhs, const Matrix< T, Alloc > &rhs)
void add2Column(IT first, size_type j)