Skip to content
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

[stdlib_linalg] matrix property checks #499

Merged
merged 37 commits into from
Dec 31, 2021
Merged
Show file tree
Hide file tree
Changes from 14 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
282 changes: 282 additions & 0 deletions doc/specs/stdlib_linalg.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,285 @@ 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
jvdp1 marked this conversation as resolved.
Show resolved Hide resolved

### Return value

Returns a logical value that is true if the input matrix is square, and false otherwise.
ghbrown marked this conversation as resolved.
Show resolved Hide resolved

### Example

```fortran
program demo_is_square
use stdlib_linalg, only: is_square
implicit none
real :: A_true(2,2), A_false(3,2)
logical :: res
A_true = reshape([1., 2., 3., 4.], shape(A_true))
A_false = reshape([1., 2., 3., 4., 5., 6.], shape(A_false))
res = is_square(A_true)
!res = .true.
res = is_square(A_false)
!res = .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
jvdp1 marked this conversation as resolved.
Show resolved Hide resolved

### Return value

Returns a logical value that is true if the input matrix is diagonal, and false otherwise.
ghbrown marked this conversation as resolved.
Show resolved Hide resolved
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_true(2,2), A_false(2,2)
logical :: res
A_true = reshape([1., 0., 0., 4.], shape(A_true))
A_false = reshape([1., 0., 3., 4.], shape(A_false))
res = is_diagonal(A_true)
!res = .true.
res = is_diagonal(A_false)
!res = .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
jvdp1 marked this conversation as resolved.
Show resolved Hide resolved

### Return value

Returns a logical value that is true if the input matrix is symmetric, and false otherwise.
ghbrown marked this conversation as resolved.
Show resolved Hide resolved

### Example

```fortran
program demo_is_symmetric
use stdlib_linalg, only: is_symmetric
implicit none
real :: A_true(2,2), A_false(2,2)
logical :: res
A_true = reshape([1., 3., 3., 4.], shape(A_true))
A_false = reshape([1., 0., 3., 4.], shape(A_false))
res = is_symmetric(A_true)
!res = .true.
res = is_symmetric(A_false)
!res = .false.
end program demo_is_symmetric
ivan-pi marked this conversation as resolved.
Show resolved Hide resolved
```

## `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
jvdp1 marked this conversation as resolved.
Show resolved Hide resolved

### Return value

Returns a logical value that is true if the input matrix is skew-symmetric, and false otherwise.
ghbrown marked this conversation as resolved.
Show resolved Hide resolved

### Example

```fortran
program demo_is_skew_symmetric
use stdlib_linalg, only: is_skew_symmetric
implicit none
real :: A_true(2,2), A_false(2,2)
logical :: res
A_true = reshape([0., -3., 3., 0.], shape(A_true))
A_false = reshape([0., 3., 3., 0.], shape(A_false))
res = is_skew_symmetric(A_true)
!res = .true.
res = is_skew_symmetric(A_false)
!res = .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
jvdp1 marked this conversation as resolved.
Show resolved Hide resolved

### Return value

Returns a logical value that is true if the input matrix is Hermitian, and false otherwise.
ghbrown marked this conversation as resolved.
Show resolved Hide resolved

### Example

```fortran
program demo_is_hermitian
use stdlib_linalg, only: is_hermitian
implicit none
complex :: A_true(2,2), A_false(2,2)
logical :: res
A_true = reshape([cmplx(1.,0.), cmplx(3.,-1.), cmplx(3.,1.), cmplx(4.,0.)], shape(A_true))
A_false = reshape([cmplx(1.,0.), cmplx(3.,1.), cmplx(3.,1.), cmplx(4.,0.)], shape(A_false))
res = is_hermitian(A_true)
!res = .true.
res = is_hermitian(A_false)
!res = .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
jvdp1 marked this conversation as resolved.
Show resolved Hide resolved

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

### Return value

Returns a logical value that is true if the input matrix is the type of triangular specified by `uplo` (upper or lower), and false otherwise.
ghbrown marked this conversation as resolved.
Show resolved Hide resolved
Note that the definition of triangular used here allows nonsquare matrices to be triangular.
ghbrown marked this conversation as resolved.
Show resolved Hide resolved
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_true(3,3), A_false(3,3)
logical :: res
A_true = reshape([1., 0., 0., 4., 5., 0., 7., 8., 9.], shape(A_true))
A_false = reshape([1., 0., 3., 4., 5., 0., 7., 8., 9.], shape(A_false))
res = is_triangular(A_true,'u')
!res = .true.
res = is_triangular(A_false,'u')
!res = .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
jvdp1 marked this conversation as resolved.
Show resolved Hide resolved

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

### Return value

Returns a logical value that is true if the input matrix is the type of Hessenberg specified by `uplo` (upper or lower), and false otherwise.
ghbrown marked this conversation as resolved.
Show resolved Hide resolved
Note that the definition of Hessenberg used here allows nonsquare matrices to be Hessenberg.
ghbrown marked this conversation as resolved.
Show resolved Hide resolved
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_true(3,3), A_false(3,3)
logical :: res
A_true = reshape([1., 2., 0., 4., 5., 6., 7., 8., 9.], shape(A_true))
A_false = reshape([1., 2., 3., 4., 5., 6., 7., 8., 9.], shape(A_false))
res = is_hessenberg(A_true,'u')
!res = .true.
res = is_hessenberg(A_false,'u')
!res = .false.
end program demo_is_hessenberg
```
3 changes: 2 additions & 1 deletion src/Makefile.manual
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ stdlib_io.o: \
stdlib_optval.o \
stdlib_kinds.o
stdlib_linalg.o: \
stdlib_kinds.o
stdlib_kinds.o \
stdlib_error.o
stdlib_linalg_diag.o: \
stdlib_linalg.o \
stdlib_kinds.o
Expand Down
Loading