Skip to content

[stdlib_linalg] matrix property checks #499

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 37 commits into from
Dec 31, 2021
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3d86036
Add all single input chekcs
ghbrown Aug 21, 2021
6d9848f
Fix is_diagonal and add some tests
ghbrown Aug 24, 2021
4c5fdf1
Add is_symmetric and is_skew_symmetric tests
ghbrown Aug 25, 2021
f28bb47
Add tests for is_skew_symmetric and start is_triangular tests
ghbrown Aug 26, 2021
857a9bb
Start complex is_triangular tests
ghbrown Aug 27, 2021
a14af3b
Add final tests
ghbrown Aug 28, 2021
bdae9ae
Style changes
ghbrown Aug 28, 2021
e1f07e6
Separate calls to check in tests
ghbrown Aug 30, 2021
55e0dd0
Extend is_hamiltonian to real types and add is_hamiltonian tests
ghbrown Aug 31, 2021
fd8fcf1
Replace A_shape with size() calls
ghbrown Sep 2, 2021
3196fea
Add docs and examples
ghbrown Sep 6, 2021
c31200f
Add stdlib_error dependency to stdlib_linalg for GNU make
ghbrown Sep 6, 2021
ce2722d
Add missing slash to broken GNU makefile
ghbrown Sep 6, 2021
0da0d7d
Change (.not * .eq *) to (* .ne. *) for brevity
ghbrown Sep 27, 2021
1a9ddb3
Switch to modern relational operators
ghbrown Sep 28, 2021
ed42211
Change style of output comments in docs
ghbrown Sep 29, 2021
58346ff
Remove doubled check for squareness
ghbrown Oct 4, 2021
a759929
Make zero variables into parameters
ghbrown Oct 4, 2021
1915bbb
Clarify return value documentation
ghbrown Oct 4, 2021
677c577
Change to more specific documentation URLs
ghbrown Oct 4, 2021
080b552
update links for FORD
jvdp1 Oct 4, 2021
9412890
Merge pull request #1 from jvdp1/linalg_link
ghbrown Oct 4, 2021
6f6f5ac
Separate out matrix property checks tests
ghbrown Oct 11, 2021
c3d07a1
Merge branch 'matrix_property_checks' of github.com:ghbrown/stdlib in…
ghbrown Oct 11, 2021
8324fa7
Merge branch 'master' into matrix_property_checks
ghbrown Oct 11, 2021
12be97b
Add back optval dependencies accidentally removed in merge conflict r…
ghbrown Oct 11, 2021
d0a4a76
Remove redundant tests after separation
ghbrown Oct 16, 2021
0a0137b
After catch up merge
ghbrown Dec 27, 2021
74abe0f
Add fypp version of is_square
ghbrown Dec 27, 2021
ecc38d1
Settle on global style for fypp templating and add is_diagonal and is…
ghbrown Dec 27, 2021
009e22c
Implement all tests with testdrive and fypp
ghbrown Dec 27, 2021
03306f1
Add missing source file to manual makefile
ghbrown Dec 27, 2021
58fc9a2
Add missing separator for line break
ghbrown Dec 27, 2021
09e333f
Correct error in fypp templating
ghbrown Dec 28, 2021
c7c8bcd
Fix GNU makefiles and cleanup cmake and fypp fixes
ghbrown Dec 28, 2021
8d36da6
Blank line insertion and deletion
ghbrown Dec 28, 2021
60f0fa6
Remove hash files generated during testing
ghbrown Dec 31, 2021
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
270 changes: 269 additions & 1 deletion doc/specs/stdlib_linalg.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Trace of a matrix (rank-2 array)

### Syntax

`result = [stdlib_linalg(module):trace(interface)](A)`
`result = [[stdlib_linalg(module):trace(interface)]](A)`

### Arguments

