Skip to content

Commit 9a3e446

Browse files
Address review: use Fortran notation in comments, merge example files
1 parent c9e4846 commit 9a3e446

6 files changed

Lines changed: 29 additions & 49 deletions

File tree

doc/specs/stdlib_linalg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ Exceptions trigger an `error stop`.
10671067
### Example
10681068

10691069
```fortran
1070-
{!example/linalg/example_solve_weighted_lstsq.f90!}
1070+
{!example/linalg/example_weighted_lstsq.f90!}
10711071
```
10721072

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

example/linalg/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ ADD_EXAMPLE(lstsq2)
3838
ADD_EXAMPLE(constrained_lstsq1)
3939
ADD_EXAMPLE(constrained_lstsq2)
4040
ADD_EXAMPLE(weighted_lstsq)
41-
ADD_EXAMPLE(solve_weighted_lstsq)
4241
ADD_EXAMPLE(norm)
4342
ADD_EXAMPLE(mnorm)
4443
ADD_EXAMPLE(get_norm)

example/linalg/example_solve_weighted_lstsq.f90

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
! Weighted least-squares solver
1+
! Weighted least-squares solver: function and subroutine interfaces
22
program example_weighted_lstsq
33
use stdlib_linalg_constants, only: dp
4-
use stdlib_linalg, only: weighted_lstsq
4+
use stdlib_linalg, only: weighted_lstsq, solve_weighted_lstsq
55
implicit none
66

7-
real(dp) :: A(4,2), b(4), w(4)
7+
real(dp) :: A(4,2), b(4), w(4), x_sub(2)
88
real(dp), allocatable :: x(:)
99

1010
! Design matrix: intercept + slope
@@ -17,10 +17,16 @@ program example_weighted_lstsq
1717
! Weights: downweight the outlier
1818
w = [1.0_dp, 1.0_dp, 0.1_dp, 1.0_dp]
1919

20-
! Solve weighted least-squares
20+
! Solve weighted least-squares (function interface)
2121
x = weighted_lstsq(w, A, b)
2222

23-
print '("Weighted fit: intercept = ",f8.4,", slope = ",f8.4)', x(1), x(2)
24-
! Weighted fit: intercept = 0.1500, slope = 1.9911
23+
print '("Function interface: intercept = ",f8.4,", slope = ",f8.4)', x(1), x(2)
24+
! Function interface: intercept = 0.1500, slope = 1.9911
25+
26+
! Solve weighted least-squares (subroutine interface)
27+
call solve_weighted_lstsq(w, A, b, x_sub)
28+
29+
print '("Subroutine interface: intercept = ",f8.4,", slope = ",f8.4)', x_sub(1), x_sub(2)
30+
! Subroutine interface: intercept = 0.1500, slope = 1.9911
2531

2632
end program example_weighted_lstsq

src/linalg/stdlib_linalg.fypp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -705,9 +705,9 @@ module stdlib_linalg
705705
module function stdlib_linalg_${ri}$_weighted_lstsq(w,a,b,cond,overwrite_a,rank,err) result(x)
706706
!> Weight vector (must be positive, always real)
707707
real(${rk}$), intent(in) :: w(:)
708-
!> Input matrix a[m,n]
708+
!> Input matrix a(m,n)
709709
${rt}$, intent(inout), target :: a(:,:)
710-
!> Right hand side vector b[m]
710+
!> Right hand side vector b(m)
711711
${rt}$, intent(in) :: b(:)
712712
!> [optional] cutoff for rank evaluation: singular values s(i)<=cond*maxval(s) are considered 0.
713713
real(${rk}$), optional, intent(in) :: cond
@@ -717,7 +717,7 @@ module stdlib_linalg
717717
integer(ilp), optional, intent(out) :: rank
718718
!> [optional] state return flag. On error if not requested, the code will stop
719719
type(linalg_state_type), optional, intent(out) :: err
720-
!> Result array x[n]
720+
!> Result array x(n)
721721
${rt}$, allocatable :: x(:)
722722
end function stdlib_linalg_${ri}$_weighted_lstsq
723723
#:endfor
@@ -747,11 +747,11 @@ module stdlib_linalg
747747
module subroutine stdlib_linalg_${ri}$_solve_weighted_lstsq(w,a,b,x,cond,overwrite_a,rank,err)
748748
!> Weight vector (must be positive, always real)
749749
real(${rk}$), intent(in) :: w(:)
750-
!> Input matrix a[m,n]
750+
!> Input matrix a(m,n)
751751
${rt}$, intent(inout), target :: a(:,:)
752-
!> Right hand side vector b[m]
752+
!> Right hand side vector b(m)
753753
${rt}$, intent(in) :: b(:)
754-
!> Result array x[n]
754+
!> Result array x(n)
755755
${rt}$, intent(inout), contiguous, target :: x(:)
756756
!> [optional] cutoff for rank evaluation: singular values s(i)<=cond*maxval(s) are considered 0.
757757
real(${rk}$), optional, intent(in) :: cond

