Skip to content

Commit bf0dfd3

Browse files
committed
document invert
1 parent 75a5a23 commit bf0dfd3

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

doc/specs/stdlib_linalg.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,3 +932,42 @@ If the matrix is singular or non-square, the operator returns zeros.
932932
{!example/linalg/example_inverse1.f90!}
933933
```
934934

935+
## `invert` - Inversion of a square matrix.
936+
937+
### Status
938+
939+
Experimental
940+
941+
### Description
942+
943+
This subroutine inverts a square `real` or `complex` matrix in-place.
944+
The inverse \( A^{-1} \) is defined such that \( A \cdot A^{-1} = A^{-1} \cdot A = I_n \).
945+
946+
On return, the input matrix `a` is replaced by its inverse.
947+
The solver is based on LAPACK's `*GETRF` and `*GETRI` backends.
948+
949+
### Syntax
950+
951+
`call ` [[stdlib_linalg(module):invert(interface)]] `(a, [, pivot] [, err])`
952+
953+
### Arguments
954+
955+
`a`: Shall be a rank-2, square, `real` or `complex` array containing the coefficient matrix. It is an `intent(inout)` argument.
956+
On output, it is replaced by the inverse of `a`.
957+
958+
`pivot` (optional): Shall be a rank-1 array of the same kind and matrix dimension as `a`, providing storage for the diagonal pivot indices. It is an `intent(inout)` arguments, and returns the diagonal pivot indices.
959+
960+
`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument.
961+
962+
### Return value
963+
964+
Replaces matrix \( A \) with its inverse, \(A^{-1}\).
965+
966+
Raises `LINALG_ERROR` if the matrix is singular or has invalid size.
967+
If `err` is not present, exceptions trigger an `error stop`.
968+
969+
### Example
970+
971+
```fortran
972+
{!example/linalg/example_inverse3.f90!}
973+
```

src/stdlib_linalg.fypp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,26 @@ module stdlib_linalg
573573

574574
! Subroutine interface: in-place factorization
575575
interface invert
576+
!! version: experimental
577+
!!
578+
!! Inversion of a square matrix
579+
!! ([Specification](../page/specs/stdlib_linalg.html#invert-inversion-of-a-square-matrix))
580+
!!
581+
!!### Summary
582+
!! This interface provides methods for inverting a square `real` or `complex` matrix in-place.
583+
!! The inverse \( A^{-1} \) is defined such that \( A \cdot A^{-1} = A^{-1} \cdot A = I_n \).
584+
!!
585+
!!### Description
586+
!!
587+
!! This operator interface provides a convenient way to compute the inverse of a matrix.
588+
!! Supported data types include `real` and `complex`.
589+
!! On completion, matrix `a` is replaced by the inverse matrix. Pre-allocated storage may be provided
590+
!! for the array of pivot indices, `pivot`. If all pre-allocated work spaces are provided, no internal
591+
!! memory allocations take place when using this interface.
592+
!!
593+
!!@note The provided subroutines are intended for square matrices.
594+
!!@note BLAS/LAPACK backends do not currently support extended precision (``xdp``).
595+
!!
576596
#:for rk,rt,ri in RC_KINDS_TYPES
577597
#:if rk!="xdp"
578598
module subroutine stdlib_linalg_invert_${ri}$(a,pivot,err)

0 commit comments

Comments
 (0)