Contents

subtract(multiplication:_:result:)

Calculates the single-precision element-wise difference of a vector and the product of two vectors.

Declaration

static func subtract<S, T, U, V>(multiplication: (a: T, b: U), _ vector: S, result: inout V) where S : AccelerateBuffer, T : AccelerateBuffer, U : AccelerateBuffer, V : AccelerateMutableBuffer, S.Element == Float, T.Element == Float, U.Element == Float, V.Element == Float

Parameters

  • multiplication:

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

  • vector:

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

  • result:

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

Discussion

This function calculates the products of the first N elements of A and B, subtracts each product from the corresponding value in C, and writes the result to D.

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

[Image]

The following code shows an example of using this function:

    let count = 5
    
    let a: [Float] = [ 1,  2,  3,  4,  5]
    let b: [Float] = [10, 20, 30, 40, 50]
    let c: [Float] = [ 5,  4,  3,  2,  1]
    
    let d = [Float](unsafeUninitializedCapacity: count) {
        buffer, initializedCount in
        
        vDSP.subtract(multiplication: (a, b), 
                      c,
                      result: &buffer)
        
        initializedCount = count
    }
    
    // Prints "[5.0, 36.0, 87.0, 158.0, 249.0]".
    print(d)

See Also

Subtraction