33 #ifndef GKO_CORE_MATRIX_ELL_HPP_ 34 #define GKO_CORE_MATRIX_ELL_HPP_ 37 #include <ginkgo/core/base/array.hpp> 38 #include <ginkgo/core/base/lin_op.hpp> 45 template <
typename ValueType>
48 template <
typename ValueType,
typename IndexType>
70 template <
typename ValueType = default_precision,
typename IndexType =
int32>
71 class Ell :
public EnableLinOp<Ell<ValueType, IndexType>>,
72 public EnableCreateMethod<Ell<ValueType, IndexType>>,
73 public ConvertibleTo<Dense<ValueType>>,
74 public ConvertibleTo<Csr<ValueType, IndexType>>,
75 public ReadableFromMatrixData<ValueType, IndexType>,
76 public WritableToMatrixData<ValueType, IndexType> {
77 friend class EnableCreateMethod<Ell>;
78 friend class EnablePolymorphicObject<Ell, LinOp>;
79 friend class Dense<ValueType>;
80 friend class Csr<ValueType, IndexType>;
86 using value_type = ValueType;
87 using index_type = IndexType;
88 using mat_data = matrix_data<ValueType, IndexType>;
90 void convert_to(Dense<ValueType> *other)
const override;
92 void move_to(Dense<ValueType> *other)
override;
94 void convert_to(Csr<ValueType, IndexType> *other)
const override;
96 void move_to(Csr<ValueType, IndexType> *other)
override;
98 void read(
const mat_data &data)
override;
100 void write(mat_data &data)
const override;
147 return num_stored_elements_per_row_;
179 return values_.
get_data()[this->linearize_index(row, idx)];
202 return this->
get_col_idxs()[this->linearize_index(row, idx)];
223 Ell(std::shared_ptr<const Executor> exec,
const dim<2> &size =
dim<2>{})
224 :
Ell(std::move(exec), size, size[1])
236 Ell(std::shared_ptr<const Executor> exec,
const dim<2> &size,
238 :
Ell(std::move(exec), size, num_stored_elements_per_row, size[0])
250 Ell(std::shared_ptr<const Executor> exec,
const dim<2> &size,
253 values_(exec, stride * num_stored_elements_per_row),
254 col_idxs_(exec, stride * num_stored_elements_per_row),
255 num_stored_elements_per_row_(num_stored_elements_per_row),
280 template <
typename ValuesArray,
typename ColIdxsArray>
281 Ell(std::shared_ptr<const Executor> exec,
const dim<2> &size,
282 ValuesArray &&values, ColIdxsArray &&col_idxs,
285 values_{exec, std::forward<ValuesArray>(values)},
286 col_idxs_{exec, std::forward<ColIdxsArray>(col_idxs)},
287 num_stored_elements_per_row_{num_stored_elements_per_row},
290 GKO_ENSURE_IN_BOUNDS(num_stored_elements_per_row_ * stride_ - 1,
292 GKO_ENSURE_IN_BOUNDS(num_stored_elements_per_row_ * stride_ - 1,
296 void apply_impl(
const LinOp *b,
LinOp *x)
const override;
299 LinOp *x)
const override;
303 return row + stride_ * col;
318 #endif // GKO_CORE_MATRIX_ELL_HPP_ value_type * get_values() noexcept
Returns the values of the matrix.
Definition: ell.hpp:107
void write(mat_data &data) const override
Writes a matrix to a matrix_data structure.
void read(const mat_data &data) override
Reads a matrix from a matrix_data structure.
size_type get_num_elems() const noexcept
Returns the number of elements in the Array.
Definition: array.hpp:388
value_type val_at(size_type row, size_type idx) const noexcept
Returns the idx-th non-zero element of the row-th row .
Definition: ell.hpp:185
ELL is a matrix format where stride with explicit zeros is used such that all rows have the same numb...
Definition: csr.hpp:53
value_type & val_at(size_type row, size_type idx) noexcept
Returns the idx-th non-zero element of the row-th row .
Definition: ell.hpp:177
index_type * get_col_idxs() noexcept
Returns the column indexes of the matrix.
Definition: ell.hpp:126
const index_type * get_const_col_idxs() const noexcept
Returns the column indexes of the matrix.
Definition: ell.hpp:135
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:94
const value_type * get_const_data() const noexcept
Returns a constant pointer to the block of memory used to store the elements of the Array...
Definition: array.hpp:406
The Ginkgo namespace.
Definition: abstract_factory.hpp:45
size_type get_num_stored_elements() const noexcept
Returns the number of elements explicitly stored in the matrix.
Definition: ell.hpp:162
index_type & col_at(size_type row, size_type idx) noexcept
Returns the idx-th column index of the row-th row .
Definition: ell.hpp:200
Definition: lin_op.hpp:134
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition: lin_op.hpp:509
void convert_to(result_type *result) const override
Definition: polymorphic_object.hpp:558
void move_to(result_type *result) override
Definition: polymorphic_object.hpp:560
const value_type * get_const_values() const noexcept
Returns the values of the matrix.
Definition: ell.hpp:116
size_type get_num_stored_elements_per_row() const noexcept
Returns the number of stored elements per row.
Definition: ell.hpp:145
value_type * get_data() noexcept
Returns a pointer to the block of memory used to store the elements of the Array. ...
Definition: array.hpp:397
index_type col_at(size_type row, size_type idx) const noexcept
Returns the idx-th column index of the row-th row .
Definition: ell.hpp:208
size_type get_stride() const noexcept
Returns the stride of the matrix.
Definition: ell.hpp:155