Skip to content

Commit 217b93d

Browse files
committed
fix metaspline with derivatives
1 parent 388d4f9 commit 217b93d

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

source/mir/interpolate/spline.d

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,12 @@ struct MetaSpline(T, X)
17411741
{
17421742
typeof(splines[0].opCall!derivative(xs[0]))[derivative + 1] ret = void;
17431743
static foreach (o; 0 .. derivative + 1)
1744-
ret[o] = splines[o].opCall!derivative(xs[0]);
1744+
{{
1745+
auto s = splines[o].opCall!derivative(xs[0]);
1746+
static foreach (r; 0 .. derivative + 1)
1747+
ret[r][o] = s[r];
1748+
1749+
}}
17451750
return ret;
17461751
}
17471752
}
@@ -1781,12 +1786,6 @@ unittest
17811786
auto trapezoidInterpolator = metaSpline!double(g.rcarray!(immutable double), d.lightConst);
17821787

17831788
auto val = trapezoidInterpolator(9.0, 1.8);
1784-
auto ext = trapezoidInterpolator.opCall!2(9.0, 1.8);
1785-
assert(ext[0][0] == val);
1786-
assert(ext == [
1787-
[-0.6323361344537806, -2.2344649859943977, 1.362173669467787],
1788-
[3.6676610644257703, -2.984652194211018, 0.9911251167133525],
1789-
[2.4365546218487393, -1.556932773109244, 0.3836134453781514]]);
17901789
}
17911790

17921791
version(mir_test)
@@ -1829,4 +1828,12 @@ unittest
18291828

18301829
///// verify result ////
18311830
assert(all!appreq(interp_data, real_data));
1831+
1832+
auto z0 = 1.23;
1833+
auto z1 = 3.21;
1834+
auto d = interpolant.withDerivative(z0, z1);
1835+
assert(appreq(d[0][0], f(z0, z1)));
1836+
assert(appreq(d[1][0], y_x0 + y_x0x1 * z1));
1837+
assert(appreq(d[0][1], y_x1 + y_x0x1 * z0));
1838+
assert(appreq(d[1][1], y_x0x1));
18321839
}

0 commit comments

Comments
 (0)