Skip to content

BUG: 1.24.0 introduces inconsistent array(arr, copy=False) behavior based on byte order and dtype declaration  #22897

@rsokl

Description

@rsokl

Describe the issue:

Starting in numpy 1.24.0 array(big_end_arr, copy=False, dtype=big_end_arr.dtype) will return a view instead a reference, whereas array(big_end_arr, copy=False) returns a reference. This specifically impacts big-endian byte orderings.

Reproduce the code example:

from numpy import array

lil_a = array(0, dtype="<f8")
lil_b_impl_dtype = array(lil_a, copy=False)
lil_b_expl_dtype = array(lil_a, copy=False, dtype="<f8")

assert lil_a is lil_b_impl_dtype
assert lil_a is lil_b_expl_dtype

big_a = array(0, dtype=">f8")
big_b_impl_dtype = array(big_a, copy=False)
big_b_expl_dtype = array(big_a, copy=False, dtype=">f8")

assert big_a is big_b_impl_dtype

assert big_b_expl_dtype.base is big_a
assert big_a is big_b_expl_dtype  # FAILS

Error message:

No response

Runtime information:

[{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
                      'found': ['SSSE3',
                                'SSE41',
                                'POPCNT',
                                'SSE42',
                                'AVX',
                                'F16C',
                                'FMA3',
                                'AVX2',
                                'AVX512F',
                                'AVX512CD',
                                'AVX512_SKX',
                                'AVX512_CLX',
                                'AVX512_CNL',
                                'AVX512_ICL'],
                      'not_found': []}},
 {'architecture': 'SkylakeX',
  'filepath': 'C:\\Users\\rsokl\\miniconda3\\envs\\py310\\Lib\\site-packages\\numpy\\.libs\\libopenblas64__v0.3.21-gcc_10_3_0.dll',
  'internal_api': 'openblas',
  'num_threads': 8,
  'prefix': 'libopenblas',
  'threading_layer': 'pthreads',
  'user_api': 'blas',
  'version': '0.3.21'}]
None

Context for the issue:

MyGrad CI caught this error using Hypothesis. See this test

Metadata

Metadata

Assignees

No one assigned

    Labels

    00 - Bug57 - Close?Issues which may be closable unless discussion continued

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions