|
| 1 | +# matrix_inf_norm |
| 2 | + |
| 3 | +* [mathjax enable] |
| 4 | +* linalg[meta header] |
| 5 | +* function template[meta id-type] |
| 6 | +* std::linalg[meta namespace] |
| 7 | +* cpp26[meta cpp] |
| 8 | + |
| 9 | +```cpp |
| 10 | +namespace std::linalg { |
| 11 | + template<in-matrix InMat, class Scalar> |
| 12 | + Scalar matrix_inf_norm(InMat A, Scalar init); // (1) |
| 13 | + |
| 14 | + template<class ExecutionPolicy, |
| 15 | + in-matrix InMat, |
| 16 | + class Scalar> |
| 17 | + Scalar matrix_inf_norm( |
| 18 | + ExecutionPolicy&& exec, |
| 19 | + InMat A, |
| 20 | + Scalar init); // (2) |
| 21 | + |
| 22 | + template<in-matrix InMat> |
| 23 | + auto matrix_inf_norm(InMat A); // (3) |
| 24 | + |
| 25 | + template<class ExecutionPolicy, in-matrix InMat> |
| 26 | + auto matrix_inf_norm(ExecutionPolicy&& exec, InMat A); // (4) |
| 27 | +} |
| 28 | +``` |
| 29 | +
|
| 30 | +
|
| 31 | +## 概要 |
| 32 | +行列の無限大ノルムを計算する。 |
| 33 | +
|
| 34 | +- (1): 逐次実行する。 |
| 35 | +- (2): 指定された実行ポリシーに応じて実行する。 |
| 36 | +- (3): (1)で`init`に`InMat::value_type`のデフォルト値を与えて逐次実行する。 |
| 37 | +- (4): (2)で`init`に`InMat::value_type`のデフォルト値を与えて、指定された実行ポリシーに応じて実行する。 |
| 38 | +
|
| 39 | +
|
| 40 | +## 適格要件 |
| 41 | +- (1), (2): `decltype(`[`abs-if-needed`](abs-if-needed.md)`(declval<typename InMat::value_type>()))`が`Scalar`に変換可能。 |
| 42 | +
|
| 43 | +
|
| 44 | +## 効果 |
| 45 | +- (3), (4): `T`を`decltype(abs-if-needed(declval<typename InMat::value_type>()))`とすると、 |
| 46 | + + (3): `matrix_inf_norm(A, T{})`を返す。 |
| 47 | + + (4): `matrix_inf_norm(std::forward<ExecutionPolicy>(exec), A, T{})`を返す。 |
| 48 | +
|
| 49 | +
|
| 50 | +## 戻り値 |
| 51 | +- (1), (2): `A`が $m \times n$ 行列とすると、以下の値を返す。 |
| 52 | + 1. もし、`m`が0なら`init` |
| 53 | + 2. そうでないなら、以下の式の値 |
| 54 | +
|
| 55 | +$$ |
| 56 | +\verb|init| + \max_{i = 0, \dots ,m - 1}\sum_{j = 0}^{n - 1} |\verb|A[|i, j\verb|]|| |
| 57 | +$$ |
| 58 | +
|
| 59 | +- (3), (4): `T`を`decltype(abs-if-needed(declval<typename InMat::value_type>()))`とすると、 |
| 60 | + + (3): `matrix_inf_norm(A, T{})`を返す。 |
| 61 | + + (4): `matrix_inf_norm(std::forward<ExecutionPolicy>(exec), A, T{})`を返す。 |
| 62 | +
|
| 63 | +
|
| 64 | +## 備考 |
| 65 | +- (1), (2): もし`InMat::value_type`と`Scalar`がどちらも浮動小数点数型または`std::complex`の特殊化で、`Scalar`が`InMat::value_type`より精度が高い場合、和の各項は`Scalar`またはより高い精度の型が使われる。 |
| 66 | +
|
| 67 | +
|
| 68 | +## 例 |
| 69 | +**[注意] 処理系にあるコンパイラで確認していないため、間違っているかもしれません。** |
| 70 | +
|
| 71 | +```cpp |
| 72 | +#include <array> |
| 73 | +#include <cmath> |
| 74 | +#include <execution> |
| 75 | +#include <iostream> |
| 76 | +#include <linalg> |
| 77 | +#include <mdspan> |
| 78 | +
|
| 79 | +int main() |
| 80 | +{ |
| 81 | + constexpr size_t M = 4; |
| 82 | + constexpr size_t N = 4; |
| 83 | +
|
| 84 | + std::array<double, M * N> mat; |
| 85 | +
|
| 86 | + std::mdspan A(mat.data(), M, N); |
| 87 | +
|
| 88 | + for(int i = 0; i < A.extent(0); ++i) { |
| 89 | + for(int j = 0; j < A.extent(1); ++j) { |
| 90 | + A(i,j) = ((i + j) % 2 == 0 ? 1.0 : -1.0) / (i * A.extent(1) + j + 1); |
| 91 | + } |
| 92 | + } |
| 93 | +
|
| 94 | + std::cout << std::linalg::matrix_inf_norm(A, -1.0 / 3) << '\n' |
| 95 | + << std::linalg::matrix_inf_norm(std::execution::par, A, -1.0 / 3) << '\n' |
| 96 | + << std::linalg::matrix_inf_norm(A) << '\n' |
| 97 | + << std::linalg::matrix_inf_norm(std::execution::par, A) << '\n'; |
| 98 | +
|
| 99 | + return 0; |
| 100 | +} |
| 101 | +``` |
| 102 | + |
| 103 | + |
| 104 | +### 出力 |
| 105 | +``` |
| 106 | +1.75 |
| 107 | +1.75 |
| 108 | +2.08333 |
| 109 | +2.08333 |
| 110 | +``` |
| 111 | + |
| 112 | + |
| 113 | +## バージョン |
| 114 | +### 言語 |
| 115 | +- C++26 |
| 116 | + |
| 117 | +### 処理系 |
| 118 | +- [Clang](/implementation.md#clang): ?? |
| 119 | +- [GCC](/implementation.md#gcc): ?? |
| 120 | +- [ICC](/implementation.md#icc): ?? |
| 121 | +- [Visual C++](/implementation.md#visual_cpp): ?? |
| 122 | + |
| 123 | + |
| 124 | +## 関連項目 |
| 125 | +- [`execution`](/reference/execution.md) |
| 126 | +- [`mdspan`](/reference/mdspan.md) |
| 127 | + |
| 128 | + |
| 129 | +## 参照 |
| 130 | +- [P0788R3 Standard Library Specification in a Concepts and Contracts World](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0788r3.pdf) |
| 131 | + |
0 commit comments