Examples#
The following example demonstrates how to construct the linear spline and perform the interpolation.
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
9constexpr std::int64_t nx = 10'000;
10constexpr std::int64_t nsites = 150'000;
11
12int main (int argc, char ** argv) {
13
14 sycl::queue q;
15 sycl::usm_allocator<double, sycl::usm::alloc::shared> alloc(q);
16
17 // Allocate memory for spline parameters
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 // Fill parameters with valid data
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 // Set parameters to spline
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 // Construct spline
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}