12#ifndef ARCCORE_ALINA_STATICMATRIX_H
13#define ARCCORE_ALINA_STATICMATRIX_H
29#include "arccore/alina/BuiltinBackend.h"
30#include "arccore/alina/ValueTypeInterface.h"
31#include "arccore/alina/DenseMatrixInverseImpl.h"
36namespace Arcane::Alina
42template <
typename T,
int N,
int M>
45 std::array<T, N * M> buf;
47 T operator()(
int i,
int j)
const
49 return buf[i * M + j];
52 T& operator()(
int i,
int j)
54 return buf[i * M + j];
57 T operator()(
int i)
const
80 for (
int i = 0; i < N * M; ++i)
88 for (
int i = 0; i < N * M; ++i)
96 for (
int i = 0; i < N * M; ++i)
103 for (
int i = 0; i < N * M; ++i)
115 for (
int i = 0; i < N * M; ++i)
116 x.buf[i] = -x.buf[i];
122 T xtrace = math::zero<T>();
123 T ytrace = math::zero<T>();
125 const int K = N < M ? N : M;
127 for (
int i = 0; i < K; ++i) {
132 return xtrace < ytrace;
135 friend std::ostream& operator<<(std::ostream& os,
const StaticMatrix& a)
137 for (
int i = 0; i < N; ++i) {
138 for (
int j = 0; j < M; ++j) {
139 os <<
" " << a(i, j);
147template <
typename T,
typename U,
int N,
int M>
153template <
typename T,
typename U,
int N,
int M>
154StaticMatrix<T, N, M> operator-(StaticMatrix<T, N, M> a,
const StaticMatrix<U, N, M>& b)
159template <
typename T,
typename U,
int N,
int K,
int M>
160StaticMatrix<T, N, M> operator*(
const StaticMatrix<T, N, K>& a,
const StaticMatrix<U, K, M>& b)
162 StaticMatrix<T, N, M> c;
163 for (
int i = 0; i < N; ++i) {
164 for (
int j = 0; j < M; ++j)
165 c(i, j) = math::zero<T>();
166 for (
int k = 0; k < K; ++k) {
168 for (
int j = 0; j < M; ++j)
169 c(i, j) += aik * b(k, j);
178template <
class T,
int N,
int M>
184namespace Arcane::Alina::backend
188template <
typename T,
int N,
int M>
194namespace Arcane::Alina::math
198template <
class T,
int N,
int M>
201 typedef typename scalar_of<T>::type type;
205template <
class T,
int N,
int M,
class S>
212template <
class T,
int N>
219template <
class T,
int N,
int M>
226template <
class T,
int N,
int M>
231template <
class T,
int N,
int M>
236template <
class T,
int N,
int M>
241template <
typename T,
int N,
int M>
249 for (
int i = 0; i < N; ++i)
250 for (
int j = 0; j < M; ++j)
251 y(j, i) = math::adjoint(x(i, j));
257template <
class T,
int N>
260 typedef T return_type;
263 T sum = math::zero<T>();
264 for (
int i = 0; i < N; ++i)
265 sum += x(i) * math::adjoint(y(i));
271template <
class T,
int N,
int M>
279 for (
int i = 0; i < M; ++i) {
280 for (
int j = 0; j < M; ++j) {
281 T sum = math::zero<T>();
282 for (
int k = 0; k < N; ++k)
283 sum += x(k, i) * math::adjoint(y(k, j));
292template <
typename T,
int N,
int M>
297 T s = math::zero<T>();
298 for (
int i = 0; i < N * M; ++i)
299 s += x(i) * math::adjoint(x(i));
300 return sqrt(math::norm(s));
305template <
typename T,
int N,
int M>
311 for (
int i = 0; i < N * M; ++i)
312 z(i) = math::zero<T>();
318template <
typename T,
int N,
int M>
323 for (
int i = 0; i < N * M; ++i)
324 if (!math::is_zero(x(i)))
331template <
typename T,
int N>
337 for (
int i = 0; i < N; ++i)
338 for (
int j = 0; j < N; ++j)
339 I(i, j) =
static_cast<T
>(i == j);
345template <
typename T,
int N,
int M>
351 for (
int i = 0; i < N * M; ++i)
358template <
typename T,
int N>
363 std::array<T, N * N> buf;
364 std::array<int, N> p;
365 detail::inverse(N, A.data(), buf.data(), p.data());
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.