5 #ifndef GKO_PUBLIC_CORE_MATRIX_SPARSITY_CSR_HPP_
6 #define GKO_PUBLIC_CORE_MATRIX_SPARSITY_CSR_HPP_
12 #include <ginkgo/core/base/array.hpp>
13 #include <ginkgo/core/base/lin_op.hpp>
14 #include <ginkgo/core/base/polymorphic_object.hpp>
21 template <
typename ValueType,
typename IndexType>
25 template <
typename ValueType>
29 template <
typename ValueType,
typename IndexType>
51 template <
typename ValueType = default_precision,
typename IndexType =
int32>
52 class SparsityCsr :
public EnableLinOp<SparsityCsr<ValueType, IndexType>>,
53 public ConvertibleTo<Csr<ValueType, IndexType>>,
54 public ConvertibleTo<Dense<ValueType>>,
55 public ReadableFromMatrixData<ValueType, IndexType>,
56 public WritableToMatrixData<ValueType, IndexType>,
59 friend class Csr<ValueType, IndexType>;
60 friend class Dense<ValueType>;
61 friend class Fbcsr<ValueType, IndexType>;
66 using ConvertibleTo<Csr<ValueType, IndexType>>::convert_to;
67 using ConvertibleTo<Csr<ValueType, IndexType>>::move_to;
68 using ConvertibleTo<Dense<ValueType>>::convert_to;
69 using ConvertibleTo<Dense<ValueType>>::move_to;
72 using value_type = ValueType;
73 using index_type = IndexType;
74 using transposed_type = SparsityCsr<IndexType, ValueType>;
75 using mat_data = matrix_data<ValueType, IndexType>;
76 using device_mat_data = device_matrix_data<ValueType, IndexType>;
78 void convert_to(Csr<ValueType, IndexType>* result)
const override;
80 void move_to(Csr<ValueType, IndexType>* result)
override;
82 void convert_to(Dense<ValueType>* result)
const override;
84 void move_to(Dense<ValueType>* result)
override;
86 void read(
const mat_data& data)
override;
88 void read(
const device_mat_data& data)
override;
90 void read(device_mat_data&& data)
override;
92 void write(mat_data& data)
const override;
94 std::unique_ptr<LinOp>
transpose()
const override;
119 bool is_sorted_by_column_index()
const;
192 static std::unique_ptr<SparsityCsr>
create(
193 std::shared_ptr<const Executor> exec,
const dim<2>& size =
dim<2>{},
215 static std::unique_ptr<SparsityCsr>
create(
216 std::shared_ptr<const Executor> exec,
const dim<2>& size,
217 array<index_type> col_idxs, array<index_type> row_ptrs,
218 value_type value = one<ValueType>());
225 template <
typename ColIndexType,
typename RowPtrType>
227 "explicitly construct the gko::array argument instead of passing "
230 std::shared_ptr<const
Executor> exec, const
dim<2>& size,
231 std::initializer_list<ColIndexType> col_idxs,
232 std::initializer_list<RowPtrType> row_ptrs,
233 value_type value =
one<ValueType>())
246 static std::unique_ptr<SparsityCsr>
create(
247 std::shared_ptr<const Executor> exec,
248 std::shared_ptr<const LinOp> matrix);
264 std::shared_ptr<const Executor> exec,
const dim<2>& size,
265 gko::detail::const_array_view<IndexType>&& col_idxs,
266 gko::detail::const_array_view<IndexType>&& row_ptrs,
267 ValueType value = one<ValueType>())
271 return std::unique_ptr<const SparsityCsr>(
new SparsityCsr{
272 exec, size, gko::detail::array_const_cast(std::move(col_idxs)),
273 gko::detail::array_const_cast(std::move(row_ptrs)), value});
306 SparsityCsr(std::shared_ptr<const Executor> exec,
const dim<2>& size,
307 array<index_type> col_idxs, array<index_type> row_ptrs,
308 value_type value = one<ValueType>());
311 std::shared_ptr<const LinOp> matrix);
313 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
316 LinOp* x)
const override;
319 array<index_type> col_idxs_;
320 array<index_type> row_ptrs_;
321 array<value_type> value_;
329 #endif // GKO_PUBLIC_CORE_MATRIX_SPARSITY_CSR_HPP_