<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/vDSP/gather(_:indices:result:)-7erii",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate4vDSPO6gather_7indices6resultyx_q_q0_ztAA0A6BufferRzAaGR_AA0a7MutableF0R0_Sf7ElementRtzSuAIRt_SfAIRt0_r1_lFZ"
  },
  "title" : "gather(_:indices:result:)"
}
-->

# gather(_:indices:result:)

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

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

The following code shows an example of gathering the values in `source` using the values in `indices`:

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

---

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)