Compare with LinearInterp and BilinearInterp derivatives
@@ -21,10 +21,16 @@ class CompareLinearInterp(unittest.TestCase):
h_interp = LinearInterp(x, y, lower_extrap=True)
e_interp = LinearFast(y, [x])
+ # Function evaluation
h_vals = h_interp(eval_points)
e_vals = e_interp(eval_points)
self.assertTrue(np.allclose(h_vals, e_vals))
+ # Derivative
+ h_der = h_interp._der(eval_points)
+ e_der = e_interp.gradient(eval_points)[0]
+ self.assertTrue(np.allclose(h_der, e_der))
+
def test_outputs(self):
"""
Tests that function calls using the base hark and
@@ -79,10 +85,21 @@ class CompareBilinearInterp(unittest.TestCase):
h_interp = BilinearInterp(z, x, y)
e_interp = LinearFast(z, [x, y])
+ # Function value
h_vals = h_interp(eval_x, eval_y)
e_vals = e_interp(eval_x, eval_y)
self.assertTrue(np.allclose(h_vals, e_vals))
+ # Derivatives
+ h_grad = [
+ h_interp.derivativeX(eval_x, eval_y),
+ h_interp.derivativeY(eval_x, eval_y),
+ ]
+ e_grad = e_interp.gradient(eval_x, eval_y)
+
+ for i, der in enumerate(h_grad):
+ self.assertTrue(np.allclose(der, e_grad[i]))
+
def test_outputs(self):
"""
Tests that function calls using the base hark and
