5 #ifndef GKO_PUBLIC_CORE_MATRIX_SPARSITY_CSR_HPP_
6 #define GKO_PUBLIC_CORE_MATRIX_SPARSITY_CSR_HPP_
11 #include <ginkgo/core/base/array.hpp>
12 #include <ginkgo/core/base/lin_op.hpp>
13 #include <ginkgo/core/base/polymorphic_object.hpp>
20 template <
typename ValueType,
typename IndexType>
24 template <
typename ValueType>
28 template <
typename ValueType,
typename IndexType>
50 template <
typename ValueType = default_precision,
typename IndexType =
int32>
51 class SparsityCsr :
public LinOp,
52 public EnableCloneable<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>;
62 GKO_ASSERT_SUPPORTED_VALUE_AND_INDEX_TYPE;
67 using ConvertibleTo<Csr<ValueType, IndexType>>::convert_to;
68 using ConvertibleTo<Csr<ValueType, IndexType>>::move_to;
69 using ConvertibleTo<Dense<ValueType>>::convert_to;
70 using ConvertibleTo<Dense<ValueType>>::move_to;
73 using value_type = ValueType;
74 using index_type = IndexType;
75 using transposed_type = SparsityCsr<IndexType, ValueType>;
76 using mat_data = matrix_data<ValueType, IndexType>;
77 using device_mat_data = device_matrix_data<ValueType, IndexType>;
79 void convert_to(Csr<ValueType, IndexType>* result)
const override;
81 void move_to(Csr<ValueType, IndexType>* result)
override;
83 void convert_to(Dense<ValueType>* result)
const override;
85 void move_to(Dense<ValueType>* result)
override;
87 void read(
const mat_data& data)
override;
89 void read(
const device_mat_data& data)
override;
91 void read(device_mat_data&& data)
override;
93 void write(mat_data& data)
const override;
95 std::unique_ptr<LinOp>
transpose()
const override;
120 bool is_sorted_by_column_index()
const;
193 static std::unique_ptr<SparsityCsr>
create(
194 std::shared_ptr<const Executor> exec,
const dim<2>& size =
dim<2>{},
216 static std::unique_ptr<SparsityCsr>
create(
217 std::shared_ptr<const Executor> exec,
const dim<2>& size,
218 array<index_type> col_idxs, array<index_type> row_ptrs,
219 value_type value = one<ValueType>());
226 template <
typename ColIndexType,
typename RowPtrType>
228 "explicitly construct the gko::array argument instead of passing "
231 std::shared_ptr<const
Executor> exec, const
dim<2>& size,
232 std::initializer_list<ColIndexType> col_idxs,
233 std::initializer_list<RowPtrType> row_ptrs,
234 value_type value =
one<ValueType>())
247 static std::unique_ptr<SparsityCsr>
create(
248 std::shared_ptr<const Executor> exec,
249 std::shared_ptr<const LinOp> matrix);
265 std::shared_ptr<const Executor> exec,
const dim<2>& size,
266 gko::detail::const_array_view<IndexType>&& col_idxs,
267 gko::detail::const_array_view<IndexType>&& row_ptrs,
268 ValueType value = one<ValueType>())
272 return std::unique_ptr<const SparsityCsr>(
new SparsityCsr{
273 exec, size, gko::detail::array_const_cast(std::move(col_idxs)),
274 gko::detail::array_const_cast(std::move(row_ptrs)), value});
307 SparsityCsr(std::shared_ptr<const Executor> exec,
const dim<2>& size,
308 array<index_type> col_idxs, array<index_type> row_ptrs,
309 value_type value = one<ValueType>());
312 std::shared_ptr<const LinOp> matrix);
314 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
317 LinOp* x)
const override;
320 array<index_type> col_idxs_;
321 array<index_type> row_ptrs_;
322 array<value_type> value_;
330 #endif // GKO_PUBLIC_CORE_MATRIX_SPARSITY_CSR_HPP_