33 #ifndef GKO_CORE_MATRIX_SELLP_HPP_ 34 #define GKO_CORE_MATRIX_SELLP_HPP_ 37 #include <ginkgo/core/base/array.hpp> 38 #include <ginkgo/core/base/lin_op.hpp> 45 constexpr
int default_slice_size = 64;
46 constexpr
int default_stride_factor = 1;
49 template <
typename ValueType>
52 template <
typename ValueType,
typename IndexType>
67 template <
typename ValueType = default_precision,
typename IndexType =
int32>
68 class Sellp :
public EnableLinOp<Sellp<ValueType, IndexType>>,
69 public EnableCreateMethod<Sellp<ValueType, IndexType>>,
70 public ConvertibleTo<Dense<ValueType>>,
71 public ConvertibleTo<Csr<ValueType, IndexType>>,
72 public ReadableFromMatrixData<ValueType, IndexType>,
73 public WritableToMatrixData<ValueType, IndexType> {
74 friend class EnableCreateMethod<Sellp>;
75 friend class EnablePolymorphicObject<Sellp, LinOp>;
76 friend class Dense<ValueType>;
77 friend class Csr<ValueType, IndexType>;
83 using value_type = ValueType;
84 using index_type = IndexType;
85 using mat_data = matrix_data<ValueType, IndexType>;
87 void convert_to(Dense<ValueType> *other)
const override;
89 void move_to(Dense<ValueType> *other)
override;
91 void convert_to(Csr<ValueType, IndexType> *other)
const override;
93 void move_to(Csr<ValueType, IndexType> *other)
override;
95 void read(
const mat_data &data)
override;
97 void write(mat_data &data)
const override;
224 return values_.
get_data()[this->linearize_index(row, slice_set, idx)];
252 return this->
get_col_idxs()[this->linearize_index(row, slice_set, idx)];
262 ->get_const_col_idxs()[this->linearize_index(row, slice_set, idx)];
275 :
Sellp(std::move(exec), size,
276 ceildiv(size[0], default_slice_size) * size[1])
287 Sellp(std::shared_ptr<const Executor> exec,
const dim<2> &size,
289 :
Sellp(std::move(exec), size, default_slice_size,
290 default_stride_factor, total_cols)
303 Sellp(std::shared_ptr<const Executor> exec,
const dim<2> &size,
306 values_(exec, slice_size * total_cols),
307 col_idxs_(exec, slice_size * total_cols),
309 (size[0] == 0) ? 0 :
ceildiv(size[0], slice_size)),
311 (size[0] == 0) ? 0 :
ceildiv(size[0], slice_size) + 1),
312 slice_size_(slice_size),
313 stride_factor_(stride_factor),
314 total_cols_(total_cols)
317 void apply_impl(
const LinOp *b,
LinOp *x)
const override;
320 LinOp *x)
const override;
325 return (slice_set + col) * slice_size_ + row;
343 #endif // GKO_CORE_MATRIX_SELLP_HPP_ constexpr int64 ceildiv(int64 num, int64 den)
Performs integer division with rounding up.
Definition: math.hpp:280
value_type & val_at(size_type row, size_type slice_set, size_type idx) noexcept
Returns the idx-th non-zero element of the row-th row with slice_set slice set.
Definition: sellp.hpp:221
size_type get_num_elems() const noexcept
Returns the number of elements in the Array.
Definition: array.hpp:388
void read(const mat_data &data) override
Reads a matrix from a matrix_data structure.
index_type col_at(size_type row, size_type slice_set, size_type idx) const noexcept
Returns the idx-th column index of the row-th row with slice_set slice set.
Definition: sellp.hpp:258
size_type get_total_cols() const noexcept
Returns the total column number.
Definition: sellp.hpp:197
const size_type * get_const_slice_sets() const noexcept
Returns the offsets of slices.
Definition: sellp.hpp:173
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_slice_size() const noexcept
Returns the size of a slice.
Definition: sellp.hpp:183
index_type & col_at(size_type row, size_type slice_set, size_type idx) noexcept
Returns the idx-th column index of the row-th row with slice_set slice set.
Definition: sellp.hpp:249
value_type * get_values() noexcept
Returns the values of the matrix.
Definition: sellp.hpp:104
SELL-P is a matrix format similar to ELL format.
Definition: csr.hpp:57
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 write(mat_data &data) const override
Writes a matrix to a matrix_data structure.
const index_type * get_const_col_idxs() const noexcept
Returns the column indexes of the matrix.
Definition: sellp.hpp:132
const value_type * get_const_values() const noexcept
Returns the values of the matrix.
Definition: sellp.hpp:113
size_type * get_slice_lengths() noexcept
Returns the lengths(columns) of slices.
Definition: sellp.hpp:142
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
size_type * get_slice_sets() noexcept
Returns the offsets of slices.
Definition: sellp.hpp:164
size_type get_stride_factor() const noexcept
Returns the stride factor(t) of SELL-P.
Definition: sellp.hpp:190
index_type * get_col_idxs() noexcept
Returns the column indexes of the matrix.
Definition: sellp.hpp:123
const size_type * get_const_slice_lengths() const noexcept
Returns the lengths(columns) of slices.
Definition: sellp.hpp:154
size_type get_num_stored_elements() const noexcept
Returns the number of elements explicitly stored in the matrix.
Definition: sellp.hpp:204
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
value_type val_at(size_type row, size_type slice_set, size_type idx) const noexcept
Returns the idx-th non-zero element of the row-th row with slice_set slice set.
Definition: sellp.hpp:230