Skip to content

ENH: Use strict for xp_test functions to toggle comparing a scalar with an array. #724

@prady0t

Description

@prady0t

Currently, the private xp test functions cannot compare a scaler with an array, even though we are ultimately using np.testing, we check for the equality of the total number of elements before:

actual_size = math.prod(actual_shape) # pyright: ignore[reportUnknownArgumentType]

To align more with numpy testing behaviour, we can use the strict parameter to check for this. If set to true, do the above check, if False check if it can broadcast. See the numpy example here.

An even cleaner solution would be to remove the above check entirely and pass the strict parameter directly to the np.testing function call. The current numpy behaviour is different from what's suggested by these comments:

# Ignore shape, but check flattened size. This is normally done by

Either it refers to an older version of numpy testing, or I'm missing something.

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