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

linalg: Matrix norms #885

Merged
merged 24 commits into from
Dec 7, 2024
Merged

linalg: Matrix norms #885

merged 24 commits into from
Dec 7, 2024

Conversation

perazz
Copy link
Contributor

@perazz perazz commented Nov 6, 2024

Address #820 in joint effort with @jalvesz.
Compute matrix norms using LAPACK *LANGE backend.
Array $A$, real or complex, has general rank n>=2.

For higher ranks n>2, user may specify two dimensions dims(2) the norms should be computed along. dims == [1,2] is otherwise assumed by default.

Proposed implementation

  • na = mnorm(a [, order=1] [, dim=dim] [, err=err]): function interface

Key facts

  • The implementations supported by *LANGE are currently provided:

    • 1, '1': 1-norm or "maximum column sum", $\max_j \sum_i{ \left|a_{i,j}\right| }$
    • 2, '2': 2-norm or "maximum singular value", maxval(svdvals(a))
    • 'Euclidean','Frobenius','fro' (or order not provided): Frobenius norm, $\sqrt{\sum_{i,j}{ a_{i,j}^2}} $
    • 'inf', huge(0): $\infty$-norm or "maximum row sum", $\max_i \sum_j{ \left|a_{i,j}\right| }$
  • order can either be an integer (1, huge(0)) or a character input ('1', '2', 'inf', 'euclidean', ...). For similarity with NumPy/SciPy, this is an optional argument. If not provided, the Frobenius norm is computed.

Progress

  • base implementation
  • tests
  • documentation
  • submodule
  • examples

Prior art

  • Numpy: linalg.matrix_norm(x, /, *, keepdims=False, ord='fro')
  • Scipy: norm(a, ord=None, axis=None, keepdims=False, check_finite=True)

cc: @jvdp1 @jalvesz @loiseaujc

Copy link
Member

@jvdp1 jvdp1 left a comment

Choose a reason for hiding this comment

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

Thank you @perazz and @jalvesz for this PR. It looks really good to me.

doc/specs/stdlib_linalg.md Outdated Show resolved Hide resolved
doc/specs/stdlib_linalg.md Show resolved Hide resolved
Co-authored-by: Jeremie Vandenplas <[email protected]>
doc/specs/stdlib_linalg.md Outdated Show resolved Hide resolved
@perazz
Copy link
Contributor Author

perazz commented Nov 18, 2024

Thank you for the review @jvdp1. What do you and @loiseaujc think of the name mnorm for matrix norms? I think it's a good compromise to differentiate matrix and vector norms, and maybe more clear than opnorm? (m=matrix?)

src/stdlib_linalg.fypp Outdated Show resolved Hide resolved
@jalvesz
Copy link
Contributor

jalvesz commented Nov 20, 2024

Thanks for this nice work @perazz, LGTM! On my side, no additional remarks. If there are no objections with the naming convention I would say this PR is ready.

@perazz
Copy link
Contributor Author

perazz commented Nov 27, 2024

@jalvesz @jvdp1 thank you for the reviews, and @fortran-lang/stdlib, if there are no further comments, I believe this may be merged soon.

@perazz perazz merged commit 38485d8 into fortran-lang:master Dec 7, 2024
16 checks passed
@perazz perazz deleted the matrix_norma branch December 7, 2024 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants