Arcane  v4.1.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ValueTypeInterface.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ValueTypeInterface.h (C) 2000-2026 */
9/* */
10/* Support for various value types. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_ALINA_VALUETYPEINTERFACE_H
13#define ARCCORE_ALINA_VALUETYPEINTERFACE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16/*
17 * This file is based on the work on AMGCL library (version march 2026)
18 * which can be found at https://github.com/ddemidov/amgcl.
19 *
20 * Copyright (c) 2012-2022 Denis Demidov <dennis.demidov@gmail.com>
21 * SPDX-License-Identifier: MIT
22 */
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26#include <type_traits>
27#include <complex>
28
29namespace Arcane::Alina::math
30{
31
33template <class T, class Enable = void>
35{
36 typedef T type;
37};
38
40template <class T, class Enable = void>
41struct rhs_of
42{
43 typedef T type;
44};
45
47template <class T, class Enable = void>
49{
50 typedef T type;
51};
52
54template <class T, class S, class Enable = void>
56{
57 typedef S type;
58};
59
61template <class T, class Enable = void>
62struct is_static_matrix : std::false_type
63{};
64
66template <class T, class Enable = void>
67struct static_rows : std::integral_constant<int, 1>
68{};
69
71template <class T, class Enable = void>
72struct static_cols : std::integral_constant<int, 1>
73{};
74
76
77template <typename ValueType, class Enable = void>
79{
80 typedef ValueType return_type;
81
82 static ValueType get(ValueType x)
83 {
84 return x;
85 }
86};
87
89
90template <typename ValueType, class Enable = void>
92{
93 typedef ValueType return_type;
94
95 static return_type get(ValueType x, ValueType y)
96 {
97 return x * y;
98 }
99};
100
102
103template <typename ValueType, class Enable = void>
105{
106 static typename scalar_of<ValueType>::type get(ValueType x)
107 {
108 return std::abs(x);
109 }
110};
111
113
114template <typename ValueType, class Enable = void>
116{
117 static ValueType get()
118 {
119 return static_cast<ValueType>(0);
120 }
121};
122
124
125template <typename ValueType, class Enable = void>
127{
128 static bool get(const ValueType& x)
129 {
130 return x == zero_impl<ValueType>::get();
131 }
132};
133
135
136template <typename ValueType, class Enable = void>
138{
139 static ValueType get()
140 {
141 return static_cast<ValueType>(1);
142 }
143};
144
146
147template <typename ValueType, class Enable = void>
149{
150 static ValueType get(typename scalar_of<ValueType>::type c)
151 {
152 return static_cast<ValueType>(c);
153 }
154};
155
157
158template <typename ValueType, class Enable = void>
160{
161 static ValueType get(const ValueType& x)
162 {
163 return identity_impl<ValueType>::get() / x;
164 }
165};
166
168template <typename ValueType>
169typename adjoint_impl<ValueType>::return_type
170adjoint(ValueType x)
171{
172 return adjoint_impl<ValueType>::get(x);
173}
174
176template <typename ValueType>
177typename inner_product_impl<ValueType>::return_type
178inner_product(ValueType x, ValueType y)
179{
180 return inner_product_impl<ValueType>::get(x, y);
181}
182
184template <typename ValueType>
185typename scalar_of<ValueType>::type norm(const ValueType& a)
186{
187 return norm_impl<ValueType>::get(a);
188}
189
191template <typename ValueType>
192ValueType zero()
193{
194 return zero_impl<ValueType>::get();
195}
196
198template <typename ValueType>
199bool is_zero(const ValueType& x)
200{
201 return is_zero_impl<ValueType>::get(x);
202}
203
205template <typename ValueType>
206ValueType identity()
207{
208 return identity_impl<ValueType>::get();
209}
210
212template <typename ValueType>
213ValueType constant(typename scalar_of<ValueType>::type c)
214{
215 return constant_impl<ValueType>::get(c);
216}
217
219template <typename ValueType>
220ValueType inverse(const ValueType& x)
221{
222 return inverse_impl<ValueType>::get(x);
223}
224
225/*---------------------------------------------------------------------------*/
226/*---------------------------------------------------------------------------*/
227
228} // namespace Arcane::Alina::math
229
230/*---------------------------------------------------------------------------*/
231/*---------------------------------------------------------------------------*/
232
233#endif
Default implementation for conjugate transpose.
Default implementation for the constant element.
Element type of a non-scalar type.
Default implementation for the identity element.
Default implementation for inner product.
Default implementation of inversion operation.
Whether the value type is a statically sized matrix.
Default implementation for zero check.
Default implementation for element norm.
Replace scalar type in the static matrix.
RHS type corresponding to a non-scalar type.
Scalar type of a non-scalar type.
Number of columns for statically sized matrix types.
Number of rows for statically sized matrix types.
Default implementation for the zero element.