-
Notifications
You must be signed in to change notification settings - Fork 191
linalg: Moore-Penrose pseudo-inverse (pinv
)
#899
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
Merged
Merged
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
f5de00f
copy in code
perazz 9d35084
copy in tests
perazz c54b959
adjust templates
perazz 37612f6
submodule
perazz 73f9742
document interfaces
perazz 2e4f1a0
sync operator behavior with `.inv.` (return NaNs on error)
perazz 61bf91c
write specs
perazz 59a881d
add example
perazz 523bf4c
fix spec link
perazz 098d9b8
relax test tolerance (gcc-12 failure)
perazz 76368a0
do not `use stdlib_linalg`
perazz 3d10d39
Update src/stdlib_linalg_pinv.fypp
perazz 38bae4d
Update src/stdlib_linalg_pinv.fypp
perazz ce36d85
Merge branch 'fortran-lang:master' into pseudo_inverse
perazz bf02cd7
use `gemm` instead of `matmul`
perazz 16a394a
Update doc/specs/stdlib_linalg.md
perazz 8912cf9
Update doc/specs/stdlib_linalg.md
perazz 9dc5cc9
fix comment
perazz 8297763
`loadtxt/savetxt`: export array size in error message
perazz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
! Matrix pseudo-inversion example: function, subroutine, and operator interfaces | ||
program example_pseudoinverse | ||
use stdlib_linalg, only: pinv, pseudoinvert, operator(.pinv.), linalg_state_type | ||
implicit none(type,external) | ||
|
||
real :: A(15,5), Am1(5,15) | ||
type(linalg_state_type) :: state | ||
integer :: i, j | ||
real, parameter :: tol = sqrt(epsilon(0.0)) | ||
|
||
! Generate random matrix A (15x15) | ||
call random_number(A) | ||
|
||
! Pseudo-inverse: Function interfcae | ||
Am1 = pinv(A, err=state) | ||
print *, 'Max error (function) : ', maxval(abs(A-matmul(A, matmul(Am1,A)))) | ||
|
||
! User threshold | ||
Am1 = pinv(A, rtol=0.001, err=state) | ||
print *, 'Max error (rtol=0.001): ', maxval(abs(A-matmul(A, matmul(Am1,A)))) | ||
|
||
! Pseudo-inverse: Subroutine interface | ||
call pseudoinvert(A, Am1, err=state) | ||
|
||
print *, 'Max error (subroutine): ', maxval(abs(A-matmul(A, matmul(Am1,A)))) | ||
|
||
! Operator interface | ||
Am1 = .pinv.A | ||
|
||
print *, 'Max error (operator) : ', maxval(abs(A-matmul(A, matmul(Am1,A)))) | ||
|
||
end program example_pseudoinverse |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.