Expand Down Expand Up @@ -234,3 +234,271 @@ program demo_outer_product
!A = reshape([3., 6., 9., 4., 8., 12.], [3,2])
end program demo_outer_product
```

## `is_square` - Checks if a matrix is square

### Status

Experimental

### Description

Checks if a matrix is square

### Syntax

`d = [[stdlib_linalg(module):is_square(interface)]](A)`

### Arguments

`A`: Shall be a rank-2 array

### Return value

Returns a `logical` scalar that is `.true.` if the input matrix is square, and `.false.` otherwise.

### Example

```fortran
program demo_is_square
use stdlib_linalg, only: is_square
implicit none
real :: A(2,2), B(3,2)
logical :: res
A = reshape([1., 2., 3., 4.], shape(A))
B = reshape([1., 2., 3., 4., 5., 6.], shape(B))
res = is_square(A) ! returns .true.
res = is_square(B) ! returns .false.
end program demo_is_square
```

## `is_diagonal` - Checks if a matrix is diagonal

### Status

Experimental

### Description

Checks if a matrix is diagonal

### Syntax

`d = [[stdlib_linalg(module):is_diagonal(interface)]](A)`

### Arguments

`A`: Shall be a rank-2 array

### Return value

Returns a `logical` scalar that is `.true.` if the input matrix is diagonal, and `.false.` otherwise.
Note that nonsquare matrices may be diagonal, so long as `a_ij = 0` when `i /= j`.

### Example

```fortran
program demo_is_diagonal
use stdlib_linalg, only: is_diagonal
implicit none
real :: A(2,2), B(2,2)
logical :: res
A = reshape([1., 0., 0., 4.], shape(A))
B = reshape([1., 0., 3., 4.], shape(B))
res = is_diagonal(A) ! returns .true.
res = is_diagonal(B) ! returns .false.
end program demo_is_diagonal
```

## `is_symmetric` - Checks if a matrix is symmetric

### Status

Experimental

### Description

Checks if a matrix is symmetric

### Syntax

`d = [[stdlib_linalg(module):is_symmetric(interface)]](A)`

### Arguments

`A`: Shall be a rank-2 array

### Return value

Returns a `logical` scalar that is `.true.` if the input matrix is symmetric, and `.false.` otherwise.

### Example

```fortran
program demo_is_symmetric
use stdlib_linalg, only: is_symmetric
implicit none
real :: A(2,2), B(2,2)
logical :: res
A = reshape([1., 3., 3., 4.], shape(A))
B = reshape([1., 0., 3., 4.], shape(B))
res = is_symmetric(A) ! returns .true.
res = is_symmetric(B) ! returns .false.
end program demo_is_symmetric
```

## `is_skew_symmetric` - Checks if a matrix is skew-symmetric

### Status

Experimental

### Description

Checks if a matrix is skew-symmetric

### Syntax

`d = [[stdlib_linalg(module):is_skew_symmetric(interface)]](A)`

### Arguments

`A`: Shall be a rank-2 array

### Return value

Returns a `logical` scalar that is `.true.` if the input matrix is skew-symmetric, and `.false.` otherwise.

### Example

```fortran
program demo_is_skew_symmetric
use stdlib_linalg, only: is_skew_symmetric
implicit none
real :: A(2,2), B(2,2)
logical :: res
A = reshape([0., -3., 3., 0.], shape(A))
B = reshape([0., 3., 3., 0.], shape(B))
res = is_skew_symmetric(A) ! returns .true.
res = is_skew_symmetric(B) ! returns .false.
end program demo_is_skew_symmetric
```

## `is_hermitian` - Checks if a matrix is Hermitian

### Status

Experimental

### Description

Checks if a matrix is Hermitian

### Syntax

`d = [[stdlib_linalg(module):is_hermitian(interface)]](A)`

### Arguments

`A`: Shall be a rank-2 array

### Return value

Returns a `logical` scalar that is `.true.` if the input matrix is Hermitian, and `.false.` otherwise.

### Example

```fortran
program demo_is_hermitian
use stdlib_linalg, only: is_hermitian
implicit none
complex :: A(2,2), B(2,2)
logical :: res
A = reshape([cmplx(1.,0.), cmplx(3.,-1.), cmplx(3.,1.), cmplx(4.,0.)], shape(A))
B = reshape([cmplx(1.,0.), cmplx(3.,1.), cmplx(3.,1.), cmplx(4.,0.)], shape(B))
res = is_hermitian(A) ! returns .true.
res = is_hermitian(B) ! returns .false.
end program demo_is_hermitian
```

## `is_triangular` - Checks if a matrix is triangular

### Status

Experimental

### Description

Checks if a matrix is triangular

### Syntax

`d = [[stdlib_linalg(module):is_triangular(interface)]](A,uplo)`

### Arguments

`A`: Shall be a rank-2 array

`uplo`: Shall be a single character from `{'u','U','l','L'}`

### Return value

Returns a `logical` scalar that is `.true.` if the input matrix is the type of triangular specified by `uplo` (upper or lower), and `.false.` otherwise.
Note that the definition of triangular used in this implementation allows nonsquare matrices to be triangular.
Specifically, upper triangular matrices satisfy `a_ij = 0` when `j < i`, and lower triangular matrices satisfy `a_ij = 0` when `j > i`.

### Example

```fortran
program demo_is_triangular
use stdlib_linalg, only: is_triangular
implicit none
real :: A(3,3), B(3,3)
logical :: res
A = reshape([1., 0., 0., 4., 5., 0., 7., 8., 9.], shape(A))
B = reshape([1., 0., 3., 4., 5., 0., 7., 8., 9.], shape(B))
res = is_triangular(A,'u') ! returns .true.
res = is_triangular(B,'u') ! returns .false.
end program demo_is_triangular
```

## `is_hessenberg` - Checks if a matrix is hessenberg

### Status

Experimental

### Description

Checks if a matrix is Hessenberg

### Syntax

`d = [[stdlib_linalg(module):is_hessenberg(interface)]](A,uplo)`

### Arguments

`A`: Shall be a rank-2 array

`uplo`: Shall be a single character from `{'u','U','l','L'}`

### Return value

Returns a `logical` scalar that is `.true.` if the input matrix is the type of Hessenberg specified by `uplo` (upper or lower), and `.false.` otherwise.
Note that the definition of Hessenberg used in this implementation allows nonsquare matrices to be Hessenberg.
Specifically, upper Hessenberg matrices satisfy `a_ij = 0` when `j < i-1`, and lower Hessenberg matrices satisfy `a_ij = 0` when `j > i+1`.

### Example

```fortran
program demo_is_hessenberg
use stdlib_linalg, only: is_hessenberg
implicit none
real :: A(3,3), B(3,3)
logical :: res
A = reshape([1., 2., 0., 4., 5., 6., 7., 8., 9.], shape(A))
B = reshape([1., 2., 3., 4., 5., 6., 7., 8., 9.], shape(B))
res = is_hessenberg(A,'u') ! returns .true.
res = is_hessenberg(B,'u') ! returns .false.
end program demo_is_hessenberg
```
6 changes: 4 additions & 2 deletions src/Makefile.manual
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,13 @@ stdlib_io_npy_save.o: \
stdlib_strings.o
stdlib_linalg.o: \
stdlib_kinds.o \
stdlib_optval.o
stdlib_optval.o \
stdlib_error.o
stdlib_linalg_diag.o: \
stdlib_linalg.o \
stdlib_kinds.o
stdlib_linalg_outer_product.o: \
stdlib_linalg.o
stdlib_logger.o: stdlib_ascii.o stdlib_optval.o
stdlib_optval.o: stdlib_kinds.o
stdlib_quadrature.o: stdlib_kinds.o
Expand Down Expand Up @@ -224,7 +227,6 @@ stdlib_math_logspace.o: \
stdlib_math_linspace.o
stdlib_math_arange.o: \
stdlib_math.o
stdlib_linalg_outer_product.o: stdlib_linalg.o
stdlib_math_is_close.o: \
stdlib_math.o
stdlib_math_all_close.o: \
Expand Down
Loading