---
title: "compress(_:gatingVector:result:)"
framework: accelerate
role: symbol
role_heading: Type Method
path: "accelerate/vdsp/compress(_:gatingvector:result:)-2yse4"
---

# compress(_:gatingVector:result:)

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

## Declaration

```swift
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

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

- [compress(_:gatingVector:nonZeroGatingCount:)](accelerate/vdsp/compress(_:gatingvector:nonzerogatingcount:)-3c7yk.md)
- [compress(_:gatingVector:nonZeroGatingCount:)](accelerate/vdsp/compress(_:gatingvector:nonzerogatingcount:)-93v23.md)
- [compress(_:gatingVector:result:)](accelerate/vdsp/compress(_:gatingvector:result:)-7fvy9.md)
