33#ifndef GKO_PUBLIC_CORE_BASE_PRECISION_DISPATCH_HPP_
34#define GKO_PUBLIC_CORE_BASE_PRECISION_DISPATCH_HPP_
37#include <ginkgo/config.hpp>
38#include <ginkgo/core/base/math.hpp>
39#include <ginkgo/core/base/temporary_conversion.hpp>
40#include <ginkgo/core/distributed/vector.hpp>
41#include <ginkgo/core/matrix/dense.hpp>
71template <
typename ValueType,
typename Ptr>
72detail::temporary_conversion<std::conditional_t<
73 std::is_const<detail::pointee<Ptr>>::value,
const matrix::Dense<ValueType>,
74 matrix::Dense<ValueType>>>
77 using Pointee = detail::pointee<Ptr>;
81 std::conditional_t<std::is_const<Pointee>::value,
const Dense, Dense>;
82 auto result = detail::temporary_conversion<
85 GKO_NOT_SUPPORTED(*matrix);
105template <
typename ValueType,
typename Function,
typename...
Args>
121template <
typename ValueType,
typename Function>
138 fn(
dynamic_cast<const Dense*
>(
dense_in->create_real_view().get()),
139 dynamic_cast<Dense*
>(
dense_out->create_real_view().get()));
155template <
typename ValueType,
typename Function>
175 dynamic_cast<const Dense*
>(
dense_in->create_real_view().get()),
176 dynamic_cast<Dense*
>(
dense_out->create_real_view().get()));
192template <
typename ValueType,
typename Function>
214 dynamic_cast<const Dense*
>(
dense_in->create_real_view().get()),
216 dynamic_cast<Dense*
>(
dense_out->create_real_view().get()));
252template <
typename ValueType,
typename Function>
255#ifdef GINKGO_MIXED_PRECISION
264 GKO_NOT_SUPPORTED(
out);
272 GKO_NOT_SUPPORTED(
out);
275 GKO_NOT_SUPPORTED(
in);
292template <
typename ValueType,
typename Function,
293 std::enable_if_t<is_complex<ValueType>()>* =
nullptr>
297#ifdef GINKGO_MIXED_PRECISION
305template <
typename ValueType,
typename Function,
306 std::enable_if_t<!is_complex<ValueType>()>* =
nullptr>
310#ifdef GINKGO_MIXED_PRECISION
327namespace experimental {
333namespace distributed {
361template <
typename ValueType>
362detail::temporary_conversion<experimental::distributed::Vector<ValueType>>
365 auto result = detail::temporary_conversion<
371 GKO_NOT_SUPPORTED(matrix);
380template <
typename ValueType>
381detail::temporary_conversion<const experimental::distributed::Vector<ValueType>>
384 auto result = detail::temporary_conversion<
390 GKO_NOT_SUPPORTED(matrix);
410template <
typename ValueType,
typename Function,
typename...
Args>
413 fn(distributed::make_temporary_conversion<ValueType>(
linops).get()...);
426template <
typename ValueType,
typename Function>
435 distributed::make_temporary_conversion<to_complex<ValueType>>(
in);
437 distributed::make_temporary_conversion<to_complex<ValueType>>(
out);
445 distributed::precision_dispatch<ValueType>(
fn,
in,
out);
453template <
typename ValueType,
typename Function>
463 distributed::make_temporary_conversion<to_complex<ValueType>>(
in);
465 distributed::make_temporary_conversion<to_complex<ValueType>>(
out);
476 distributed::make_temporary_conversion<ValueType>(
in).get(),
477 distributed::make_temporary_conversion<ValueType>(
out).get());
485template <
typename ValueType,
typename Function>
496 distributed::make_temporary_conversion<to_complex<ValueType>>(
in);
498 distributed::make_temporary_conversion<to_complex<ValueType>>(
out);
511 distributed::make_temporary_conversion<ValueType>(
in).get(),
513 distributed::make_temporary_conversion<ValueType>(
out).get());
534template <
typename ValueType,
typename Function>
539 experimental::distributed::precision_dispatch_real_complex<ValueType>(
551template <
typename ValueType,
typename Function>
552void precision_dispatch_real_complex_distributed(
Function fn,
554 const LinOp*
in, LinOp*
out)
556 if (
dynamic_cast<const experimental::distributed::DistributedBase*
>(
in)) {
557 experimental::distributed::precision_dispatch_real_complex<ValueType>(
569template <
typename ValueType,
typename Function>
570void precision_dispatch_real_complex_distributed(
Function fn,
573 const LinOp* beta, LinOp*
out)
575 if (
dynamic_cast<const experimental::distributed::DistributedBase*
>(
in)) {
576 experimental::distributed::precision_dispatch_real_complex<ValueType>(
598template <
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:499
Definition lin_op.hpp:146
A base class for distributed objects.
Definition base.hpp:60
Vector is a format which explicitly stores (multiple) distributed column vectors in a dense storage f...
Definition vector.hpp:92
Dense is a matrix format which explicitly stores all values of the matrix.
Definition dense.hpp:136
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:427
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:363
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:411
The Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803
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:253
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:294
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:106
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:75
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:122