Skip to content
New issue

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

__str__ and __repr__ of array_api_strict arrays #112

Open
ev-br opened this issue Dec 16, 2024 · 0 comments
Open

__str__ and __repr__ of array_api_strict arrays #112

ev-br opened this issue Dec 16, 2024 · 0 comments

Comments

@ev-br
Copy link
Contributor

ev-br commented Dec 16, 2024

Currently, both str and repr ---- I guess --- inherit from numpy, thus 0D arrays look like scalars when printed:

In [16]: xp.asarray(1).__repr__()
Out[16]: 'Array(1, dtype=array_api_strict.int64)'

In [17]: xp.asarray(1).__str__()
Out[17]: '1'

For ndim > 1 str is also inherited from numpy, and printed arrays look like lists only without commas.

In [18]: xp.asarray([1, 2, 3]).__str__()
Out[18]: '[1 2 3]'

In [19]: xp.asarray([1, 2, 3]).__repr__()
Out[19]: 'Array([1, 2, 3], dtype=array_api_strict.int64)'

It might make sense to make __str__ identical to __repr__, if only to some confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant