question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API for variable number of returns in linalg

See original GitHub issue

Feedback from @mruberry: it may be nice to support always returning the same type from functions like Cholesky, with tensors accessed by names. That way frameworks could return additional tensors and there wouldn’t be BC-compatibility issues if more tensor returns are added later. This suggestion, however, comes from a place of “it’d be nice if people wanted to use this API”, as opposed to the perspective of, “this API is a lowest common denominator only intended for library writers.”

cholesky always return a single array, so I thought it’d be fine - but the comment may be related to https://github.com/pytorch/pytorch/issues/47608 (desire to return an error code rather than raise a RuntimeError for failures). For qr, svd and perhaps some more functions there’s the related issue of different returns based on keywords. Using a class to stuff all return values in is a common design pattern for, e.g., scipy.optimize. I’m not convinced it’s a good idea for the linalg functions here, but worth considering at least.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
rgommerscommented, Jan 29, 2021

I re-read https://github.com/pytorch/pytorch/issues/46187, and PyTorch deviated on purpose from NumPy in the new design by always return a tuple with the max number of elements if there’s a boolean keyword to control number of returns in NumPy (e.g., svd(x, compute_uv=False) return an array in NumPy and a tuple (tensor([]), S, tensor([]) in PyTorch. The rationale is that this is much easier for the JIT; doing overloads on the boolean keyword is a pain.

The conclusion from that issue was that indeed dataclasses would be desirable long-term.

1reaction
asmeurercommented, Dec 2, 2020

I don’t understand the technical details of that pytorch issue. Does it mean that any API that raises an exception is potentially problematic?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using linalg.block_diag for variable number of blocks
So for example, let's say I have: a , b , c -> some matrices matrix_list = [a, b, c] It's happy with:...
Read more >
Linear algebra (numpy.linalg) — NumPy v1.24 Manual
linalg.cond (x[, p]). Compute the condition number of a matrix. ; linalg.det (a). Compute the determinant of an array. ; linalg.matrix_rank (A[, tol,...
Read more >
scipy.linalg.expm — SciPy v1.9.3 Manual
Implements the algorithm given in [1], which is essentially a Pade approximation with a variable order that is decided based on the array...
Read more >
14.2.41 Class Variable — MOSEK Fusion API for Python 10.0.33
Return a variable of size one corresponding to a single element in the variable object. i1 ( int ) – Index in the...
Read more >
Statistics in Python: Multiple Linear Regression - Menu
Multiple linear regression, if there are two independent variables, ... Perform multiple linear regression returns = np.linalg.lstsq(xy, z, rcond=None).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found