src/linalg/stdlib_linalg_least_squares.fypp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,9 @@ submodule (stdlib_linalg) stdlib_linalg_least_squares
573573
module function stdlib_linalg_${ri}$_weighted_lstsq(w,a,b,cond,overwrite_a,rank,err) result(x)
574574
!> Weight vector (must be positive, always real)
575575
real(${rk}$), intent(in) :: w(:)
576-
!> Input matrix a[m,n]
576+
!> Input matrix a(m,n)
577577
${rt}$, intent(inout), target :: a(:,:)
578-
!> Right hand side vector b[m]
578+
!> Right hand side vector b(m)
579579
${rt}$, intent(in) :: b(:)
580580
!> [optional] cutoff for rank evaluation: singular values s(i)<=cond*maxval(s) are considered 0.
581581
real(${rk}$), optional, intent(in) :: cond
@@ -585,7 +585,7 @@ submodule (stdlib_linalg) stdlib_linalg_least_squares
585585
integer(ilp), optional, intent(out) :: rank
586586
!> [optional] state return flag. On error if not requested, the code will stop
587587
type(linalg_state_type), optional, intent(out) :: err
588-
!> Result array x[n]
588+
!> Result array x(n)
589589
${rt}$, allocatable :: x(:)
590590

591591
integer(ilp) :: n
@@ -609,10 +609,10 @@ submodule (stdlib_linalg) stdlib_linalg_least_squares
609609
!!
610610
!! This subroutine computes the weighted least-squares solution of a linear matrix problem.
611611
!!
612-
!! param: w Weight vector of size [m] (must be positive, always real).
613-
!! param: a Input matrix of size [m,n].
614-
!! param: b Right-hand-side vector of size [m].
615-
!! param: x Solution vector of size [n].
612+
!! param: w Weight vector of size (m) (must be positive, always real).
613+
!! param: a Input matrix of size (m,n).
614+
!! param: b Right-hand-side vector of size (m).
615+
!! param: x Solution vector of size (n).
616616
!! param: cond [optional] Real input threshold indicating that singular values `s_i <= cond*maxval(s)`
617617
!! do not contribute to the matrix rank.
618618
!! param: overwrite_a [optional] Flag indicating if the input matrix can be overwritten.
@@ -621,11 +621,11 @@ submodule (stdlib_linalg) stdlib_linalg_least_squares
621621
!!
622622
!> Weight vector (must be positive, always real)
623623
real(${rk}$), intent(in) :: w(:)
624-
!> Input matrix a[m,n]
624+
!> Input matrix a(m,n)
625625
${rt}$, intent(inout), target :: a(:,:)
626-
!> Right hand side vector b[m]
626+
!> Right hand side vector b(m)
627627
${rt}$, intent(in) :: b(:)
628-
!> Result array x[n]
628+
!> Result array x(n)
629629
${rt}$, intent(inout), contiguous, target :: x(:)
630630
!> [optional] cutoff for rank evaluation: singular values s(i)<=cond*maxval(s) are considered 0.
631631
real(${rk}$), optional, intent(in) :: cond

0 commit comments

Comments
 (0)