File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 6464
6565
6666## 例
67+ ** [ 注意] 処理系にあるコンパイラで確認していないため、間違っているかもしれません。**
68+
69+ ``` cpp
70+ #include < array>
71+ #include < cmath>
72+ #include < execution>
73+ #include < iostream>
74+ #include < linalg>
75+ #include < mdspan>
76+
77+
78+ template <class Scalar >
79+ Scalar get_sum_of_squares (std::linalg::sum_of_squares_result<Scalar > result) {
80+ return std::pow(result.scaling_factor, 2) * result.scaled_sum_of_squares;
81+ }
82+
83+
84+ int main()
85+ {
86+ constexpr size_t N = 4;
87+
88+ std::array<double, N> vec;
89+
90+ std::mdspan v(vec.data(), N);
91+
92+ for(int i = 0; i < v.extent(0); ++i) {
93+ v(i) = std::pow(-1.0, i) / (i + 1);
94+ }
95+
96+ auto init = std::linalg::sum_of_squares_result<double >{.scaling_factor = 1.0 / 5,
97+ .scaled_sum_of_squares = 1.0};
98+
99+ std::cout << get_sum_of_squares(
100+ std::linalg::vector_sum_of_squares(v, init)) // (1)
101+ << get_sum_of_squares(
102+ std::linalg::vector_sum_of_squares(std::execution::par, v, init)) << '\n' // (2)
103+ << get_sum_of_squares(
104+ std::linalg::vector_sum_of_squares(v)) << '\n' // (3)
105+ << get_sum_of_squares(
106+ std::linalg::vector_sum_of_squares(std::execution::par, v)) << '\n'; // (4)
107+
108+ return 0;
109+ }
110+ ```
67111
68112
69113### 出力
114+ ```
115+ 1.46361
116+ 1.46361
117+ 1.42361
118+ 1.42361
119+ ```
70120
71121
72122## バージョン
You can’t perform that action at this time.
0 commit comments