Contents

absolute(_:result:)

Calculates the absolute value of each element in the supplied double-precision vector.

Declaration

static func absolute<U, V>(_ vector: U, result: inout V) where U : AccelerateBuffer, V : AccelerateMutableBuffer, U.Element == Double, V.Element == Double

Parameters

  • vector:

    The source vector.

  • result:

    On output, the absolute values of the elements in the source vector.

Discussion

For example, the following code calculates the absolute values of the elements of an array:

    let values: [Double] = [-1, 2, -3, 4, -5, 6, -7, 8]
    
    let absoluteValues = [Double](unsafeUninitializedCapacity: values.count) {
        buffer, initializedCount in
        
        vDSP.absolute(values, result: &buffer)
        
        initializedCount = values.count
    }
    
    // Prints "[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]".
    print(absoluteValues)

See Also

Vector absolute functions