Function

vDSP_vsmsma(_:_:_:_:_:_:_:_:_:)

Adds the product of a single-precision vector and a single-precision scalar value to a second product of a single-precision vector and a single-precision scalar value.

Declaration

func vDSP_vsmsma(_ __A: UnsafePointer<Float>, _ __IA: vDSP_Stride, _ __B: UnsafePointer<Float>, _ __C: UnsafePointer<Float>, _ __IC: vDSP_Stride, _ __D: UnsafePointer<Float>, _ __E: UnsafeMutablePointer<Float>, _ __IE: vDSP_Stride, _ __N: vDSP_Length)

Parameters

__A

Single-precision real input vector.

__IA

Stride for A.

__B

Pointer to single-precision real input scalar.

__C

Single-precision real input vector.

__IC

Stride for C.

__D

Pointer to single-precision real input scalar.

__E

Single-precision real output vector.

__IE

Stride for E.

__N

Number of elements to process in each vector.

Discussion

This function calculates the products of the first N elements of A and the scalar value B, the products of the first N elements of C and the scalar value D, sum the corresponding products, and writes the result to E:

A diagram showing the operation of the vDSP_vsmsma function. There are four rows and the top three rows are composed of two columns. The top two rows of the left column represent the input vector A and scalar B. The top two rows of the right column represent the input vector C and scalar D. The third row in both columns represent the intermediate result of the respective inputs. The bottom row represents the output vector, E. The diagram has connecting lines from the inputs to the output vector indicating the relationships between the inputs and output.

The operation is:

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

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

let a: [Float] = [1, 2, 4, 5]
var b: Float = 2
let c: [Float] = [10, 20, 40, 50]
var d: Float = 10

var e = [Float](repeating: 0,
                count: a.count)

let stride = vDSP_Stride(1)
let n = vDSP_Length(a.count)

vDSP_vsmsma(a, stride,
            &b,
            c, stride,
            &d,
            &e, stride,
            n)

// Prints "[102.0, 204.0, 408.0, 510.0]"
print(e)

See Also

Quaternary (Vector-Vector-Scalar-Scalar) Multiply-Multiply-Add Operations

func vDSP_vsmsmaD(UnsafePointer<Double>, vDSP_Stride, UnsafePointer<Double>, UnsafePointer<Double>, vDSP_Stride, UnsafePointer<Double>, UnsafeMutablePointer<Double>, vDSP_Stride, vDSP_Length)

Adds the product of a double-precision vector and a double-precision scalar value to a second product of a double-precision vector and a double-precision scalar value.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software