Skip to content

__str__ and __repr__ of array_api_strict arrays #112

Closed
@ev-br

Description

@ev-br

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions