Description
Describe the issue:
All arrays imported from dlpacks come out set readonly.
It looks like initially setting the writeable flag was overlooked when flags are passed as 0
at
numpy/numpy/_core/src/multiarray/dlpack.c
Lines 704 to 705 in 9389862
numpy/numpy/_core/src/multiarray/dlpack.c
Lines 710 to 712 in 9389862
Reproduce the code example:
import numpy as np
original_array = np.array([0])
imported_array = np.from_dlpack(original_array)
imported_array[0] = 1
imported_array.flags.writeable = True
Error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: assignment destination is read-only
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: cannot set WRITEABLE flag to True of this array
Python and NumPy Versions:
2.2.4
3.12.3 (main, Feb 4 2025, 14:48:35) [GCC 13.3.0]]
Runtime Environment:
[{'numpy_version': '2.2.4',
'python': '3.12.3 (main, Feb 4 2025, 14:48:35) [GCC 13.3.0]',
'uname': uname_result(system='Linux', node='LAPTOP-JDTFCTMR', release='5.15.167.4-microsoft-standard-WSL2', version='#1 SMP Tue Nov 5 00:21:55 UTC 2024', machine='x86_64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3', 'SSE41', 'POPCNT', 'SSE42'],
'not_found': ['AVX',
'F16C',
'FMA3',
'AVX2',
'AVX512F',
'AVX512CD',
'AVX512_KNL',
'AVX512_KNM',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL']}},
{'architecture': 'Katmai',
'filepath': '/home/karl3/.local/lib/python3.12/site-packages/numpy.libs/libscipy_openblas64_-6bb31eeb.so',
'internal_api': 'openblas',
'num_threads': 3,
'prefix': 'libscipy_openblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.28'}]
Context for the issue:
This issue prevents the use of numpy for writing into aliased data from other tensor libraries or in general contexts using the array api. I was implementing a lightweight n-dimensional large integer class, using views to change between unsigned and signed representations.