Impure wrapper function for f_lin_mahalanobis_core
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | x(:) |
input vector 1 |
||
real(kind=wp), | intent(in) | :: | y(:) |
input vector 2 |
||
real(kind=wp), | intent(in), | optional | :: | cov(:,:) |
covariance matrix |
Mahalanobis distance
impure function f_lin_mahalanobis(x, y, cov) result(dist) ! ==== Description !! Impure wrapper function for `f_lin_mahalanobis_core`. ! ==== Declarations real(wp), intent(in) :: x(:) !! input vector 1 real(wp), intent(in) :: y(:) !! input vector 2 real(wp), intent(in), optional :: cov(:,:) !! covariance matrix real(wp) :: dist !! Mahalanobis distance ! ==== Instructions ! ---- handle input ! check if size is valid if (size(x) .le. 1 .or. size(y) .le. 1) then ! write error message and assign sentinel value if invalid call s_err_print(fsml_error(4)) dist = c_sentinel_r return endif if (present(cov)) then ! check if dims match if (size(cov, 1) .ne. size(x)) then ! write error message and assign sentinel value if invalid call s_err_print(fsml_error(3)) dist = c_sentinel_r return endif ! check if dims match if (size(cov, 1) .ne. size(cov, 2)) then ! write error message and assign sentinel value if invalid call s_err_print(fsml_error(3)) dist = c_sentinel_r return endif endif ! ---- compute Mahalanobis distance ! call pure function if (present(cov)) then dist = f_lin_mahalanobis_core(x, y, cov) else dist = f_lin_mahalanobis_core(x, y) endif end function f_lin_mahalanobis