Function

vDSP_svesq(_:_:_:_:)

Calculates the sum of squares in a single-precision vector.

Declaration

func vDSP_svesq(_ __A: UnsafePointer<Float>, _ __IA: vDSP_Stride, _ __C: UnsafeMutablePointer<Float>, _ __N: vDSP_Length)

Parameters

__A

Single-precision real input vector.

__I

Stride for A.

__C

Single-precision real output scalar.

__N

The number of elements to process.

Discussion

This function calculates the sum of the squares of the first N elements of A and writes the result to C:

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

The operation is:

C[0] = sum(A[n] * A[n], 0 <= n < N);

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

let stride = vDSP_Stride(1)

let a: [Float] = [-1.5, 2.25, 3.6,
                  0.2, -0.1, -4.3]
let n = vDSP_Length(a.count)

var c: Float = .nan

vDSP_svesq(a,
           stride,
           &c,
           n)

// Prints "sum of squares 38.8125"
print(String(format: "sum of squares %.4f", c))

See Also

Vector Summation

static func sum<U>(U) -> Double

Returns the double-precision vector sum.

static func sum<U>(U) -> Float

Returns the single-precision vector sum.

static func sumAndSumOfSquares<U>(U) -> (elementsSum: Double, squaresSum: Double)

Returns the double-precision vector sum and sum of squares.

static func sumAndSumOfSquares<U>(U) -> (elementsSum: Float, squaresSum: Float)

Returns the single-precision vector sum and sum of squares.

static func sumOfMagnitudes<U>(U) -> Double

Returns the double-precision vector sum of magnitudes.

static func sumOfMagnitudes<U>(U) -> Float

Returns the single-precision vector sum of magnitudes.

static func sumOfSquares<U>(U) -> Double

Returns the double-precision vector sum of squares.

static func sumOfSquares<U>(U) -> Float

Returns the single-precision vector sum of squares.

func vDSP_svemg(UnsafePointer<Float>, vDSP_Stride, UnsafeMutablePointer<Float>, vDSP_Length)

Calculates the sum of magnitudes in a single-precision vector.

func vDSP_svs(UnsafePointer<Float>, vDSP_Stride, UnsafeMutablePointer<Float>, vDSP_Length)

Calculates the sum of signed squares in a single-precision vector.

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

Calculates the sum of signed squares in a double-precision vector.