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>
17template <
typename ValueType,
typename IndexType>
20template <
typename ValueType>
39template <
typename ValueType = default_precision>
45#if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
48#if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
69 using ConvertibleTo<Diagonal<next_precision<ValueType>>>::convert_to;
70 using ConvertibleTo<Diagonal<next_precision<ValueType>>>::move_to;
72 using value_type = ValueType;
73 using index_type =
int64;
90#if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
92 using ConvertibleTo<Diagonal<next_precision<ValueType, 2>>>::convert_to;
93 using ConvertibleTo<Diagonal<next_precision<ValueType, 2>>>::move_to;
101#if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
103 using ConvertibleTo<Diagonal<next_precision<ValueType, 3>>>::convert_to;
104 using ConvertibleTo<Diagonal<next_precision<ValueType, 3>>>::move_to;
129 value_type*
get_values() noexcept {
return values_.get_data(); }
140 return values_.get_const_data();
152 GKO_ASSERT_REVERSE_CONFORMANT(
this, b);
153 GKO_ASSERT_EQUAL_ROWS(b, x);
154 GKO_ASSERT_EQUAL_COLS(
this, x);
156 this->rapply_impl(b.
get(), x.
get());
170 GKO_ASSERT_CONFORMANT(
this, b);
171 GKO_ASSERT_EQUAL_ROWS(b, x);
172 GKO_ASSERT_EQUAL_ROWS(
this, x);
174 this->inverse_apply_impl(b.
get(), x.
get());
177 void read(
const mat_data& data)
override;
179 void read(
const mat_data32& data)
override;
181 void read(
const device_mat_data& data)
override;
183 void read(
const device_mat_data32& data)
override;
185 void read(device_mat_data&& data)
override;
187 void read(device_mat_data32&& data)
override;
189 void write(mat_data& data)
const override;
191 void write(mat_data32& data)
const override;
202 std::shared_ptr<const Executor> exec,
size_type size = 0);
219 std::shared_ptr<const Executor> exec,
const size_type size,
226 template <
typename InputValueType>
228 "explicitly construct the gko::array argument instead of passing an"
232 std::initializer_list<InputValueType> values)
248 std::shared_ptr<const Executor> exec,
size_type size,
249 gko::detail::const_array_view<ValueType>&& values);
252 Diagonal(std::shared_ptr<const Executor> exec,
size_type size = 0);
254 Diagonal(std::shared_ptr<const Executor> exec,
const size_type size,
257 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
260 LinOp* x)
const override;
262 void rapply_impl(
const LinOp* b,
LinOp* x)
const;
264 void inverse_apply_impl(
const LinOp* b,
LinOp* x)
const;
ConvertibleTo interface is used to mark that the implementer can be converted to the object of Result...
Definition polymorphic_object.hpp:479
The EnableAbsoluteComputation mixin provides the default implementations of compute_absolute_linop an...
Definition lin_op.hpp:794
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition lin_op.hpp:879
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:668
The first step in using the Ginkgo library consists of creating an executor.
Definition executor.hpp:615
Definition lin_op.hpp:117
A LinOp implementing this interface can read its data from a matrix_data structure.
Definition lin_op.hpp:605
Linear operators which support transposition should implement the Transposable interface.
Definition lin_op.hpp:433
A LinOp implementing this interface can write its data to a matrix_data structure.
Definition lin_op.hpp:660
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition array.hpp:166
This type is a device-side equivalent to matrix_data.
Definition device_matrix_data.hpp:36
CSR is a matrix format which stores only the nonzero coefficients by compressing each row of the matr...
Definition csr.hpp:126
Dense is a matrix format which explicitly stores all values of the matrix.
Definition dense.hpp:120
static std::unique_ptr< const Diagonal > create_const(std::shared_ptr< const Executor > exec, size_type size, gko::detail::const_array_view< ValueType > &&values)
Creates a constant (immutable) Diagonal matrix from a constant array.
void rapply(ptr_param< const LinOp > b, ptr_param< LinOp > x) const
Applies the diagonal matrix from the right side to a matrix b, which means scales the columns of b wi...
Definition diagonal.hpp:150
static std::unique_ptr< Diagonal > create(std::shared_ptr< const Executor > exec, size_type size=0)
Creates an Diagonal matrix of the specified size.
void inverse_apply(ptr_param< const LinOp > b, ptr_param< LinOp > x) const
Applies the inverse of the diagonal matrix to a matrix b, which means scales the columns of b with th...
Definition diagonal.hpp:168
value_type * get_values() noexcept
Returns a pointer to the array of values of the matrix.
Definition diagonal.hpp:129
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
static std::unique_ptr< Diagonal > create(std::shared_ptr< const Executor > exec, const size_type size, array< value_type > values)
Creates a Diagonal matrix from an already allocated (and initialized) array.
std::unique_ptr< absolute_type > compute_absolute() const override
Gets the AbsoluteLinOp.
const value_type * get_const_values() const noexcept
Returns a pointer to the array of values of the matrix.
Definition diagonal.hpp:138
void compute_absolute_inplace() override
Compute absolute inplace on each element.
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
This class is used for function parameters in the place of raw pointers.
Definition utils_helper.hpp:41
T * get() const
Definition utils_helper.hpp:75
The matrix namespace.
Definition dense_cache.hpp:24
The Ginkgo namespace.
Definition abstract_factory.hpp:20
typename detail::remove_complex_s< T >::type remove_complex
Obtain the type which removed the complex of complex/scalar type or the template parameter of class b...
Definition math.hpp:264
std::int32_t int32
32-bit signed integral type.
Definition types.hpp:107
typename detail::to_complex_s< T >::type to_complex
Obtain the type which adds the complex of complex/scalar type or the template parameter of class by a...
Definition math.hpp:283
void write(StreamType &&os, MatrixPtrType &&matrix, layout_type layout=detail::mtx_io_traits< std::remove_cv_t< detail::pointee< MatrixPtrType > > >::default_layout)
Writes a matrix into an output stream in matrix market format.
Definition mtx_io.hpp:295
std::int64_t int64
64-bit signed integral type.
Definition types.hpp:113
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:90
std::unique_ptr< MatrixType > read(StreamType &&is, MatrixArgs &&... args)
Reads a matrix stored in matrix market format from an input stream.
Definition mtx_io.hpp:159
typename detail::find_precision_impl< T, -step >::type previous_precision
Obtains the previous move type of T in the singly-linked precision corresponding bfloat16/half.
Definition math.hpp:473
typename detail::find_precision_impl< T, step >::type next_precision
Obtains the next move type of T in the singly-linked precision corresponding bfloat16/half.
Definition math.hpp:466
This structure is used as an intermediate data type to store a sparse matrix.
Definition matrix_data.hpp:126