5#ifndef GKO_PUBLIC_CORE_BASE_PRECISION_DISPATCH_HPP_
6#define GKO_PUBLIC_CORE_BASE_PRECISION_DISPATCH_HPP_
9#include <ginkgo/config.hpp>
10#include <ginkgo/core/base/math.hpp>
11#include <ginkgo/core/base/temporary_conversion.hpp>
12#include <ginkgo/core/distributed/vector.hpp>
13#include <ginkgo/core/matrix/dense.hpp>
43template <
typename ValueType,
typename Ptr>
44detail::temporary_conversion<std::conditional_t<
45 std::is_const<detail::pointee<Ptr>>::value,
const matrix::Dense<ValueType>,
46 matrix::Dense<ValueType>>>
49 using Pointee = detail::pointee<Ptr>;
53 std::conditional_t<std::is_const<Pointee>::value,
const Dense, Dense>;
54 auto result = detail::temporary_conversion<
57 GKO_NOT_SUPPORTED(*matrix);
77template <
typename ValueType,
typename Function,
typename...
Args>
93template <
typename ValueType,
typename Function>
110 fn(
dynamic_cast<const Dense*
>(
dense_in->create_real_view().get()),
111 dynamic_cast<Dense*
>(
dense_out->create_real_view().get()));
127template <
typename ValueType,
typename Function>
147 dynamic_cast<const Dense*
>(
dense_in->create_real_view().get()),
148 dynamic_cast<Dense*
>(
dense_out->create_real_view().get()));
164template <
typename ValueType,
typename Function>
186 dynamic_cast<const Dense*
>(
dense_in->create_real_view().get()),
188 dynamic_cast<Dense*
>(
dense_out->create_real_view().get()));
224template <
typename ValueType,
typename Function>
227#ifdef GINKGO_MIXED_PRECISION
236 GKO_NOT_SUPPORTED(
out);
244 GKO_NOT_SUPPORTED(
out);
247 GKO_NOT_SUPPORTED(
in);
264template <
typename ValueType,
typename Function,
265 std::enable_if_t<is_complex<ValueType>()>* =
nullptr>
269#ifdef GINKGO_MIXED_PRECISION
277template <
typename ValueType,
typename Function,
278 std::enable_if_t<!is_complex<ValueType>()>* =
nullptr>
282#ifdef GINKGO_MIXED_PRECISION
299namespace experimental {
305namespace distributed {
333template <
typename ValueType>
334detail::temporary_conversion<experimental::distributed::Vector<ValueType>>
337 auto result = detail::temporary_conversion<
343 GKO_NOT_SUPPORTED(matrix);
352template <
typename ValueType>
353detail::temporary_conversion<const experimental::distributed::Vector<ValueType>>
356 auto result = detail::temporary_conversion<
362 GKO_NOT_SUPPORTED(matrix);
382template <
typename ValueType,
typename Function,
typename...
Args>
385 fn(distributed::make_temporary_conversion<ValueType>(
linops).get()...);
398template <
typename ValueType,
typename Function>
407 distributed::make_temporary_conversion<to_complex<ValueType>>(
in);
409 distributed::make_temporary_conversion<to_complex<ValueType>>(
out);
417 distributed::precision_dispatch<ValueType>(
fn,
in,
out);
425template <
typename ValueType,
typename Function>
435 distributed::make_temporary_conversion<to_complex<ValueType>>(
in);
437 distributed::make_temporary_conversion<to_complex<ValueType>>(
out);
448 distributed::make_temporary_conversion<ValueType>(
in).get(),
449 distributed::make_temporary_conversion<ValueType>(
out).get());
457template <
typename ValueType,
typename Function>
468 distributed::make_temporary_conversion<to_complex<ValueType>>(
in);
470 distributed::make_temporary_conversion<to_complex<ValueType>>(
out);
483 distributed::make_temporary_conversion<ValueType>(
in).get(),
485 distributed::make_temporary_conversion<ValueType>(
out).get());
506template <
typename ValueType,
typename Function>
511 experimental::distributed::precision_dispatch_real_complex<ValueType>(
523template <
typename ValueType,
typename Function>
524void precision_dispatch_real_complex_distributed(
Function fn,
526 const LinOp*
in, LinOp*
out)
528 if (
dynamic_cast<const experimental::distributed::DistributedBase*
>(
in)) {
529 experimental::distributed::precision_dispatch_real_complex<ValueType>(
541template <
typename ValueType,
typename Function>
542void precision_dispatch_real_complex_distributed(
Function fn,
545 const LinOp* beta, LinOp*
out)
547 if (
dynamic_cast<const experimental::distributed::DistributedBase*
>(
in)) {
548 experimental::distributed::precision_dispatch_real_complex<ValueType>(
570template <
typename ValueType,
typename Function,
typename...
Args>
ConvertibleTo interface is used to mark that the implementer can be converted to the object of Result...
Definition polymorphic_object.hpp:471
Definition lin_op.hpp:118
A base class for distributed objects.
Definition base.hpp:32
Vector is a format which explicitly stores (multiple) distributed column vectors in a dense storage f...
Definition vector.hpp:63
Dense is a matrix format which explicitly stores all values of the matrix.
Definition dense.hpp:107
void precision_dispatch_real_complex(Function fn, const LinOp *in, LinOp *out)
Calls the given function with the given LinOps temporarily converted to experimental::distributed::Ve...
Definition precision_dispatch.hpp:399
detail::temporary_conversion< experimental::distributed::Vector< ValueType > > make_temporary_conversion(LinOp *matrix)
Convert the given LinOp from experimental::distributed::Vector<...> to experimental::distributed::Vec...
Definition precision_dispatch.hpp:335
void precision_dispatch(Function fn, Args *... linops)
Calls the given function with each given argument LinOp temporarily converted into experimental::dist...
Definition precision_dispatch.hpp:383
The Ginkgo namespace.
Definition abstract_factory.hpp:20
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:775
void mixed_precision_dispatch(Function fn, const LinOp *in, LinOp *out)
Calls the given function with each given argument LinOp converted into matrix::Dense<ValueType> as pa...
Definition precision_dispatch.hpp:225
void mixed_precision_dispatch_real_complex(Function fn, const LinOp *in, LinOp *out)
Calls the given function with the given LinOps cast to their dynamic type matrix::Dense<ValueType>* a...
Definition precision_dispatch.hpp:266
void precision_dispatch(Function fn, Args *... linops)
Calls the given function with each given argument LinOp temporarily converted into matrix::Dense<Valu...
Definition precision_dispatch.hpp:78
detail::temporary_conversion< std::conditional_t< std::is_const< detail::pointee< Ptr > >::value, const matrix::Dense< ValueType >, matrix::Dense< ValueType > > > make_temporary_conversion(Ptr &&matrix)
Convert the given LinOp from matrix::Dense<...> to matrix::Dense<ValueType>.
Definition precision_dispatch.hpp:47
void precision_dispatch_real_complex(Function fn, const LinOp *in, LinOp *out)
Calls the given function with the given LinOps temporarily converted to matrix::Dense<ValueType>* as ...
Definition precision_dispatch.hpp:94