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 EnableLinOp<SparsityCsr<ValueType, IndexType>>,
52 public ConvertibleTo<Csr<ValueType, IndexType>>,
53 public ConvertibleTo<Dense<ValueType>>,
54 public ReadableFromMatrixData<ValueType, IndexType>,
55 public WritableToMatrixData<ValueType, IndexType>,
58 friend class Csr<ValueType, IndexType>;
59 friend class Dense<ValueType>;
60 friend class Fbcsr<ValueType, IndexType>;
65 using ConvertibleTo<Csr<ValueType, IndexType>>::convert_to;
66 using ConvertibleTo<Csr<ValueType, IndexType>>::move_to;
67 using ConvertibleTo<Dense<ValueType>>::convert_to;
68 using ConvertibleTo<Dense<ValueType>>::move_to;
71 using value_type = ValueType;
72 using index_type = IndexType;
73 using transposed_type = SparsityCsr<IndexType, ValueType>;
74 using mat_data = matrix_data<ValueType, IndexType>;
75 using device_mat_data = device_matrix_data<ValueType, IndexType>;
77 void convert_to(Csr<ValueType, IndexType>* result)
const override;
79 void move_to(Csr<ValueType, IndexType>* result)
override;
81 void convert_to(Dense<ValueType>* result)
const override;
83 void move_to(Dense<ValueType>* result)
override;
85 void read(
const mat_data& data)
override;
87 void read(
const device_mat_data& data)
override;
89 void read(device_mat_data&& data)
override;
91 void write(mat_data& data)
const override;
93 std::unique_ptr<LinOp>
transpose()
const override;
118 bool is_sorted_by_column_index()
const;
191 static std::unique_ptr<SparsityCsr>
create(
192 std::shared_ptr<const Executor> exec,
const dim<2>& size =
dim<2>{},
214 static std::unique_ptr<SparsityCsr>
create(
215 std::shared_ptr<const Executor> exec,
const dim<2>& size,
216 array<index_type> col_idxs, array<index_type> row_ptrs,
217 value_type value = one<ValueType>());
224 template <
typename ColIndexType,
typename RowPtrType>
226 "explicitly construct the gko::array argument instead of passing "
229 std::shared_ptr<const
Executor> exec, const
dim<2>& size,
230 std::initializer_list<ColIndexType> col_idxs,
231 std::initializer_list<RowPtrType> row_ptrs,
232 value_type value =
one<ValueType>())
245 static std::unique_ptr<SparsityCsr>
create(
246 std::shared_ptr<const Executor> exec,
247 std::shared_ptr<const LinOp> matrix);
263 std::shared_ptr<const Executor> exec,
const dim<2>& size,
264 gko::detail::const_array_view<IndexType>&& col_idxs,
265 gko::detail::const_array_view<IndexType>&& row_ptrs,
266 ValueType value = one<ValueType>())
270 return std::unique_ptr<const SparsityCsr>(
new SparsityCsr{
271 exec, size, gko::detail::array_const_cast(std::move(col_idxs)),
272 gko::detail::array_const_cast(std::move(row_ptrs)), value});
305 SparsityCsr(std::shared_ptr<const Executor> exec,
const dim<2>& size,
306 array<index_type> col_idxs, array<index_type> row_ptrs,
307 value_type value = one<ValueType>());
310 std::shared_ptr<const LinOp> matrix);
312 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
315 LinOp* x)
const override;
318 array<index_type> col_idxs_;
319 array<index_type> row_ptrs_;
320 array<value_type> value_;
328 #endif // GKO_PUBLIC_CORE_MATRIX_SPARSITY_CSR_HPP_