Skip to content

BUG: Add test to reproduce problem described in #30816#30818

Merged
seberg merged 7 commits intonumpy:mainfrom
denialhaag:ubuntu-arm-norm
Mar 23, 2026
Merged

BUG: Add test to reproduce problem described in #30816#30818
seberg merged 7 commits intonumpy:mainfrom
denialhaag:ubuntu-arm-norm

Conversation

@denialhaag
Copy link
Copy Markdown
Contributor

@denialhaag denialhaag commented Feb 11, 2026

This PR adds a test case and fixes #30816.

@seberg seberg added the 57 - Close? Issues which may be closable unless discussion continued label Feb 11, 2026
@seberg
Copy link
Copy Markdown
Member

seberg commented Feb 11, 2026

If CI fails, that might be interesting for gh-30816. Otherwise, this PR can be closed probably. If it fails, it might make sense to convert it to a proper test. But then without the npy file, etc.)

@seberg seberg marked this pull request as draft February 11, 2026 12:34
@denialhaag
Copy link
Copy Markdown
Contributor Author

denialhaag commented Feb 11, 2026

@seberg, thanks a lot for triggering the CI. The run reflects the issue quite well, as the added test only fails in *linux_aarch64 containers, while any other platform-architecture combination seems fine. I'd be happy to try to create a proper test in numpy/linalg/tests/test_regession.py.

@seberg
Copy link
Copy Markdown
Member

seberg commented Feb 11, 2026

Yeah, does indeed reproduce, nice:

      def test_norm():
          test_array_path = Path(__file__).parent / "test_array.npy"
          test_array = np.load(test_array_path)
          norm = np.linalg.norm(test_array)
          print(f"norm = {norm}")
  >       assert np.isclose(norm, 1.0)
  E       assert np.False_
  E        +  where np.False_ = <function isclose at 0xff0eb80413f0>(np.float64(nan), 1.0)
  E        +    where <function isclose at 0xff0eb80413f0> = np.isclose
  
  norm       = np.float64(nan)
  test_array = array([ 0.00367843-0.00350762j,  0.00259778-0.01135681j,
         -0.00356539-0.00070692j, ...,  0.00231578-0.00841487j,
         -0.00324557+0.0058289j , -0.00042056-0.00383656j], shape=(15625,))
  test_array_path = PosixPath('/tmp/tmp.mCkoin/venv/lib/python3.12/site-packages/numpy/tests/test_array.npy')

@denialhaag
Copy link
Copy Markdown
Contributor Author

@seberg, sorry that I didn't get back to this. Frankly speaking, I still don't understand where exactly the problem lies. Our test vector is rather large (5**6) and complex-valued, so it could be related to either of these two factors. I'll try to find time later today to create an example using np.random!

@denialhaag
Copy link
Copy Markdown
Contributor Author

denialhaag commented Mar 16, 2026

@seberg, the test I just added seems more reasonable to me. It only fails on the linux-24.04-arm runner in our CI, and I'm "hopeful" it fails here as well. 🤞

@denialhaag
Copy link
Copy Markdown
Contributor Author

One observation: The test below passes on all platforms, so the problem is not just array size.

def test_norm_linux_arm(self) -> None:
    a = np.arange(20000)
    norm = np.linalg.norm(a)
    assert_almost_equal(norm, 1632931.9244843002)

@mattip
Copy link
Copy Markdown
Member

mattip commented Mar 17, 2026

There is a linting failure

@mattip
Copy link
Copy Markdown
Member

mattip commented Mar 17, 2026

Interesting. So the test passes when using ints, but fails for complex:

      def test_norm_linux_arm(self):
          # gh-30816
          a = np.arange(20000) / 50000
          b = a + 1j * np.roll(np.flip(a), 12345)
          norm = np.linalg.norm(b)
  >       assert_almost_equal(norm, 46.18628948075393)
  E       AssertionError: 
  E       Arrays are not almost equal to 7 decimals
  E        ACTUAL: np.float64(1.5141196919662592)
  E        DESIRED: 46.18628948075393

@mattip
Copy link
Copy Markdown
Member

mattip commented Mar 18, 2026

I pushed an update to use the new scipy-openblas 0.31.159.0, which will report its version number in the meson build and in show_runtime. One test should fail since I did not update the release build as well, lets see if the new test passes now. For a follow-up, we should add testing for show_runtime and/or threadpoolctl that the version listed in requirements/ci_requirements.txt is the one used in the build.

@mattip
Copy link
Copy Markdown
Member

mattip commented Mar 18, 2026

In this comment, NumPy 2.4.3 successfully passes the test if the shared object from scipy-openblas64==0.3.31.126.1 is used to replace the shared object from the wheel. This is strange, since they are supposed to be the same shared object, just with some RPATH twiddling. In this PR, I see at the beginning of tests that show_config is correctly reporting the new version of scipy-openblas but the test is failing. I am at a loss to explain what is going on. Maybe because the tests run in a docker quay.io/pypa/manylinux_2_28_aarch64:2026.03.01-1? I do not have access to a machine that exhibits the failure.

@mattip
Copy link
Copy Markdown
Member

mattip commented Mar 18, 2026

Progress. I found a cfarm build machine with SVE. I can reproduce the problem using the test here. It reproduces with all the scipy-openblas wheels. I will respond on the issue.

@mattip
Copy link
Copy Markdown
Member

mattip commented Mar 21, 2026

I updated scipy-openblas but apparently pypi has not percolated the change out yet. Restarting the failing CI to get the newer version.

@mattip
Copy link
Copy Markdown
Member

mattip commented Mar 21, 2026

the new test is passing. The failure is because I did not update the numpy/numpy-release repo with the newer scipy-openblas version.

@mattip
Copy link
Copy Markdown
Member

mattip commented Mar 23, 2026

the updated scipy-openblas is now part of the requirements for numpy-release, and rerunning the failing check tests now passes. @denialhaag can you confirm this fixes the problem?

@denialhaag
Copy link
Copy Markdown
Contributor Author

Yes, looks good to me! Thanks a lot for all the effort!

@denialhaag denialhaag marked this pull request as ready for review March 23, 2026 09:10
Copy link
Copy Markdown
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

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

Thanks for the testing @denialhaag and figuring out the issue Matti!

@seberg seberg merged commit 0f16a04 into numpy:main Mar 23, 2026
91 of 103 checks passed
@seberg seberg added 09 - Backport-Candidate PRs tagged should be backported and removed 57 - Close? Issues which may be closable unless discussion continued labels Mar 23, 2026
@denialhaag denialhaag changed the title BUG: Add test to reproduce problem described in #30816 BUG: Fix np.linalg.norm on ARM Linux Mar 23, 2026
@denialhaag denialhaag changed the title BUG: Fix np.linalg.norm on ARM Linux BUG: Add test to reproduce problem described in #30816 Mar 23, 2026
charris pushed a commit to charris/numpy that referenced this pull request Mar 23, 2026
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Mar 23, 2026
charris added a commit that referenced this pull request Mar 23, 2026
BUG: Add test to reproduce problem described in #30816 (#30818)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: np.linalg.norm returns different value on ubuntu-24.04-arm runner after update to 2.4.2

4 participants