Skip to content

np.linalg.norm is broken with float32 and arrays > 2 ** 28 #9852

@kohr-h

Description

@kohr-h

I get this:

>>> a = np.ones(2 ** 28, dtype='float32')
>>> np.linalg.norm(a) == np.sqrt(a.size)
True
>>> a = np.ones(2 ** 28 + 2 ** 12 + 1024, dtype='float32')
>>> np.isclose(np.linalg.norm(a), np.sqrt(a.size))
True
>>> a = np.ones(2 ** 28 + 2 ** 12 + 2048, dtype='float32')
>>> np.isclose(np.linalg.norm(a), np.sqrt(a.size))
False

For float64, everything is fine even with size 2 ** 32, so 32-bit integer indices are not the immediate issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions