例#
次の例は、線形スプラインを構築し、補間を行う方法を示しています。
1 #include <cstdint>
2 #include <iostream>
3 #include <vector>
4
5 #include <sycl/sycl.hpp>
6
7 #include <oneapi/mkl/experimental/data_fitting.hpp>
8
9 constexpr std::int64_t nx = 10'000;
10 constexpr std::int64_t nsites = 150'000;
11
12 int main (int argc, char ** argv) {
13
14 sycl::queue q;
15 sycl::usm_allocator<double, sycl::usm::alloc::shared> alloc(q);
16
17 // スプライン・パラメーターにメモリーを割り当て
18 std::vector<double, decltype(alloc)> partitions(nx, alloc);
19 std::vector<double, decltype(alloc)> functions(nx, alloc);
20 std::vector<double, decltype(alloc)> coeffs(2 * (nx - 1), alloc);
21 std::vector<double, decltype(alloc)> sites(nsites, alloc);
22 std::vector<double, decltype(alloc)> results(nsites, alloc);
23
24 // 有効なデータでパラメーターを入力
25 for (std::int64_t i = 0; i < nx; ++i) {
26 partitions[i] = 0.1 * i;
27 functions[i] = i * i;
28 }
29
30 for (std::int64_t i = 0; i < nsites; ++i) {
31 sites[i] = (0.1 * nx * i) / nsites);
32 }
33
34 namespace df = oneapi::mkl::experimental::data_fitting;
35 // スプラインにパラメーターを設定
36 df::spline<double, df::linear_spline::default_type> spl(q);
37 spl.set_partitions(partitions.data(), nx)
38 .set_coefficients(coeffs.data())
39 .set_function_values(functions.data());
40
41 // スプラインを構築
42 auto event = spl.construct();
43 event = df::interpolate(spl, sites.data(), nsites, results.data(), { event });
44 event.wait();
45
46 std::cout << "done" << std::endl;
47 return 0;
48 }