Ginkgo: ginkgo/core/base/type_traits.hpp Source File

| Ginkgo Generated from branch based on main. Ginkgo version 1.11.0 A numerical linear algebra library targeting many-core architectures

Loading...
Searching...
No Matches
type_traits.hpp
1// SPDX-FileCopyrightText: 2025 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_BASE_TYPE_TRAITS_HPP_
6#define GKO_PUBLIC_CORE_BASE_TYPE_TRAITS_HPP_
7
8#include <type_traits>
9
10#include <ginkgo/core/base/lin_op.hpp>
11
12namespace gko {
13namespace detail {
14
15
16template <typename Type>
17constexpr bool is_ginkgo_linop = std::is_base_of_v<LinOp, Type>;
18
19
20// helper to get factory type of concrete type or LinOp
21template <typename Type>
22struct factory_type_impl {
23 using type = typename Type::Factory;
24};
25
26// It requires LinOp to be complete type
27template <>
28struct factory_type_impl<LinOp> {
29 using type = LinOpFactory;
30};
31
32
33template <typename Type>
34using factory_type = typename factory_type_impl<Type>::type;
35
36
37// helper for handle the transposed type of concrete type and LinOp
38template <typename Type, typename = void>
39struct transposed_type_impl {
40 using type = typename Type::transposed_type;
41};
42
43// It requires LinOp to be complete type
44template <>
45struct transposed_type_impl<LinOp, void> {
46 using type = LinOp;
47};
48
49// return the same type when Type is the precision format.
50// it is used in ILU.
51template <typename Type>
52struct transposed_type_impl<Type, std::enable_if_t<!is_ginkgo_linop<Type>>> {
53 using type = Type;
54};
55
56
57template <typename Type>
58using transposed_type = typename transposed_type_impl<Type>::type;
59
60
61// helper to get value_type of concrete type or void for LinOp
62template <typename Type, typename = void>
63struct get_value_type_impl {
64 using type = typename Type::value_type;
65};
66
67// We need to use SFINAE not conditional_t because both type needs to be
68// valid in conditional_t
69template <typename Type>
70struct get_value_type_impl<Type, std::enable_if_t<!is_ginkgo_linop<Type>>> {
71 using type = Type;
72};
73
74
75template <typename Type>
76using get_value_type = typename get_value_type_impl<Type>::type;
77
78
79} // namespace detail
80} // namespace gko
81
82#endif // GKO_PUBLIC_CORE_BASE_TYPE_TRAITS_HPP_
gko
The Ginkgo namespace.
Definition abstract_factory.hpp:20