Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BUG: Callingsqueeze on a slice of a memmap raises cryptic error #25278

Closed
Labels
@WardBrian

Description

@WardBrian

Describe the issue:

Calling .squeeze() on a slice of a memmap that has shape(1,) raises

RuntimeError: ndarray subclass __array_wrap__ method returned an object which was not an instance of an ndarray subclass

Reproduce the code example:

importnumpyasnpimportstruct# set up filefilename='ex.bin'withopen(filename,'wb')asf:f.write(bytearray(struct.pack('d',3.14)))f.write(bytearray(struct.pack('d',6.28)))# mmap filearr=np.memmap(filename,dtype=np.float64,mode='r',shape=(2,1))print(arr)print(arr.squeeze())# worksprint(arr[1:2,0])print(np.array(arr)[1:2,0].squeeze())# worksprint(arr[1:2,0].squeeze())# fails

Error message:

Traceback (most recent call last):  File"/home/brian/Dev/cpp/ffistan/repr.py", line 18,in<module>print(arr[1:2,0].squeeze())# failsRuntimeError: ndarray subclass __array_wrap__ method returned an object which was not an instance of an ndarray subclass

Runtime information:

>>> import sys, numpy; print(numpy.__version__); print(sys.version)1.26.23.9.13 | packaged by conda-forge | (main, May 27 2022, 16:56:21) [GCC 10.3.0]
>>> print(numpy.show_runtime())WARNING: `threadpoolctl` not found in system! Install it by `pip install threadpoolctl`. Once installed, try `np.show_runtime` again for more detailed build information[{'numpy_version': '1.26.2',  'python': '3.9.13 | packaged by conda-forge | (main, May 27 2022, '            '16:56:21) \n'            '[GCC 10.3.0]',  'uname': uname_result(system='Linux', node='FlatTop', release='6.2.0-37-generic', version='#38~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov  2 18:01:13 UTC 2', machine='x86_64')}, {'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': ['AVX512_KNL', 'AVX512_KNM']}}]None

Context for the issue:

This operation seems well-defined for normal arrays but fails for memmaps. This violates the sentenceThe memmap object can be used anywhere an ndarray is accepted. in the documentation, and makes it difficult to write a library which relies onsqueeze in a generic way which is ambivalent to whether the user provided an array or memmap

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp