5 #ifndef GKO_PUBLIC_CORE_MATRIX_DIAGONAL_HPP_
6 #define GKO_PUBLIC_CORE_MATRIX_DIAGONAL_HPP_
9 #include <ginkgo/core/base/array.hpp>
10 #include <ginkgo/core/base/lin_op.hpp>
17 template <
typename ValueType,
typename IndexType>
20 template <
typename ValueType>
39 template <
typename ValueType = default_precision>
42 public EnableCloneable<Diagonal<ValueType>>,
43 public ConvertibleTo<Csr<ValueType, int32>>,
44 public ConvertibleTo<Csr<ValueType, int64>>,
45 public ConvertibleTo<Diagonal<next_precision<ValueType>>>,
46 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
47 public ConvertibleTo<Diagonal<next_precision<ValueType, 2>>>,
49 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
50 public ConvertibleTo<Diagonal<next_precision<ValueType, 3>>>,
53 public WritableToMatrixData<ValueType, int32>,
54 public WritableToMatrixData<ValueType, int64>,
55 public ReadableFromMatrixData<ValueType, int32>,
56 public ReadableFromMatrixData<ValueType, int64>,
57 public EnableAbsoluteComputation<remove_complex<Diagonal<ValueType>>> {
58 friend class EnableCloneable<Diagonal>;
59 friend class Csr<ValueType,
int32>;
60 friend class Csr<ValueType,
int64>;
62 GKO_ASSERT_SUPPORTED_VALUE_TYPE;
67 using ConvertibleTo<Csr<ValueType, int32>>::convert_to;
68 using ConvertibleTo<Csr<ValueType, int32>>::move_to;
69 using ConvertibleTo<Csr<ValueType, int64>>::convert_to;
70 using ConvertibleTo<Csr<ValueType, int64>>::move_to;
71 using ConvertibleTo<Diagonal<next_precision<ValueType>>>::convert_to;
72 using ConvertibleTo<Diagonal<next_precision<ValueType>>>::move_to;
74 using value_type = ValueType;
75 using index_type =
int64;
76 using mat_data = matrix_data<ValueType, int64>;
77 using mat_data32 = matrix_data<ValueType, int32>;
78 using device_mat_data = device_matrix_data<ValueType, int64>;
79 using device_mat_data32 = device_matrix_data<ValueType, int32>;
80 using absolute_type = remove_complex<Diagonal>;
84 std::unique_ptr<LinOp>
transpose()
const override;
88 void convert_to(Diagonal<next_precision<ValueType>>* result)
const override;
90 void move_to(Diagonal<next_precision<ValueType>>* result)
override;
92 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
94 using ConvertibleTo<Diagonal<next_precision<ValueType, 2>>>::convert_to;
95 using ConvertibleTo<Diagonal<next_precision<ValueType, 2>>>::move_to;
98 Diagonal<next_precision<ValueType, 2>>* result)
const override;
100 void move_to(Diagonal<next_precision<ValueType, 2>>* result)
override;
103 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
105 using ConvertibleTo<Diagonal<next_precision<ValueType, 3>>>::convert_to;
106 using ConvertibleTo<Diagonal<next_precision<ValueType, 3>>>::move_to;
109 Diagonal<next_precision<ValueType, 3>>* result)
const override;
111 void move_to(Diagonal<next_precision<ValueType, 3>>* result)
override;
114 void convert_to(Csr<ValueType, int32>* result)
const override;
116 void move_to(Csr<ValueType, int32>* result)
override;
118 void convert_to(Csr<ValueType, int64>* result)
const override;
120 void move_to(Csr<ValueType, int64>* result)
override;
154 GKO_ASSERT_REVERSE_CONFORMANT(
this, b);
155 GKO_ASSERT_EQUAL_ROWS(b, x);
156 GKO_ASSERT_EQUAL_COLS(
this, x);
158 this->rapply_impl(b.
get(), x.
get());
172 GKO_ASSERT_CONFORMANT(
this, b);
173 GKO_ASSERT_EQUAL_ROWS(b, x);
174 GKO_ASSERT_EQUAL_ROWS(
this, x);
176 this->inverse_apply_impl(b.
get(), x.
get());
179 void read(
const mat_data& data)
override;
181 void read(
const mat_data32& data)
override;
183 void read(
const device_mat_data& data)
override;
185 void read(
const device_mat_data32& data)
override;
187 void read(device_mat_data&& data)
override;
189 void read(device_mat_data32&& data)
override;
191 void write(mat_data& data)
const override;
193 void write(mat_data32& data)
const override;
203 static std::unique_ptr<Diagonal>
create(
204 std::shared_ptr<const Executor> exec,
size_type size = 0);
220 static std::unique_ptr<Diagonal>
create(
221 std::shared_ptr<const Executor> exec,
const size_type size,
228 template <
typename InputValueType>
230 "explicitly construct the gko::array argument instead of passing an"
234 std::initializer_list<InputValueType> values)
250 std::shared_ptr<const Executor> exec,
size_type size,
251 gko::detail::const_array_view<ValueType>&& values);
259 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
262 LinOp* x)
const override;
264 void rapply_impl(
const LinOp* b,
LinOp* x)
const;
266 void inverse_apply_impl(
const LinOp* b,
LinOp* x)
const;
277 #endif // GKO_PUBLIC_CORE_MATRIX_DIAGONAL_HPP_