4#include "yas/serialize.hpp"
5#include "yas/std_types.hpp"
11template <
typename Ttype>
22 std::fill(is_changed.begin(), is_changed.end(),
false);
25 template <
typename OtherTtype>
30 std::fill(is_changed.begin(), is_changed.end(),
false);
31 tensors.resize(other.
size());
32 for(
auto it = other.
cbegin(); it != other.
cend(); ++it) { tensors[std::distance(other.
cbegin(), it)] = *it; }
38 inline std::size_t
size()
const {
return tensors.size(); }
49 is_changed[index] =
true;
50 return tensors[index];
52 inline const Ttype&
operator[](
const std::size_t index)
const {
return tensors[index]; }
53 inline const Ttype&
at(
const std::size_t index)
const {
return tensors.at(index); }
56 inline void resetChange() { std::fill(is_changed.begin(), is_changed.end(),
false); }
64 std::fill(is_changed.begin(), is_changed.end(),
false);
67 auto begin() {
return tensors.begin(); }
68 auto end() {
return tensors.end(); }
70 auto cbegin()
const {
return tensors.cbegin(); }
71 auto cend()
const {
return tensors.cend(); }
73 void fill(
const std::vector<Ttype>& tensors_in) { tensors = tensors_in; }
75 void setConstant(
const Ttype& val) { std::fill(tensors.begin(), tensors.end(), val); }
77 Ttype
sum()
const {
return std::accumulate(tensors.begin(), tensors.end(), Ttype(0.)); }
79 template <
typename Ar>
82 ar& YAS_OBJECT_NVP(
"TMatrix", (
"pattern",
pat), (
"tensors", tensors), (
"is_changed", is_changed), (
"name", name));
87 std::vector<Ttype> out(
pat.
size());
88 for(
int x = 0; x <
pat.
Lx; ++x) {
96 std::vector<Ttype> tensors;
97 std::vector<bool> is_changed;
98 std::string name =
"";
Definition: Pattern.hpp:18
std::size_t Ly
Definition: Pattern.hpp:72
std::size_t Lx
Definition: Pattern.hpp:72
std::size_t uniqueSize() const
Definition: Pattern.hpp:43
std::size_t size() const
Definition: Pattern.hpp:44
std::size_t uniqueIndex(const int x, const int y) const
Definition: Pattern.cpp:66
Definition: TMatrix.hpp:13
Ttype sum() const
Definition: TMatrix.hpp:77
auto cbegin() const
Definition: TMatrix.hpp:70
std::size_t size() const
Definition: TMatrix.hpp:38
TMatrix(const Pattern &pat, const std::string name="")
Definition: TMatrix.hpp:16
const Ttype & at(const std::size_t index) const
Definition: TMatrix.hpp:53
auto end()
Definition: TMatrix.hpp:68
void serialize(Ar &ar)
Definition: TMatrix.hpp:80
const Ttype & operator()(const int row, const int col) const
Definition: TMatrix.hpp:45
TMatrix(const TMatrix< OtherTtype > &other)
Definition: TMatrix.hpp:26
std::vector< Ttype > uncompressedVector() const
Definition: TMatrix.hpp:85
void resize(const Pattern &pattern)
Definition: TMatrix.hpp:58
Ttype & operator[](const std::size_t index)
Definition: TMatrix.hpp:47
auto begin()
Definition: TMatrix.hpp:67
std::size_t cols() const
Definition: TMatrix.hpp:36
Ttype & operator()(const int row, const int col)
Definition: TMatrix.hpp:40
void resetChange()
Definition: TMatrix.hpp:56
void setConstant(const Ttype &val)
Definition: TMatrix.hpp:75
Pattern pat
Definition: TMatrix.hpp:93
bool isChanged(const int row, const int col) const
Definition: TMatrix.hpp:55
std::size_t rows() const
Definition: TMatrix.hpp:35
void fill(const std::vector< Ttype > &tensors_in)
Definition: TMatrix.hpp:73
auto cend() const
Definition: TMatrix.hpp:71
const Ttype & operator[](const std::size_t index) const
Definition: TMatrix.hpp:52