Skip to content

Commit 7cc80dc

Browse files
committed
numerical
1 parent 736f1f2 commit 7cc80dc

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/numerical/interpolation.h

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,27 @@ class Interpolation final
5757
std::array<int, N> max_;
5858
std::span<const DataType> data_;
5959

60+
[[nodiscard]] DataType compute_interpolation(
61+
const std::array<int, N>& x0,
62+
const std::array<int, N>& x1,
63+
const std::array<InterpolationType, N>& x) const
64+
{
65+
std::array<DataType, (1 << N)> data;
66+
67+
for (std::size_t i = 0; i < data.size(); ++i)
68+
{
69+
long long index = 0;
70+
for (std::size_t n = 0; n < N; ++n)
71+
{
72+
const int coordinate = ((1 << n) & i) ? x1[n] : x0[n];
73+
index += global_index_.stride(n) * coordinate;
74+
}
75+
data[i] = data_[index];
76+
}
77+
78+
return interpolation(data, x);
79+
}
80+
6081
public:
6182
constexpr Interpolation(const std::array<int, N>& size, const std::span<const DataType> data)
6283
: global_index_(size),
@@ -114,20 +135,7 @@ class Interpolation final
114135
}
115136
}
116137

117-
std::array<DataType, (1 << N)> data;
118-
119-
for (std::size_t i = 0; i < data.size(); ++i)
120-
{
121-
long long index = 0;
122-
for (std::size_t n = 0; n < N; ++n)
123-
{
124-
const int coordinate = ((1 << n) & i) ? x1[n] : x0[n];
125-
index += global_index_.stride(n) * coordinate;
126-
}
127-
data[i] = data_[index];
128-
}
129-
130-
return interpolation(data, x);
138+
return compute_interpolation(x0, x1, x);
131139
}
132140
};
133141
}

0 commit comments

Comments
 (0)