Skip to content

linalg: determinant #798

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 29 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4a4b899
import files
perazz Apr 13, 2024
d54cfa3
add `pure` interface
perazz Apr 13, 2024
c987fa1
add operator interface
perazz Apr 13, 2024
b9a3b0e
add tests
perazz Apr 13, 2024
4a29219
make `pure`
perazz Apr 13, 2024
3d05cc3
remove `xdp`
perazz Apr 13, 2024
4beab1f
Documentation
perazz Apr 13, 2024
15023e1
`submodule version`
perazz Apr 14, 2024
5923a54
Update src/stdlib_linalg.fypp
perazz Apr 15, 2024
31cdc84
Update src/stdlib_linalg.fypp
perazz Apr 15, 2024
45a606f
add `det` example
perazz Apr 15, 2024
cacb585
Update src/stdlib_linalg_determinant.fypp
perazz Apr 15, 2024
5c16ff8
Update src/stdlib_linalg_determinant.fypp
perazz Apr 15, 2024
ab030c5
Update src/stdlib_linalg_determinant.fypp
perazz Apr 15, 2024
13bd98a
warn about `xdp`
perazz Apr 15, 2024
7bf7141
Merge branch 'determinant' of github.com:perazz/stdlib into determinant
perazz Apr 15, 2024
504d90d
cleanup xdp notes
perazz Apr 15, 2024
e80b508
spacing
perazz Apr 15, 2024
c6076ea
relax error thresholds
perazz Apr 15, 2024
eaebe5c
restore `pure` attribute
perazz Apr 15, 2024
5d52d48
Update test/linalg/test_linalg_determinant.fypp
perazz Apr 15, 2024
cff995d
add docs
perazz Apr 21, 2024
2fe2428
link to specs
perazz Apr 21, 2024
45447a8
Update doc/specs/stdlib_linalg.md
perazz Apr 21, 2024
3ee20ad
Update doc/specs/stdlib_linalg.md
perazz Apr 21, 2024
1e50115
Update doc/specs/stdlib_linalg.md
perazz Apr 21, 2024
fe933ad
Update doc/specs/stdlib_linalg.md
perazz Apr 21, 2024
59dae89
Update doc/specs/stdlib_linalg.md
perazz Apr 21, 2024
3c72b06
Update doc/specs/stdlib_linalg.md
perazz Apr 21, 2024
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
Prev Previous commit
Next Next commit
add docs
  • Loading branch information
perazz committed Apr 21, 2024
commit cff995d60405dd814b32266e74267e8080572008
73 changes: 73 additions & 0 deletions doc/specs/stdlib_linalg.md
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,76 @@ Specifically, upper Hessenberg matrices satisfy `a_ij = 0` when `j < i-1`, and l
```fortran
{!example/linalg/example_is_hessenberg.f90!}
```

## `det` - Computes the determinant of a square matrix

### Status

Experimental

### Description

This function computes the determinant of a real square matrix.

This interface comes with a `pure` version `det(a)`, and a non-pure version `det(a,overwrite_a,err)` that
allows for more expert control.

### Syntax

`c = ` [[stdlib_linalg(module):det(interface)]] `(a,overwrite_a,err)`

### Arguments

`a`: Shall be a rank-2 square array

`overwrite_a` (optional): Shall be an input `logical` flag. if `.true.`, input matrix `a` will be used as temporary storage and overwritten. This avoids internal data allocation.

`err` (optional): Shall be a `type(linalg_state_type)` return value.

### Return value

Returns a real scalar value that represents the determinnt of the matrix.

Raises `LINALG_ERROR` if the matrix is singular.
Raises `LINALG_VALUE_ERROR` if the matrix is non-square.
Exceptions are returned to the `err` argument if provided; an `error stop` is triggered otherwise.

### Example

```fortran
{!example/linalg/example_determinant.f90!}
```

## `.det.` - Determinant operator of a square matrix

### Status

Experimental

### Description

This operator returns the determinant of a real square matrix.

This interface is equivalent to the `pure` version of determinant [[stdlib_linalg(module):det(interface)]].

### Syntax

`c = ` [[stdlib_linalg(module):operator(.det.)(interface)]] `(a)`

### Arguments

`a`: Shall be a rank-2 square array

### Return value

Returns a real scalar value that represents the determinnt of the matrix.

Raises `LINALG_ERROR` if the matrix is singular.
Raises `LINALG_VALUE_ERROR` if the matrix is non-square.
Exceptions trigger an `error stop`.

### Example

```fortran
{!example/linalg/example_determinant2.f90!}
```
1 change: 1 addition & 0 deletions example/linalg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ ADD_EXAMPLE(state2)
ADD_EXAMPLE(blas_gemv)
ADD_EXAMPLE(lapack_getrf)
ADD_EXAMPLE(determinant)
ADD_EXAMPLE(determinant2)

13 changes: 13 additions & 0 deletions example/linalg/example_determinant2.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
program example_determinant2
use stdlib_kinds, only: dp
use stdlib_linalg, only: operator(.det.)
implicit none

real(dp) :: d

! Compute determinate of a real matrix
d = .det.reshape([real(dp)::1,2,3,4],[2,2])

print *, d ! a*d-b*c = -2.0

end program example_determinant2