Skip to content

BUG: For integer arguments, round returns a view while ceil returns a copy #29124

@ev-br

Description

@ev-br

Describe the issue:

I expected that all of ceil, trunc and round always return either a view or a copy for all dtypes. However, for integer arguments, round returns a view for integer inputs and a copy for float inputs.
ceil and floor all return a copy for both integers and floats.

IIUC the return dtype was changed in numpy 2.0, so this looks like a small omission.

Reproduce the code example:

In [13]: for func in [np.round, np.ceil, np.trunc]:
    ...:     for dt in [int, float]:
    ...:         a = np.arange(3, dtype=dt)
    ...:         b = func(a)
    ...:         is_view = np.shares_memory(a, b)
    ...:         print(f"{func.__name__}  {a.dtype} : {is_view}")
    ...: 
round  int64 : True
round  float64 : False
ceil  int64 : False
ceil  float64 : False
trunc  int64 : False
trunc  float64 : False

Error message:

.

Python and NumPy Versions:

In [5]: np.__version__
Out[5]: '2.4.0.dev0+git20250603.ff1d6cc'

Runtime Environment:

In [14]: np.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': '2.4.0.dev0+git20250603.ff1d6cc',
  'python': '3.12.10 | packaged by conda-forge | (main, Apr 10 2025, 22:21:13) '
            '[GCC 13.3.0]',
  'uname': uname_result(system='Linux', node='gonzales', release='5.15.0-76-generic', version='#83~20.04.1-Ubuntu SMP Wed Jun 21 20:23:31 UTC 2023', 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',
                                    'AVX512_SPR']}}]

Context for the issue:

Found in data-apis/array-api-compat#333 which aims to make sure that array_api_compat.numpy does not change the view/copy semantics of numpy itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    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