Function

vDSP_vaddi(_:_:_:_:_:_:_:)

Adds two integer vectors.

Declaration

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

Parameters

__A

Integer input vector.

__IA

Stride for A.

__B

Integer input vector

__IB

Stride for B.

__C

Integer result vector.

__IC

Stride for C.

__N

Number of elements to process in the input and output vectors.

Discussion

This function calculates the sums of the first N elements of A and B, writing the result to C:

A diagram showing the operation of the vDSP_vaddi function. There are three rows. The top row represents the first input, vector A. The second row represents the second input, vector B. The bottom row represents the output, vector C. The diagram has connecting lines from the input vectors to the output vector indicating the relationships between the inputs and output.

The operation is:

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

The following code shows an example of using vDSP_vaddi(_:_:_:_:_:_:_:):

let stride = vDSP_Stride(1)

let a: [Int32] = [10, 20, 30, 40, 50]
let b: [Int32] = [ 1,  2,  3,  4,  5]

let n = vDSP_Length(a.count)

var c = [Int32](repeating: 0,
                count: a.count)

vDSP_vaddi(a, stride,
           b, stride,
           &c, stride,
           n)

// Prints "[11, 22, 33, 44, 55]"
print(c)