Contents

compress(_:gatingVector:result:)

Compresses the specified double-precision vector using the nonzero values in a gating vector.

Declaration

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

Parameters

  • vector:

    The source vector that the function compresses.

  • gatingVector:

    The gating vector.

  • result:

    The destination vector that receives the result.

Discussion

The following code shows an example of compressing the values in source using the nonzero values in gatingVector:

let source: [Double] = [1, 2,
                        3, 4,
                        5, 6,
                        7, 8]

let gatingVector: [Double] = [-1, 0,
                              1, 0,
                              0.001, 0,
                              10, 0]

let count = gatingVector.filter {
    !$0.isZero
}.count

let destination = [Double](unsafeUninitializedCapacity: count) {
    buffer, initializedCount in
    
    vDSP.compress(source,
                  gatingVector: gatingVector,
                  result: &buffer)
    
    initializedCount = count
}

// Prints "[1.0, 3.0, 5.0, 7.0]".
print(destination)

See Also

Vector compression