Skip to content

Conversation

@mruberry
Copy link
Collaborator

@mruberry mruberry commented Aug 6, 2020

This PR adds the torch.linalg namespace as part of our continued effort to be more compatible with NumPy. The namespace is tested by adding a single function, torch.linalg.outer, and testing it in a new test suite, test_linalg.py. It follows the same pattern that #41911, which added the torch.fft namespace, did.

Future PRs will likely:

  • add more functions to torch.linalg
  • expand the testing done in test_linalg.py, including legacy functions, like torch.ger
  • deprecate existing linalg functions outside of torch.linalg in preference to the new namespace

@mruberry mruberry added the module: numpy Related to numpy support, and also numpy compatibility of our operators label Aug 6, 2020
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Aug 6, 2020
@dr-ci
Copy link

dr-ci bot commented Aug 6, 2020

💊 CI failures summary and remediations

As of commit 962dec2 (more details on the Dr. CI page):


  • 3/3 failures possibly* introduced in this PR
    • 2/3 non-CircleCI failure(s)

1 job timed out:

  • pytorch_linux_bionic_py3_8_gcc9_test

ci.pytorch.org: 2 failed


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 9 times.

@mattip
Copy link
Contributor

mattip commented Aug 6, 2020

Here is the reference page for numpy.linalg. The equivalent pytorch functions:

done? NumPy (numpy.linalg) PyTorch (torch.* unless otherwise noted) notes (differences in arguments)
. dot dot pytorch does not broadcast, does not have an out argument
. multi-dot X does not exist yet
. vdot X If the first argument is complex the complex conjugate of the first argument is used for the calculation of the dot product.
. inner dot? but there are special cases ...
yes outer ger
. matmul matmul
. tensordot tensordot
. einsum einsum
. matrix_power Raise a square matrix to the (integer) power n. No stacked matrices
. kron
. cholesky cholesky
. qr qr interface for mode is different
. svd svd interface for mode is different
. eig eig interface to return both eigenvalues and eigenvectors is different
. eigh X
. eigvals X
. eigvalsh X
. norm norm
. cond X
. det det
. matrix_rank matrix_rank
. slog_det slogdet
. trace trace interface is different
. solve solve
. tensorsolve X numpy has an axes arg beyond solve
. lstsq lstsq numpy has an extra rcond arg
. inv inverse pytorch adds an out arg
. pinv pinverse numpy has an extra hermatian boolean arg
. tensorinv X inverse of tensordot

Should I move this to a tracking issue?

@mruberry
Copy link
Collaborator Author

mruberry commented Aug 6, 2020

@mattip A tracking issue with those functions would be great!

@mattip mattip mentioned this pull request Aug 6, 2020
4 tasks
@mruberry mruberry requested review from bhosmer and gchanan and removed request for bhosmer August 6, 2020 19:30
Tensor = torch.Tensor

# Note: This not only adds the doc strings for the spectral ops, but
# connects the torch.fft Python namespace to the torch._C._fft builtins.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# connects the torch.fft Python namespace to the torch._C._fft builtins.
# connects the torch.linalg Python namespace to the torch._C._linalg builtins.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! Thank you, @kurtamohler!

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mruberry merged this pull request in 9c8021c.

@mruberry mruberry deleted the linalg_namespace branch August 21, 2020 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged module: numpy Related to numpy support, and also numpy compatibility of our operators oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants