<!--
{
  "documentType" : "article",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/compression-and-gathering-functions",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Compression and gathering functions"
}
-->

# Compression and gathering functions

Compress vectors based on the nonzero elements in a gating vector, or gather vectors based on a separate vector that contains indices.

## Topics

### Vector compression

The functions in this group compress an input vector by eliminating elements that correspond to zero values in a gating vector.

[`static func compress<T, U>(T, gatingVector: U, nonZeroGatingCount: Int?) -> [Float]`](/documentation/Accelerate/vDSP/compress(_:gatingVector:nonZeroGatingCount:)-3c7yk)

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

[`static func compress<T, U>(T, gatingVector: U, nonZeroGatingCount: Int?) -> [Double]`](/documentation/Accelerate/vDSP/compress(_:gatingVector:nonZeroGatingCount:)-93v23)

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

[`static func compress<T, U, V>(T, gatingVector: U, result: inout V)`](/documentation/Accelerate/vDSP/compress(_:gatingVector:result:)-7fvy9)

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

[`static func compress<T, U, V>(T, gatingVector: U, result: inout V)`](/documentation/Accelerate/vDSP/compress(_:gatingVector:result:)-2yse4)

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

[`extern void vDSP_vcmprs(const float *__A, vDSP_Stride __IA, const float *__B, vDSP_Stride __IB, float *__C, vDSP_Stride __IC, vDSP_Length __N);`](/documentation/Accelerate/vDSP_vcmprs)

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

[`extern void vDSP_vcmprsD(const double *__A, vDSP_Stride __IA, const double *__B, vDSP_Stride __IB, double *__C, vDSP_Stride __IC, vDSP_Length __N);`](/documentation/Accelerate/vDSP_vcmprsD)

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

### Vector gathering functions

The functions in this group use indices or pointers stored in a source vector to generate a new vector with elements from a second source vector or memory.

[`static func gather<T, U>(T, indices: U) -> [Float]`](/documentation/Accelerate/vDSP/gather(_:indices:)-4jwvh)

Returns a gathered copy of the specified single-precision vector using a vector that defines the indices to keep.

[`static func gather<T, U>(T, indices: U) -> [Double]`](/documentation/Accelerate/vDSP/gather(_:indices:)-4yt3o)

Returns a gathered copy of the specified double-precision vector using a vector that defines the indices to keep.

[`static func gather<T, U, V>(T, indices: U, result: inout V)`](/documentation/Accelerate/vDSP/gather(_:indices:result:)-7erii)

Gathers the specified single-precision vector using a vector that defines the indices to keep.

[`static func gather<T, U, V>(T, indices: U, result: inout V)`](/documentation/Accelerate/vDSP/gather(_:indices:result:)-34yzg)

Gathers the specified double-precision vector using a vector that defines the indices to keep.

[`extern void vDSP_vindex(const float *__A, const float *__B, vDSP_Stride __IB, float *__C, vDSP_Stride __IC, vDSP_Length __N);`](/documentation/Accelerate/vDSP_vindex)

Generates a gathered copy of the specified single-precision vector using a vector that defines the zero-based indices to keep.

[`extern void vDSP_vindexD(const double *__A, const double *__B, vDSP_Stride __IB, double *__C, vDSP_Stride __IC, vDSP_Length __N);`](/documentation/Accelerate/vDSP_vindexD)

Generates a gathered copy of the specified double-precision vector using a vector that defines the zero-based indices to keep.

[`extern void vDSP_vgathr(const float *__A, const vDSP_Length *__B, vDSP_Stride __IB, float *__C, vDSP_Stride __IC, vDSP_Length __N);`](/documentation/Accelerate/vDSP_vgathr)

Generates a gathered copy of the specified single-precision vector using a vector that defines the one-based indices to keep.

[`extern void vDSP_vgathrD(const double *__A, const vDSP_Length *__B, vDSP_Stride __IB, double *__C, vDSP_Stride __IC, vDSP_Length __N);`](/documentation/Accelerate/vDSP_vgathrD)

Generates a gathered copy of the specified double-precision vector using a vector that defines the one-based indices to keep.

[`extern void vDSP_vgathra(const float * const*__A, vDSP_Stride __IA, float *__C, vDSP_Stride __IC, vDSP_Length __N);`](/documentation/Accelerate/vDSP_vgathra)

Generates a gathered copy of the specified single-precision vector using a vector that defines the pointers to the values to keep.

[`extern void vDSP_vgathraD(const double * const*__A, vDSP_Stride __IA, double *__C, vDSP_Stride __IC, vDSP_Length __N);`](/documentation/Accelerate/vDSP_vgathraD)

Generates a gathered copy of the specified double-precision vector using a vector that defines the pointers to the values to keep.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)