8000 BUG: `numpy.clip` doesn't maintain dtype · Issue #24253 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
BUG: numpy.clip doesn't maintain dtype #24253
Closed
@vovaf709

Description

@vovaf709

Describe the issue:

For some min-max values numpy.clip changes input dtype like in the example below

Reproduce the code example:

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

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

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

      0