`xp.vecdot` output arrayness depends on NumPy version

Open
#355 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
numpy, python
Domain
data

Research direction

Start by reproducing the reported xp.vecdot behavior with NumPy versions below and above 2.0, then inspect the compatibility implementation for xp.vecdot. Confirm the chosen return type against the Array API requirement and add or update coverage for both version ranges; done means consistent behavior across them.

Written by the indexing model from the issue text.

Description

With NumPy >= 2.0:

import numpy as np
from scipy._lib._array_api import array_namespace
x1 = np.asarray([0.667, 0.667, 0.667])
x2 = np.asarray([0.123, 0.456, 0.789])
xp = array_namespace(x1, x2)
xp.vecdot(x1, x2)
# np.float64(0.912456)

With NumPy < 2.0, the result is a 0d array.

I'd suggest that array-api-compat should either:

  • make modern NumPy produce an array (for compliance with the standard) or
  • make old NumPy produce a NumPy float (for consistency with all NumPy functions).

The latter would be my preference for now. (Actually fixing NumPy would be the long term preference - https://github.com/mdhaber/numpy/pull/2).

Dominant language
Python
Stars
131
Forks
49
Avg merge
2d 8h
Merged PRs (30d)
6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from data-apis/array-api-compat

All issues in data-apis/array-api-compat

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.