f_lin_euclidean_core Function

public pure function f_lin_euclidean_core(x, y) result(dist)

Compute Euclidean (L2) distance between vectors x and y.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: x(:)

input vector 1

real(kind=wp), intent(in) :: y(:)

input vector 2

Return Value real(kind=wp)

Euclidean distance


Called by

proc~~f_lin_euclidean_core~~CalledByGraph proc~f_lin_euclidean_core f_lin_euclidean_core proc~f_lin_euclidean f_lin_euclidean proc~f_lin_euclidean->proc~f_lin_euclidean_core interface~fsml_euclidean fsml_euclidean interface~fsml_euclidean->proc~f_lin_euclidean

Source Code

pure function f_lin_euclidean_core(x, y) result(dist)

! ==== Description
!! Compute Euclidean (L2) distance between vectors x and y.

! ==== Declarations
  real(wp), intent(in) :: x(:)    !! input vector 1
  real(wp), intent(in) :: y(:)    !! input vector 2
  real(wp)             :: dist    !! Euclidean distance
  real(wp)             :: diff    !! vector differences
  integer(i4)          :: m       !! vector length
  integer(i4)          :: i

! ==== Instructions

  ! get dims
  m = size(x)

  ! calculate distance
  dist = 0.0_wp
  do i = 1, m
     diff = x(i) - y(i)
     dist = dist + diff*diff
  enddo
  dist = sqrt(max(0.0_wp, dist))

end function f_lin_euclidean_core