@@ -47,32 +47,40 @@ def test_morphsqueeze(x_morph, x_target, squeeze_coeffs):
47
47
squeeze_polynomial = Polynomial (squeeze_coeffs )
48
48
x_squeezed = x_morph + squeeze_polynomial (x_morph )
49
49
y_morph = np .sin (x_squeezed )
50
+ low_extrap = np .where (x_morph < x_squeezed [0 ])[0 ]
51
+ high_extrap = np .where (x_morph > x_squeezed [- 1 ])[0 ]
52
+ extrap_index_low_expected = low_extrap [- 1 ] if low_extrap .size else None
53
+ extrap_index_high_expected = high_extrap [0 ] if high_extrap .size else None
50
54
x_morph_expected = x_morph
51
55
y_morph_expected = np .sin (x_morph )
52
56
morph = MorphSqueeze ()
53
57
morph .squeeze = squeeze_coeffs
54
- (
55
- x_morph_actual ,
56
- y_morph_actual ,
57
- x_target_actual ,
58
- y_target_actual ,
59
- low_extrap_idx ,
60
- high_extrap_idx ,
61
- ) = morph (x_morph , y_morph , x_target , y_target )
62
- if low_extrap_idx is None and high_extrap_idx is None :
63
- assert np .allclose (y_morph_actual , y_morph_expected , atol = 1e-6 )
64
- else :
65
- interp_start = low_extrap_idx + 1 if low_extrap_idx is not None else 0
66
- interp_end = (
67
- high_extrap_idx
68
- if high_extrap_idx is not None
69
- else len (y_morph_actual )
70
- )
71
- assert np .allclose (
72
- y_morph_actual [interp_start :interp_end ],
73
- y_morph_expected [interp_start :interp_end ],
74
- atol = 1e-6 ,
75
- )
58
+ x_morph_actual , y_morph_actual , x_target_actual , y_target_actual = morph (
59
+ x_morph , y_morph , x_target , y_target
60
+ )
61
+ extrap_index_low = morph .extrap_index_low
62
+ extrap_index_high = morph .extrap_index_high
63
+ if extrap_index_low is None :
64
+ extrap_index_low = 0
65
+ elif extrap_index_high is None :
66
+ extrap_index_high = - 1
67
+ assert np .allclose (
68
+ y_morph_actual [extrap_index_low + 1 : extrap_index_high ],
69
+ y_morph_expected [extrap_index_low + 1 : extrap_index_high ],
70
+ atol = 1e-6 ,
71
+ )
72
+ assert np .allclose (
73
+ y_morph_actual [:extrap_index_low ],
74
+ y_morph_expected [:extrap_index_low ],
75
+ atol = 1e-3 ,
76
+ )
77
+ assert np .allclose (
78
+ y_morph_actual [extrap_index_high :],
79
+ y_morph_expected [extrap_index_high :],
80
+ atol = 1e-3 ,
81
+ )
82
+ assert morph .extrap_index_low == extrap_index_low_expected
83
+ assert morph .extrap_index_high == extrap_index_high_expected
76
84
assert np .allclose (x_morph_actual , x_morph_expected )
77
85
assert np .allclose (x_target_actual , x_target )
78
86
assert np .allclose (y_target_actual , y_target )
0 commit comments