Contents

multiply(addition:subtraction:result:)

Calculates the double-precision element-wise product of the sum of two vectors and the difference of two vectors.

Declaration

static func multiply<R, S, T, U, V>(addition: (a: R, b: S), subtraction: (c: T, d: U), result: inout V) where R : AccelerateBuffer, S : AccelerateBuffer, T : AccelerateBuffer, U : AccelerateBuffer, V : AccelerateMutableBuffer, R.Element == Float, S.Element == Float, T.Element == Float, U.Element == Float, V.Element == Float

Parameters

  • addition:

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

  • subtraction:

    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 products of the first N elements of the addition of vectors A and B and the subtraction of vectors C and D.

 for (n = 0; n < N; ++n)
    E[n] = (B[n]+A[n]) * (C[n]-D[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] = [50, 40, 30, 20, 10]
    
    
    let e = [Float](unsafeUninitializedCapacity: count) {
        buffer, initializedCount in
        
        vDSP.multiply(addition: (a, b),
                      subtraction: (c, d),
                      result: &buffer)
        
        initializedCount = count
    }
    
    // Prints "[-495.0, -792.0, -891.0, -792.0, -495.0]".
    print(e)

See Also

Multiplication