---
title: "gather(_:indices:result:)"
framework: accelerate
role: symbol
role_heading: Type Method
path: "accelerate/vdsp/gather(_:indices:result:)-7erii"
---

# gather(_:indices:result:)

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

## Declaration

```swift
static func gather<T, U, V>(_ vector: T, indices: U, result: inout V) where T : AccelerateBuffer, U : AccelerateBuffer, V : AccelerateMutableBuffer, T.Element == Float, U.Element == UInt, V.Element == Float
```

## Parameters

- `vector`: The source vector that the function gathers.
- `indices`: The vector that contains the one-based indices.
- `result`: The destination vector that receives the result.

## Discussion

Discussion The following code shows an example of gathering the values in source using the values in indices: let source: [Float] = [10, 20,                         30, 40,                         50, 60,                         70, 80]

let indices: [UInt] = [1, 3, 5, 7]

let count = indices.count

let destination = [Float](unsafeUninitializedCapacity: count) {     buffer, initializedCount in          vDSP.gather(source,                 indices: indices,                 result: &buffer)          initializedCount = count }

// Prints "[10.0, 30.0, 50.0, 70.0]". print(destination)

## See Also

### Vector gathering functions

- [gather(_:indices:)](accelerate/vdsp/gather(_:indices:)-4jwvh.md)
- [gather(_:indices:)](accelerate/vdsp/gather(_:indices:)-4yt3o.md)
- [gather(_:indices:result:)](accelerate/vdsp/gather(_:indices:result:)-34yzg.md)
