12 #ifndef THRILL_COMMON_MATRIX_HEADER 13 #define THRILL_COMMON_MATRIX_HEADER 28 template <
typename Type>
42 :
Matrix(rows_columns, rows_columns, initial) { }
45 Matrix(
size_t rows,
size_t columns, std::vector<Type>&&
data)
64 const Type&
at(
size_t row,
size_t column)
const {
71 Type&
at(
size_t row,
size_t column) {
79 return at(row, column);
84 return at(row, column);
91 data_.begin(),
data_.begin(), std::plus<Type>());
104 std::for_each(
data_.begin(),
data_.end(), [&s](
Type& t) { t *= s; });
110 if (
rows() != b.rows() ||
columns() != b.columns())
return false;
111 return std::equal(
data_.begin(),
data_.end(), b.data_.begin());
125 template <
typename Archive>
127 ar.template Put<size_t>(
rows_);
129 for (
typename std::vector<Type>::const_iterator it =
data_.begin();
130 it !=
data_.end(); ++it) {
136 template <
typename Archive>
138 size_t rows = ar.template Get<size_t>();
139 size_t columns = ar.template Get<size_t>();
140 std::vector<Type>
data;
142 data.reserve(rows * columns);
143 for (
size_t i = 0; i < rows *
columns; ++i) {
147 return Matrix(rows, columns, std::move(data));
163 #endif // !THRILL_COMMON_MATRIX_HEADER static Matrix ThrillDeserialize(Archive &ar)
deserialization with Thrill's serializer
Matrix()=default
empty matrix constructor
Matrix(size_t rows_columns, const Type &initial=Type())
constructor of square n times n matrix.
Matrix & operator*=(const Type &s)
multiply matrix with a scalar
bool operator==(const Matrix &b) const noexcept
equality operator
const Type & operator()(size_t row, size_t column) const
return const reference to element at cell
void ThrillSerialize(Archive &ar) const
serialization with Thrill's serializer
A simple m x n dense matrix for generating statistics.
Type & at(size_t row, size_t column)
return reference to element at cell
Matrix(size_t rows, size_t columns, std::vector< Type > &&data)
constructor of m times n matrix from appropriate vector
std::vector< Type > data_
data of matrix.
size_t rows_
number of rows in matrix
const Type & at(size_t row, size_t column) const
return const reference to element at cell
static constexpr size_t thrill_fixed_size
static constexpr bool thrill_is_fixed_size
size_t columns_
number of columns in matrix
size_t size() const
size of matrix raw data (rows * columns)
Matrix operator+(const Matrix &b) const
add matrix to this one, returning result as a new matrix
size_t columns() const
number of columns in matrix
Matrix(size_t rows, size_t columns, const Type &initial=Type())
constructor of m times n matrix.
Type * data() const
raw data of matrix
Matrix & operator+=(const Matrix &b)
add matrix to this one
bool operator!=(const Matrix &b) const noexcept
inequality operator
size_t rows() const
number of rows in matrix