Contents

subtract(multiplication:multiplication:result:)

Calculates the double-precision element-wise difference of the products of two pairs of vectors.

Declaration

static func subtract<R, S, T, U, V>(multiplication multiplicationAB: (a: T, b: U), multiplication multiplicationCD: (c: R, d: S), result: inout V) where R : AccelerateBuffer, S : AccelerateBuffer, T : AccelerateBuffer, U : AccelerateBuffer, V : AccelerateMutableBuffer, R.Element == Double, S.Element == Double, T.Element == Double, U.Element == Double, V.Element == Double

Parameters

  • multiplicationAB:

    A tuple that contains the vectors A and B in E = (A * B) - (C * D).

  • multiplicationCD:

    A tuple that contains the vectors C and D in E = (A * B) - (C * D).

  • result:

    The output vector E in E = (A * B) - (C * D).

Discussion

This function calculates the differences of the first N elements of the product of vectors A and B and the product of vectors C and D.

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

[Image]

The following code shows an example of using this function:

    let count = 5
    
    let a: [Double] = [ 1,  2,  3,  4,  5]
    let b: [Double] = [10, 20, 30, 40, 50]
    let c: [Double] = [ 5,  4,  3,  2,  1]
    let d: [Double] = [50, 40, 30, 20, 10]
    
    let e = [Double](unsafeUninitializedCapacity: count) {
        buffer, initializedCount in
        
        vDSP.subtract(multiplication: (a, b),
                      multiplication: (c, d),
        result: &buffer)
        
        initializedCount = count
    }
    
    // Prints "[-240.0, -120.0, 0.0, 120.0, 240.0]".
    print(e)

See Also

Subtraction