Function

vDSP_vsbsm(_:_:_:_:_:_:_:_:)

Multiplies the difference of two single-precision vectors by a single-precision scalar value.

Declaration

func vDSP_vsbsm(_ __A: UnsafePointer<Float>, _ __IA: vDSP_Stride, _ __B: UnsafePointer<Float>, _ __IB: vDSP_Stride, _ __C: UnsafePointer<Float>, _ __D: UnsafeMutablePointer<Float>, _ __ID: vDSP_Stride, _ __N: vDSP_Length)

Parameters

__A

Single-precision real input vector.

__IA

Stride for A.

__B

Single-precision real input vector.

__IB

Stride for B.

__C

Single-precision real input scalar.

__D

Single-precision real output vector.

__ID

Stride for D.

__N

The number of elements to process.

Discussion

This function subtracts the the first N elements of A from B, multiplies the differences by the scalar value C, and writes the result to D:

A diagram showing the operation of the vDSP_vsbsm function. There are five rows. The top two rows represents the first two inputs, vector A and vector B. The third row represents the intermediate result of the first two inputs. The forth row represents the third input, scalar C. The bottom row represents the output, vector D. 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)
    D[n] = (A[n] - B[n]) * C;

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

let stride = vDSP_Stride(1)

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

var c: Float = 2

let n = vDSP_Length(a.count)

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

vDSP_vsbsm(a, stride,
           b, stride,
           &c,
           &d, stride,
           n)

// Prints "[18.0, 36.0, 54.0, 72.0, 90.0]"
print(d)

See Also

Ternary (Vector-Vector-Scalar) Subtract-Multiply Operations