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

# compress(_:gatingVector:nonZeroGatingCount:)

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

## Declaration

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

## 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: [Float] = [1, 2,                        3, 4,                        5, 6,                        7, 8]

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