Skip to content

BUG: In numpy.array_api, divide and pow related functions/methods do not accept integer arrays #20752

Closed

Description

@honno

The Array API initially only allowed floating arrays and Python scalars for these functions, but has since allowed all numeric arrays/Python scalars. They currently do work for integer Python scalars, but are restricted from using integer arrays.

Power functions: xp.pow(), x.__pow()__ and x.__ipow()__
Divide functions: xp.divide(), x.__truediv__() and x.__itruediv__()

Note scalar scenarios can still fail as the left argument could be an integer array.

cc @asmeurer @IvanYashchuk

Reproduce the code example:

>>> import numpy.array_api as xp
>>> xp.asarray(2) / xp.asarray(2)
TypeError: Only floating-point dtypes are allowed in __truediv__
>>> xp.asarray(2) ** xp.asarray(2)
TypeError: Only floating-point dtypes are allowed in __pow__

NumPy/Python version information:

1.23.0.dev0+358.g1684a933d 3.8.10 (default, Nov 26 2021, 20:14:08)
[GCC 9.3.0]

Activity

  1. honno commented on Jan 6, 2022

    @honno
    MemberAuthor

    Will try submitting a patch for this tomorrow. Not sure if maintainers would want to backport things until the 2021 spec is actually finalised, or if at all.

  2. honno commented on Jan 7, 2022

    @honno
    MemberAuthor

    Floating arrays should be okay as-is if data-apis/array-api#362 passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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