Skip to content

Commit 1e02559

Browse files
committed
Interfaces for the constrained lstsq solver.
1 parent 9e4c230 commit 1e02559

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/stdlib_linalg.fypp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,56 @@ module stdlib_linalg
576576
#:endfor
577577
end interface lstsq_space
578578

579+
! Equality-constrained least-squares, i.e. minimize the sum of squares
580+
! cost || Ax - b ||^2 subject to the equality constraint Cx = d.
581+
interface constrained_lstsq
582+
#:for rk, rt, ri in RC_KINDS_TYPES
583+
module function stdlib_linalg_${ri}$_constrained_lstsq(A, b, C, d, overwrite_matrices, err) result(x)
584+
!> Input matrices.
585+
${rt}$, intent(inout), target :: A(:, :), C(:, :)
586+
!> Right-hand side vectors.
587+
${rt}$, intent(inout), target :: b(:), d(:)
588+
!> [optional] Can A and C be overwritten?
589+
logical(lk), optional, intent(in) :: overwrite_matrices
590+
!> [optional] State return flag.
591+
type(linalg_state_type), optional, intent(out) :: err
592+
!> Solution of the constrained least-squares problem.
593+
${rt}$, allocatable, target :: x(:)
594+
end function stdlib_linalg_${ri}$_constrained_lstsq
595+
#:endfor
596+
end interface
597+
598+
! Equality-constrained least-squares, i.e. minimize the sum of squares
599+
! cost || Ax - b ||^2 subject to the equality constraint Cx = d.
600+
interface solve_constrained_lstsq
601+
#:for rk, rt, ri in RC_KINDS_TYPES
602+
module subroutine stdlib_linalg_${ri}$_solve_constrained_lstsq(A, b, C, d, x, storage, overwrite_matrices, err)
603+
!> Input matrices.
604+
${rt}$, intent(inout), target :: A(:, :), C(:, :)
605+
!> Right-hand side vectors.
606+
${rt}$, intent(inout), target :: b(:), d(:)
607+
!> Solution vector.
608+
${rt}$, intent(out) :: x(:)
609+
!> [optional] Storage.
610+
${rt}$, optional, intent(out) :: storage(:)
611+
!> [optional] Can A and C be overwritten?
612+
logical(lk), optional, intent(in) :: overwrite_matrices
613+
!> [optional] State return flag. On error if not requested, the code stops.
614+
type(linalg_state_type), optional, intent(out) :: err
615+
end subroutine stdlib_linalg_${ri}$_solve_constrained_lstsq
616+
#:endfor
617+
end interface
618+
619+
interface constrained_lstsq_space
620+
#:for rk, rt, ri in RC_KINDS_TYPES
621+
pure module subroutine stdlib_linalg_${ri}$_constrained_lstsq_space(A, b, C, d, lwork)
622+
${rt}$, intent(in), target :: A(:, :), C(:, :)
623+
${rt}$, intent(in), target :: b(:), d(:)
624+
integer(ilp), intent(out) :: lwork
625+
end subroutine stdlib_linalg_${ri}$_constrained_lstsq_space
626+
#:endfor
627+
end interface
628+
579629
! QR factorization of rank-2 array A
580630
interface qr
581631
!! version: experimental

0 commit comments

Comments
 (0)