---
title: "compress(_:gatingVector:nonZeroGatingCount:)"
framework: accelerate
role: symbol
role_heading: Type Method
path: "accelerate/vdsp/compress(_:gatingvector:nonzerogatingcount:)-93v23"
---

# compress(_:gatingVector:nonZeroGatingCount:)

Returns a compressed copy of the specified double-precision vector using the nonzero values in a gating vector.

## Declaration

```swift
static func compress<T, U>(_ vector: T, gatingVector: U, nonZeroGatingCount: Int?) -> [Double] where T : AccelerateBuffer, U : AccelerateBuffer, T.Element == Double, U.Element == Double
```

## Parameters

- `vector`: The source vector that the function compresses.
- `gatingVector`: The gating vector.
- `nonZeroGatingCount`: The number of nonzero elements in gatingVector. Set to nil to have the operation calculate this value for you.

## Return Value

Return Value The result of the compression operation.

## 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 destination = vDSP.compress(source,                                 gatingVector: gatingVector,                                 nonZeroGatingCount: nil)

// 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:result:)](accelerate/vdsp/compress(_:gatingvector:result:)-7fvy9.md)
- [compress(_:gatingVector:result:)](accelerate/vdsp/compress(_:gatingvector:result:)-2yse4.md)
