5 #ifndef GKO_PUBLIC_CORE_MATRIX_ELL_HPP_
6 #define GKO_PUBLIC_CORE_MATRIX_ELL_HPP_
9 #include <ginkgo/core/base/array.hpp>
10 #include <ginkgo/core/base/lin_op.hpp>
11 #include <ginkgo/core/matrix/device_views.hpp>
18 template <
typename ValueType>
21 template <
typename ValueType,
typename IndexType>
24 template <
typename ValueType,
typename IndexType>
27 template <
typename ValueType,
typename IndexType>
52 template <
typename ValueType = default_precision,
typename IndexType =
int32>
53 class Ell :
public EnableLinOp<Ell<ValueType, IndexType>>,
54 public ConvertibleTo<Ell<next_precision<ValueType>, IndexType>>,
55 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
56 public ConvertibleTo<Ell<next_precision<ValueType, 2>, IndexType>>,
58 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
59 public ConvertibleTo<Ell<next_precision<ValueType, 3>, IndexType>>,
61 public ConvertibleTo<Dense<ValueType>>,
62 public ConvertibleTo<Csr<ValueType, IndexType>>,
63 public DiagonalExtractable<ValueType>,
64 public ReadableFromMatrixData<ValueType, IndexType>,
65 public WritableToMatrixData<ValueType, IndexType>,
66 public EnableAbsoluteComputation<
67 remove_complex<Ell<ValueType, IndexType>>> {
68 friend class EnablePolymorphicObject<
Ell,
LinOp>;
69 friend class Dense<ValueType>;
70 friend class Coo<ValueType, IndexType>;
71 friend class Csr<ValueType, IndexType>;
74 friend class Hybrid<ValueType, IndexType>;
75 GKO_ASSERT_SUPPORTED_VALUE_AND_INDEX_TYPE;
80 using ConvertibleTo<Ell<next_precision<ValueType>, IndexType>>::convert_to;
81 using ConvertibleTo<Ell<next_precision<ValueType>, IndexType>>::move_to;
82 using ConvertibleTo<Dense<ValueType>>::convert_to;
83 using ConvertibleTo<Dense<ValueType>>::move_to;
84 using ConvertibleTo<Csr<ValueType, IndexType>>::convert_to;
85 using ConvertibleTo<Csr<ValueType, IndexType>>::move_to;
88 using value_type = ValueType;
89 using index_type = IndexType;
90 using mat_data = matrix_data<ValueType, IndexType>;
91 using device_mat_data = device_matrix_data<ValueType, IndexType>;
92 using absolute_type = remove_complex<Ell>;
93 using device_view = matrix::view::ell<value_type, index_type>;
94 using const_device_view =
95 matrix::view::ell<const value_type, const index_type>;
98 Ell<next_precision<ValueType>, IndexType>* result)
const override;
100 void move_to(
Ell<next_precision<ValueType>, IndexType>* result)
override;
102 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
105 Ell<next_precision<ValueType, 2>, IndexType>>::convert_to;
106 using ConvertibleTo<Ell<next_precision<ValueType, 2>, IndexType>>::move_to;
109 Ell<next_precision<ValueType, 2>, IndexType>* result)
const override;
111 void move_to(
Ell<next_precision<ValueType, 2>, IndexType>* result)
override;
114 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
117 Ell<next_precision<ValueType, 3>, IndexType>>::convert_to;
118 using ConvertibleTo<Ell<next_precision<ValueType, 3>, IndexType>>::move_to;
121 Ell<next_precision<ValueType, 3>, IndexType>* result)
const override;
123 void move_to(
Ell<next_precision<ValueType, 3>, IndexType>* result)
override;
126 void convert_to(Dense<ValueType>* other)
const override;
128 void move_to(Dense<ValueType>* other)
override;
130 void convert_to(Csr<ValueType, IndexType>* other)
const override;
132 void move_to(Csr<ValueType, IndexType>* other)
override;
134 void read(
const mat_data& data)
override;
136 void read(
const device_mat_data& data)
override;
138 void read(device_mat_data&& data)
override;
140 void write(mat_data& data)
const override;
193 return num_stored_elements_per_row_;
225 return values_.
get_data()[this->linearize_index(row, idx)];
248 return this->
get_col_idxs()[this->linearize_index(row, idx)];
276 static std::unique_ptr<Ell>
create(
277 std::shared_ptr<const Executor> exec,
const dim<2>& size = {},
299 static std::unique_ptr<Ell>
create(std::shared_ptr<const Executor> exec,
311 template <
typename InputValueType,
typename InputColumnIndexType>
313 "explicitly construct the gko::array argument instead of passing "
316 std::shared_ptr<const
Executor> exec, const
dim<2>& size,
317 std::initializer_list<InputValueType> values,
318 std::initializer_list<InputColumnIndexType> col_idxs,
323 num_stored_elements_per_row, stride);
340 std::shared_ptr<const Executor> exec,
const dim<2>& size,
341 gko::detail::const_array_view<ValueType>&& values,
342 gko::detail::const_array_view<IndexType>&& col_idxs,
372 Ell(std::shared_ptr<const Executor> exec,
const dim<2>& size = {},
375 Ell(std::shared_ptr<const Executor> exec,
const dim<2>& size,
390 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
393 LinOp* x)
const override;
397 return row + stride_ * col;
403 array<value_type> values_;
404 array<index_type> col_idxs_;
412 #endif // GKO_PUBLIC_CORE_MATRIX_ELL_HPP_