8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
numpy.clip
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
For some min-max values numpy.clip changes input dtype like in the example below
import numpy as np x = np.ones(1, dtype=np.float16) print(np.clip(x, 0, 255).dtype) # np.float16 print(np.clip(x, 0, 256).dtype) # np.float32
No response
1.25.1 3.9.5 (default, Jun 4 2021, 12:28:51) [GCC 7.5.0] [{'numpy_version': '1.25.1', 'python': '3.9.5 (default, Jun 4 2021, 12:28:51) \n[GCC 7.5.0]', 'uname': uname_result(system='Linux', node='skynet', release='5.19.0-46-generic', version='#47~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Jun 21 15:35:31 UTC 2', machine='x86_64')}, {'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'], 'found': ['SSSE3', 'SSE41', 'POPCNT', 'SSE42', 'AVX', 'F16C', 'FMA3', 'AVX2'], 'not_found': ['AVX512F', 'AVX512CD', 'AVX512_KNL', 'AVX512_KNM', 'AVX512_SKX', 'AVX512_CLX', 'AVX512_CNL', 'AVX512_ICL']}}, {'architecture': 'Zen', 'filepath': '/home/vovaf709/miniconda3/lib/python3.9/site-packages/numpy.libs/libopenblas64_p-r0-7a851222.3.23.so', 'internal_api': 'openblas', 'num_threads': 12, 'prefix': 'libopenblas', 'threading_layer': 'pthreads', 'user_api': 'blas', 'version': '0.3.23'}] None
The text was updated successfully, but these errors were encountered:
This will be fixed by #23912, which uses NEP 50 semantics.
Sorry, something went wrong.
As a workaround, you can explicitly specify an out array with the same shape as x:
out
x
In [3]: o = np.ones(x.shape, dtype=np.float16) In [4]: np.clip(x, 0, 256, out=o) Out[4]: array([1.], dtype=float16) In [5]: print(o.dtype) float16
You can also set NPY_PROMOTION_STATE=weak before you start python to opt into the NEP 50 promotion semantics.
NPY_PROMOTION_STATE=weak
Closing since this is a known issue that will be fixed by switching to weak promotion by default.
Nice, thx!
No branches or pull requests
Describe the issue:
For some min-max values
numpy.clip
changes input dtype like in the example belowReproduce the code example:
Error message:
No response
Runtime information:
1.25.1
3.9.5 (default, Jun 4 2021, 12:28:51)
[GCC 7.5.0]
[{'numpy_version': '1.25.1',
'python': '3.9.5 (default, Jun 4 2021, 12:28:51) \n[GCC 7.5.0]',
'uname': uname_result(system='Linux', node='skynet', release='5.19.0-46-generic', version='#47~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Jun 21 15:35:31 UTC 2', machine='x86_64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2'],
'not_found': ['AVX512F',
'AVX512CD',
'AVX512_KNL',
'AVX512_KNM',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL']}},
{'architecture': 'Zen',
'filepath': '/home/vovaf709/miniconda3/lib/python3.9/site-packages/numpy.libs/libopenblas64_p-r0-7a851222.3.23.so',
'internal_api': 'openblas',
'num_threads': 12,
'prefix': 'libopenblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.23'}]
None
Context for the issue:
No response
The text was updated successfully, but these errors were encountered: