Function

vDSP_vdistD(_:_:_:_:_:_:_:)

Calculates the distance between corresponding elements of two double-precision vectors.

Declaration

func vDSP_vdistD(_ __A: UnsafePointer<Double>, _ __IA: vDSP_Stride, _ __B: UnsafePointer<Double>, _ __IB: vDSP_Stride, _ __C: UnsafeMutablePointer<Double>, _ __IC: vDSP_Stride, _ __N: vDSP_Length)

Parameters

__A

Double-precision real input vector.

__IA

Stride for A.

__B

Double-precision real input vector.

__IB

Stride for B.

__C

Double-precision real output vector.

__IC

Stride for C.

__N

The number of elements to process.

Discussion

The vDSP_vdist(_:_:_:_:_:_:_:) and vDSP_vdistD(_:_:_:_:_:_:_:) functions calculate the square roots of the sum of the squares of corresponding elements of vectors A and B, using the following operation:

for (n = 0; n < N; ++n)
    C[n] = sqrt(A[n]*A[n] + B[n]*B[n]);

For example, the following code calculates the hypotenuse of four Pythagorean triples:

let a: [Float] = [3, 6, 5, 9]
let b: [Float] = [4, 8, 12, 12]

var c: [Float] = [0, 0, 0, 0]

let stride = vDSP_Stride(1)

vDSP_vdist(a, stride,
           b, stride,
           &c, stride,
           vDSP_Length(c.count))

On return, c contains [5.0, 10.0, 13.0, 15.0].

See Also

Vector-to-Vector Distance Computation

static func distanceSquared<U, V>(U, V) -> Double

Returns the double-precision distance squared between two points in n-dimensional space.

static func distanceSquared<U, V>(U, V) -> Float

Returns the single-precision distance squared between two points in n-dimensional space.

func vDSP_distancesq(UnsafePointer<Float>, vDSP_Stride, UnsafePointer<Float>, vDSP_Stride, UnsafeMutablePointer<Float>, vDSP_Length)

Calculates the distance squared between two single-precision points in n-dimensional space, using the specified strides.

func vDSP_distancesqD(UnsafePointer<Double>, vDSP_Stride, UnsafePointer<Double>, vDSP_Stride, UnsafeMutablePointer<Double>, vDSP_Length)

Calculates the distance squared between two double-precision points in n-dimensional space, using the specified strides.