Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
06bfe4b
templated BLAS/LAPACK initials
perazz Apr 25, 2024
a2afe6b
base implementation
perazz Apr 25, 2024
d929077
exclude `xdp`
perazz Apr 25, 2024
5c817c8
`pure` interfaces
perazz Apr 25, 2024
4cef2ac
cleanup names
perazz Apr 25, 2024
7b7c051
submodule
perazz Apr 25, 2024
0be918e
`real` and `complex` tests
perazz Apr 25, 2024
9906c93
add `real` and `complex` examples
perazz Apr 26, 2024
a5d1b8a
add specs
perazz Apr 26, 2024
c1365ff
document interface
perazz Apr 26, 2024
af70ff9
Merge branch 'master' into linalg_solve
perazz Apr 26, 2024
3de6834
fix resolve conflict
perazz Apr 26, 2024
04f126d
Update doc/specs/stdlib_linalg.md
perazz Apr 27, 2024
7ae0510
Update doc/specs/stdlib_linalg.md
perazz Apr 27, 2024
ed135d9
Update doc/specs/stdlib_linalg.md
perazz Apr 30, 2024
e9bf020
Update doc/specs/stdlib_linalg.md
perazz Apr 30, 2024
3265f8f
Update src/stdlib_linalg.fypp
perazz Apr 30, 2024
77fc5bd
Update doc/specs/stdlib_linalg.md
perazz Apr 30, 2024
b04b3d9
Update doc/specs/stdlib_linalg.md
perazz Apr 30, 2024
8d5e682
Update src/stdlib_linalg_solve.fypp
perazz Apr 30, 2024
4458b88
fix test
perazz Apr 30, 2024
bc13246
Merge branch 'linalg_solve' of github.com:perazz/stdlib into linalg_s…
perazz Apr 30, 2024
316c44a
implement `subroutine` interface
perazz Apr 30, 2024
04f1465
Merge branch 'fortran-lang:master' into linalg_solve
perazz May 8, 2024
5e0620c
specify full-rank
perazz May 9, 2024
c9f5f0c
document `solve_lu`
perazz May 9, 2024
e75bb2f
add `solve_lu` test
perazz May 9, 2024
449d0a2
add pivot
perazz May 9, 2024
b288520
cleanup subroutine example; add preallocated pivot
perazz May 9, 2024
7aab844
document `solve_lu` interface
perazz May 9, 2024
da16d0f
Merge branch 'master' into linalg_solve
perazz May 9, 2024
a05809e
typo
perazz May 9, 2024
5832df5
avoid 128-bit random numbers
perazz May 9, 2024
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
Prev Previous commit
Next Next commit
Merge branch 'master' into linalg_solve
  • Loading branch information
perazz authored Apr 26, 2024
commit af70ff9ca043a28e8ac6fc8bcd03a4aa45cf24d8
74 changes: 74 additions & 0 deletions doc/specs/stdlib_linalg.md
Original file line number Diff line number Diff line change
Expand Up @@ -649,3 +649,77 @@ Exceptions trigger an `error stop`.

{!example/linalg/example_solve2.f90!}
```

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

### Status

Experimental

### Description

This function computes the determinant of a `real` or `complex` 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.
This is an `intent(in)` argument.

`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument.

### Return value

Returns a `real` scalar value of the same kind of `a` that represents the determinant 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 of any `real` or `complex` kinds. It is an `intent(in)` argument.

