Calculates the pseudoinverse of a matrix A using the LU decomposition.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=rk), | intent(in), | dimension(:, :), contiguous | :: | A |
pure function pinvLU_rel(A) result(Apinv) #elif defined (IMPURE) impure function pinvLU_rel(A) result(Apinv) #endif ! Inputs: real(rk), dimension(:, :), contiguous, intent(in) :: A ! Input matrix A ! Outputs: real(rk), dimension(size(A,2), size(A,1)) :: Apinv ! Pseudoinverse of A if (size(A, 1) == size(A, 2)) then Apinv = invLU_rel(A) elseif (size(A, 1) > size(A, 2)) then Apinv = transpose(A) Apinv = gemm(invLU_rel(gemm(Apinv, A)), Apinv) else Apinv = transpose(A) Apinv = gemm(Apinv, invLU_rel(gemm(A, Apinv))) end if end function pinvLU_rel