Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion aeon/transformations/collection/feature_based/_catch22.py
Original file line number Diff line number Diff line change
Expand Up @@ -1934,7 +1934,10 @@ def _transform_case_numba(
# typed placeholders; real values are assigned before first use. These
# must be dtype-fixed (not aliases of series) so the kernel also
# compiles for integer input arrays.
outlier_series = np.empty(0, np.float64)
# / 1 applies the same dtype promotion z_normalise_series_with_mean
# uses internally (float32 stays float32, everything else becomes
# float64), so this placeholder always matches the real value's dtype.
outlier_series = series[:0] / 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if we override the value afterward, I'd rather want a helper function to init an empty array to the correct type/shape.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the _zeros_promoted helper as requested in 7a5a783 — it's used both here and for the c22 buffer above.

have_outlier = False
fft = ac_tw[:0]
have_fft = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1521,3 +1521,24 @@ def track_n(s):
assert abs(np.std(passed_series["p"]) - 1.0) < 1e-10
assert abs(np.mean(passed_series["n"])) < 1e-10
assert abs(np.std(passed_series["n"]) - 1.0) < 1e-10


def test_catch22_float32_output_dtype():
"""Test Catch22 does not raise on float32 input with outlier features.

Regression test: the outlier_series placeholder in _transform_case_numba was
hardcoded to float64, which numba's nopython mode could not unify with a
float32 z-normalised series produced for features 13/14 (outlier_include /
outlier_include_n), raising a TypingError for float32 input.
"""
X = np.random.default_rng(0).standard_normal((6, 1, 40)).astype(np.float32)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be replaced with the existing testing utils (make_example_3d_numpy) to generate 3D data. You need to keep the float32 cast

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use make_example_3d_numpy with the float32 cast kept — see db44123.


# outlier_norm=True exercises the fixed code path (features 13/14)
c22 = Catch22(outlier_norm=True, replace_nans=True)
result = c22.fit_transform(X)
assert result.shape == (6, 22)

# outlier_norm=False takes the other branch -- should still work
c22_no_norm = Catch22(outlier_norm=False, replace_nans=True)
result_no_norm = c22_no_norm.fit_transform(X)
assert result_no_norm.shape == (6, 22)
Loading