### 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!}
```
2 changes: 2 additions & 0 deletions example/linalg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ ADD_EXAMPLE(blas_gemv)
ADD_EXAMPLE(lapack_getrf)
ADD_EXAMPLE(solve1)
ADD_EXAMPLE(solve2)
ADD_EXAMPLE(determinant)
ADD_EXAMPLE(determinant2)
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(fppFiles
stdlib_linalg_kronecker.fypp
stdlib_linalg_cross_product.fypp
stdlib_linalg_solve.fypp
stdlib_linalg_determinant.fypp
stdlib_linalg_state.fypp
stdlib_optval.fypp
stdlib_selection.fypp
Expand Down
102 changes: 102 additions & 0 deletions src/stdlib_linalg.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,108 @@ module stdlib_linalg
#:endfor
end interface solve

interface det
!! version: experimental
!!
!! Computes the determinant of a square matrix
!! ([Specification](../page/specs/stdlib_linalg.html#det-computes-the-determinant-of-a-square-matrix))
!!
!!### Summary
!! Interface for computing matrix determinant.
!!
!!### Description
!!
!! This interface provides methods for computing the determinant of a matrix.
!! Supported data types include `real` and `complex`.
!!
!!@note The provided functions are intended for square matrices only.
!!@note BLAS/LAPACK backends do not currently support extended precision (``xdp``).
!!
!!### Example
!!
!!```fortran
!!
!! real(sp) :: a(3,3), d
!! type(linalg_state_type) :: state
!! a = reshape([1, 2, 3, 4, 5, 6, 7, 8, 9], [3, 3])
!!
!! ! ...
!! d = det(a,err=state)
!! if (state%ok()) then
!! print *, 'Success! det=',d
!! else
!! print *, state%print()
!! endif
!! ! ...
!!```
!!
#:for rk,rt in RC_KINDS_TYPES
#:if rk!="xdp"
module procedure stdlib_linalg_${rt[0]}$${rk}$determinant
module procedure stdlib_linalg_pure_${rt[0]}$${rk}$determinant
#:endif
#:endfor
end interface det

interface operator(.det.)
!! version: experimental
!!
!! Determinant operator of a square matrix
!! ([Specification](../page/specs/stdlib_linalg.html#det-determinant-operator-of-a-square-matrix))
!!
!!### Summary
!! Pure operator interface for computing matrix determinant.
!!
!!### Description
!!
!! This pure operator interface provides a convenient way to compute the determinant of a matrix.
!! Supported data types include real and complex.
!!
!!@note The provided functions are intended for square matrices.
!!@note BLAS/LAPACK backends do not currently support extended precision (``xdp``).
!!
!!### Example
!!
!!```fortran
!!
!! ! ...
!! real(sp) :: matrix(3,3), d
!! matrix = reshape([1, 2, 3, 4, 5, 6, 7, 8, 9], [3, 3])
!! d = .det.matrix
!! ! ...
!!
!!```
!
#:for rk,rt in RC_KINDS_TYPES
#:if rk!="xdp"
module procedure stdlib_linalg_pure_${rt[0]}$${rk}$determinant
#:endif
#:endfor
end interface operator(.det.)

interface
#:for rk,rt in RC_KINDS_TYPES
#:if rk!="xdp"
module function stdlib_linalg_${rt[0]}$${rk}$determinant(a,overwrite_a,err) result(det)
!> Input matrix a[m,n]
${rt}$, intent(inout), target :: a(:,:)
!> [optional] Can A data be overwritten and destroyed?
logical(lk), optional, intent(in) :: overwrite_a
!> State return flag.
type(linalg_state_type), intent(out) :: err
!> Matrix determinant
${rt}$ :: det
end function stdlib_linalg_${rt[0]}$${rk}$determinant
pure module function stdlib_linalg_pure_${rt[0]}$${rk}$determinant(a) result(det)
!> Input matrix a[m,n]
${rt}$, intent(in) :: a(:,:)
!> Matrix determinant
${rt}$ :: det
end function stdlib_linalg_pure_${rt[0]}$${rk}$determinant
#:endif
#:endfor
end interface

contains


Expand Down
1 change: 1 addition & 0 deletions test/linalg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set(
"test_linalg.fypp"
"test_blas_lapack.fypp"
"test_linalg_solve.fypp"
"test_linalg_determinant.fypp"
"test_linalg_matrix_property_checks.fypp"
)
fypp_f90("${fyppFlags}" "${fppFiles}" outFiles)
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.