Contents

# Examples

The following example demonstrates how to construct the linear spline and perform the interpolation.
``````#include <cstdint>
#include <iostream>
#include <vector>

#include <CL/sycl.hpp>

#include <oneapi/mkl/experimental/data_fitting.hpp>

constexpr std::int64_t nx = 10'000;
constexpr std::int64_t nsites = 150'000;

int main (int argc, char ** argv) {

sycl::queue q;
sycl::usm_allocator<double, sycl::usm::alloc::shared> alloc(q);

// Allocate memory for spline parameters
std::vector<double, decltype(alloc)> partitions(nx, alloc);
std::vector<double, decltype(alloc)> functions(nx, alloc);
std::vector<double, decltype(alloc)> coeffs(2 * (nx - 1), alloc);
std::vector<double, decltype(alloc)> sites(nsites, alloc);
std::vector<double, decltype(alloc)> results(nsites, alloc);

// Fill parameters with valid data
for (std::int64_t i = 0; i < nx; ++i) {
partitions[i] = 0.1 * i;
functions[i] = i * i;
}

for (std::int64_t i = 0; i < nsites; ++i) {
sites[i] = (0.1 * nx * i) / nsites);
}

namespace df = oneapi::mkl::experimental::data_fitting;
// Set parameters to spline
df::spline<double, df::linear_spline::default_type> spl(q);
spl.set_partitions(partitions.data(), nx)
.set_coefficients(coeffs.data())
.set_function_values(functions.data());

// Construct spline
auto event = spl.construct();
event = df::interpolate(spl, sites.data(), nsites, results.data(), { event });
event.wait();

std::cout << "done" << std::endl;
return 0;
}
``````

#### Product and Performance Information

1

Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.