Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: document np.linalg equivalent functions #16

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,60 @@ $ python -P -c'import gulinalg as g; g.test(verbosity=2)'
or use the standard `pytest` invocations.


--------------------------------------------------------------------------------

NumPy analogs
=============

This packages shares ancestry with `numpy.linalg`. In fact, about a half of
the `gulinalg` functionality is also available from `numpy.linalg`. We recommend
that existing users of `gulinalg` migrate to `numpy.linalg` using the following equivalence (NumPy functions below are from `np.linalg` namespace unless
explicitly namespaced with `np.`)

| `gulinalg` | `np.linalg` |
|:------------------------|:----------------------------------|
| `matrix_multiply(a, b)` | `a @ b`, `np.matmul(a, b)` |
| `inner1d(a, b)` | `vecdot(a.conj(), b)` |
| `dotc1d(a, b)` | `vecdot(a, b)` |
| `cholesky(a, b)` | `cholesky(a, b)` |
| `qr(a)` | `qr(a)` |
| `svd(a)` | `svd(a)` |
| `solve(a, b)` | `solve(a, b)` |
| `inv(a, b)` | `inv(a, b)` |
| `det(a, b)` | `det(a, b)` |
| `slogdet(a, b)` | `slogdet(a, b)` |
| `eig(a, b)` | `eig(a, b)` |
| `eigh(a, b)` | `eigh(a, b)` |
| `eigvals(a, b)` | `eigvals(a, b)` |
| `eigvalsh(a, b)` | `eigvalsh(a, b)` |



<!--| `matvec_multiply(a, b)` | `matvec(a, b)` (`numpy >= 2.2.0`) | -->

A few things to keep in mind when porting from `gulinalg` to `np.linalg`:

1. `np.linalg.vecdot` complex conjugates its first argument. Therefore for
complex-valued arguments it is equivalent to `gulinalg.dotc1d`, and for
real-valued arguments it is equivalent to `gulinalg.inner1d`.
2. For matrix factorization, `gulinalg` functions return tuples of arrays, while
`np.linalg` analogs return namedtuples.
3. For matrix factorizationsWhere the result is not unique (e.g., the
`QR`factorization is unique only up to a matching permutation of the rows of
the `Q` matrix and the columns of the `R` matrix),
`np.linalg` and `gulinalg` functions may return different, if equivalent, results.


Several `gulinalg` functions have no direct NumPy equivalents but are simple
to replicate manually, at least for 1D arguments:

| `gulinalg` | `np.linalg` |
|:--------------------------|:-----------------------------|
| `update_rank1(a, b, c)` | `np.outer(a, b) + c` |
| `innerwt(a, b, c)` | `np.linalg.vecdot(a * b, c)` |
| `quadratic_form(a, b, c`) | `a.T @ b @ c` |


--------------------------------------------------------------------------------


Expand Down
Loading