add(multiplication:multiplication:result:)
Calculates the double-precision element-wise addition of two vector-scalar products.
Declaration
static func add<T, U, V>(multiplication multiplicationAB: (a: T, b: Double), multiplication multiplicationCD: (c: U, d: Double), result: inout V) where T : AccelerateBuffer, U : AccelerateBuffer, V : AccelerateMutableBuffer, T.Element == Double, U.Element == Double, V.Element == DoubleParameters
- multiplicationAB:
A tuple that contains the vector
Aand the scalar valueBinE = (A * B) + (C * D). - multiplicationCD:
A tuple that contains the vector
Cand the scalar valueDinE = (A * B) + (C * D). - result:
The output vector
EinE = (A * B) + (C * D).
Discussion
This function calculates the element-wise vector-scalar products of A and B, and C and D, and writes the sum of the products to vector D.
for (n = 0; n < N; ++n)
E[n] = A[n]*B + C[n]*D;[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
let c: [Double] = [ 5, 4, 3, 2, 1]
let d: Double = 50
let e = [Double](unsafeUninitializedCapacity: count) {
buffer, initializedCount in
vDSP.add(multiplication: (a, b),
multiplication: (c, d),
result: &buffer)
initializedCount = count
}
// Prints "[260.0, 220.0, 180.0, 140.0, 100.0]".
print(e)