RFC: `linalg.outer` support batches of vectors

Open
#242 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
numpy, pytorch
Domain
api

Research direction

Start with the linked linalg.outer specification and review the PyTorch and NumPy behavior cited in the issue, then read the discussion in pytorch/pytorch#63293. Done means the Array API community has agreed on batched-input semantics and updated the linalg.outer specification accordingly.

Written by the indexing model from the issue text.

Description

API change RFC status: Blocked topic: Linear Algebra

Current Status

Current API spec defines the linalg.outer behaviour for one-dimensional vector inputs only.

Quoting from the docs.

Computes the outer product of two vectors x1 and x2 .
Parameters

  • x1 :
    • first one-dimensional input array of size N . Should have a numeric data type.
  • x2 :
    • second one-dimensional input array of size M . Should have a numeric data type.

Proposal

Most of the array/tensor libraries involve the manipulation and usage of batched vectors. It would be worth considering batch support in linalg.outer for the Array API standard, instead of only the 1D Vectors. This will also make linalg.outer more in line with the behaviour offered by other linalg functions in the spec which generally take in an nd-array/tensor.


Interestingly

  • PyTorch currently has torch.outer which also only supports 1d Tensors.
  • NumPy though supports nd-arrays with numpy.outer, but the behaviour is to flatten the inputs to 1d Vectors in case the input is not already 1-dimensional.

This was initially discussed in pytorch/pytorch#63293.

cc @Lezcano @rgommers

Dominant language
Python
Stars
281
Forks
52
PR merge metrics
No merged PRs in 30d

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

All issues in data-apis/array-api

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.