Skip to content

[BUG] Preserve float precision in Numba helpers - #3726

Open
cakeni wants to merge 7 commits into
aeon-toolkit:mainfrom
cakeni:codex/float32-numba-outputs
Open

[BUG] Preserve float precision in Numba helpers#3726
cakeni wants to merge 7 commits into
aeon-toolkit:mainfrom
cakeni:codex/float32-numba-outputs

Conversation

@cakeni

@cakeni cakeni commented Aug 9, 2026

Copy link
Copy Markdown

Reference Issues/PRs

Fixes #3720. See also #3707, which addresses the same dtype class in separate z-normalisation helpers.

What does this implement/fix? Explain your changes.

Allocates outputs using the dtype produced by true division of the input. This keeps float32 inputs as float32 across all six affected Numba helpers while preserving the existing float64 output for integer and float64 inputs. A focused regression test covers every returned array from the six helpers.

The calculation loops are unchanged; only output allocation dtype is corrected. If #3707 merges first, its changes touch the same module but this fix does not depend on them.

Does your contribution introduce a new dependency? If yes, which one?

No.

Any other comments?

Validation performed locally:

  • .venv\Scripts\python.exe -m pytest -o addopts='' aeon/utils/numba/tests/test_general.py -q — 42 passed
  • .venv\Scripts\python.exe -m pytest -o addopts='' aeon/utils/numba/tests/test_general.py -q --nonumba true — 42 passed
  • .venv\Scripts\python.exe -m pytest -o addopts='' aeon/distances/elastic/tests/test_distance_correctness.py -q — 2 passed
  • .venv\Scripts\python.exe -m pytest -o addopts='' aeon/similarity_search/subsequence/tests/test_mass.py -q — 9 passed
  • .venv\Scripts\pre-commit.exe run --files aeon/utils/numba/general.py aeon/utils/numba/tests/test_general.py — all hooks passed

PR checklist

For all contributions
  • I will use @all-contributors after this PR has been merged.
  • The PR title starts with either [ENH], [MNT], [DOC], [BUG], [REF], [DEP] or [GOV] indicating whether the PR topic is related to enhancement, maintenance, documentation, bugs, refactoring, deprecation or governance.

This pull request includes code written with the assistance of AI.
The code has not yet been reviewed by a human.

This pull request includes code written with the assistance of AI.
The code has **not yet been reviewed** by a human.
@aeon-actions-bot aeon-actions-bot Bot added the bug Something isn't working label Aug 9, 2026
@aeon-actions-bot

Copy link
Copy Markdown
Contributor

Thank you for contributing to aeon

I have added the following labels to this PR based on the title: [ bug ].

The Checks tab will show the status of our automated tests. You can click on individual test runs in the tab or "Details" in the panel below to see more information if there is a failure.

If our pre-commit code quality check fails, please run pre-commit locally and push the fixes to your PR branch.

Don't hesitate to ask questions on the aeon Discord channel if you have any.

PR CI actions

These checkboxes will add labels to enable or disable CI functionality for this PR. This may not take effect immediately, and a new commit may be required to run the new configuration.

  • Run pre-commit checks for all files
  • Run mypy typecheck tests
  • Run all pytest tests and configurations
  • Run all notebook example tests
  • Run numba-disabled codecov tests
  • Disable numba cache loading
  • Regenerate expected results for testing
  • Push an empty commit to re-run CI checks

@baraline

Copy link
Copy Markdown
Member

Hi, thanks for working on this.

I'll wait for #3707 to get in first, as we would want to re-use (or adapt) some functions declared there to initialize arrays with the correct dtype, instead of re-declaring the X / 1 trick everywhere.

Other than that it looks correct, will review better when the other PR is in.

@baraline

Copy link
Copy Markdown
Member

hi @cakeni the first PR is in. Could you try to uniformize what you done to use the same reasoning ?

TonyBagnall and others added 3 commits August 26, 2026 21:59
This pull request includes code written with the assistance of AI.\nThe code has **not yet been reviewed** by a human.
@cakeni

cakeni commented Aug 27, 2026

Copy link
Copy Markdown
Author

Done — I’ve updated the dtype initialization to reuse _as_normalised_float from #3707 and synced the branch with the latest main. The focused tests are passing.

@baraline baraline left a comment

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.

Just one small comment on the test data and we can merge this, good job !

Comment thread aeon/utils/numba/tests/test_general.py Outdated
@pytest.mark.parametrize("dtype", DATATYPES)
def test_float_output_dtype_follows_input_precision(dtype):
"""Test helpers preserve float precision and promote integer input."""
X = np.arange(24, dtype=dtype).reshape(2, 12)

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.

Could you just replace this with the testing.utils function to generate data ? (and cast it to the dtype)

"""
n_channels, _ = X.shape
values = np.zeros((n_channels, length))
values = np.zeros((n_channels, length), dtype=_as_normalised_float(X[:0]).dtype)

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.

It's not "pretty", but doing things like :

def _as_normalised_float_dtype(input_dtype):
   if input_dtype == np.float32 return np.float64 else return np.float32

Is not possible inside numba functions (or at least not without overcomplicating things), so we'll go with this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] utils/numba/general.py returns float64 for float32 input in six functions

3 participants