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>
17 template <
typename ValueType>
20 template <
typename ValueType,
typename IndexType>
23 template <
typename ValueType,
typename IndexType>
26 template <
typename ValueType,
typename IndexType>
51 template <
typename ValueType = default_precision,
typename IndexType =
int32>
52 class Ell :
public EnableLinOp<Ell<ValueType, IndexType>>,
53 public ConvertibleTo<Ell<next_precision<ValueType>, IndexType>>,
54 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
55 public ConvertibleTo<Ell<next_precision<ValueType, 2>, IndexType>>,
57 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
58 public ConvertibleTo<Ell<next_precision<ValueType, 3>, IndexType>>,
60 public ConvertibleTo<Dense<ValueType>>,
61 public ConvertibleTo<Csr<ValueType, IndexType>>,
62 public DiagonalExtractable<ValueType>,
63 public ReadableFromMatrixData<ValueType, IndexType>,
64 public WritableToMatrixData<ValueType, IndexType>,
65 public EnableAbsoluteComputation<
66 remove_complex<Ell<ValueType, IndexType>>> {
67 friend class EnablePolymorphicObject<
Ell,
LinOp>;
68 friend class Dense<ValueType>;
69 friend class Coo<ValueType, IndexType>;
70 friend class Csr<ValueType, IndexType>;
73 friend class Hybrid<ValueType, IndexType>;
78 using ConvertibleTo<Ell<next_precision<ValueType>, IndexType>>::convert_to;
79 using ConvertibleTo<Ell<next_precision<ValueType>, IndexType>>::move_to;
80 using ConvertibleTo<Dense<ValueType>>::convert_to;
81 using ConvertibleTo<Dense<ValueType>>::move_to;
82 using ConvertibleTo<Csr<ValueType, IndexType>>::convert_to;
83 using ConvertibleTo<Csr<ValueType, IndexType>>::move_to;
86 using value_type = ValueType;
87 using index_type = IndexType;
88 using mat_data = matrix_data<ValueType, IndexType>;
89 using device_mat_data = device_matrix_data<ValueType, IndexType>;
90 using absolute_type = remove_complex<Ell>;
93 Ell<next_precision<ValueType>, IndexType>* result)
const override;
95 void move_to(
Ell<next_precision<ValueType>, IndexType>* result)
override;
97 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
100 Ell<next_precision<ValueType, 2>, IndexType>>::convert_to;
101 using ConvertibleTo<Ell<next_precision<ValueType, 2>, IndexType>>::move_to;
104 Ell<next_precision<ValueType, 2>, IndexType>* result)
const override;
106 void move_to(
Ell<next_precision<ValueType, 2>, IndexType>* result)
override;
109 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
112 Ell<next_precision<ValueType, 3>, IndexType>>::convert_to;
113 using ConvertibleTo<Ell<next_precision<ValueType, 3>, IndexType>>::move_to;
116 Ell<next_precision<ValueType, 3>, IndexType>* result)
const override;
118 void move_to(
Ell<next_precision<ValueType, 3>, IndexType>* result)
override;
121 void convert_to(Dense<ValueType>* other)
const override;
123 void move_to(Dense<ValueType>* other)
override;
125 void convert_to(Csr<ValueType, IndexType>* other)
const override;
127 void move_to(Csr<ValueType, IndexType>* other)
override;
129 void read(
const mat_data& data)
override;
131 void read(
const device_mat_data& data)
override;
133 void read(device_mat_data&& data)
override;
135 void write(mat_data& data)
const override;
188 return num_stored_elements_per_row_;
220 return values_.
get_data()[this->linearize_index(row, idx)];
243 return this->
get_col_idxs()[this->linearize_index(row, idx)];
265 static std::unique_ptr<Ell>
create(
266 std::shared_ptr<const Executor> exec,
const dim<2>& size = {},
288 static std::unique_ptr<Ell>
create(std::shared_ptr<const Executor> exec,
300 template <
typename InputValueType,
typename InputColumnIndexType>
302 "explicitly construct the gko::array argument instead of passing "
305 std::shared_ptr<const
Executor> exec, const
dim<2>& size,
306 std::initializer_list<InputValueType> values,
307 std::initializer_list<InputColumnIndexType> col_idxs,
312 num_stored_elements_per_row, stride);
329 std::shared_ptr<const Executor> exec,
const dim<2>& size,
330 gko::detail::const_array_view<ValueType>&& values,
331 gko::detail::const_array_view<IndexType>&& col_idxs,
361 Ell(std::shared_ptr<const Executor> exec,
const dim<2>& size = {},
364 Ell(std::shared_ptr<const Executor> exec,
const dim<2>& size,
379 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
382 LinOp* x)
const override;
386 return row + stride_ * col;
392 array<value_type> values_;
393 array<index_type> col_idxs_;
401 #endif // GKO_PUBLIC_CORE_MATRIX_ELL_HPP_