Contents

sumAndSumOfSquares(_:)

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

Declaration

static func sumAndSumOfSquares<U>(_ vector: U) -> (elementsSum: Double, squaresSum: Double) where U : AccelerateBuffer, U.Element == Double

Parameters

  • vector:

    The vector to sum.

Discussion

This function calculates and returns the sum and the sum of the squares of the elements of a supplied vector.

The following is an example of using sumAndSumOfSquares(_:):

let a: [Double] = [-1.5, 2.25, 3.6,
                   0.2, -0.1, -4.3]

let sumAndSumOfSquares = vDSP.sumAndSumOfSquares(a)

// Prints "sum 0.1500 sum of squares 38.8125"
print(String(format: "sum %.4f", sumAndSumOfSquares.elementsSum),
      String(format: "sum of squares %.4f", sumAndSumOfSquares.squaresSum))

See Also

Type Methods