Contents

add(_:_:result:)

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

Declaration

static func add<T, U, V>(_ vectorA: T, _ vectorB: U, result: inout V) where T : AccelerateBuffer, U : AccelerateBuffer, V : AccelerateMutableBuffer, T.Element == Double, U.Element == Double, V.Element == Double

Parameters

  • vectorA:

    The first input vector, A.

  • vectorB:

    The second input vector, B.

  • result:

    The output vector, C.

Discussion

This function calculates the sums of the first N elements of input vectors A and B, and writes the result to output vector C.

 for (n = 0; n < N; ++n)
    C[n] = A[n] + B[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](unsafeUninitializedCapacity: count) {
        buffer, initializedCount in
        
        vDSP.add(a, b,
                 result: &buffer)
        
        initializedCount = count
    }
   
    // Prints "[11.0, 22.0, 33.0, 44.0, 55.0]".
    print(c)

See Also

Addition