# ?swap: Swap values of two arrays. As fast as you can, dear

**URL:** <https://discourse.julialang.org/t/swap-swap-values-of-two-arrays-as-fast-as-you-can-dear/81661>\
**Category:** General Usage\
**Created:** [May 25, 2022, 2:39pm UTC](https://discourse.julialang.org/t/swap-swap-values-of-two-arrays-as-fast-as-you-can-dear/81661 "2022-05-25T14:39:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [May 25, 2022, 2:39pm UTC](https://discourse.julialang.org/t/swap-swap-values-of-two-arrays-as-fast-as-you-can-dear/81661/1 "2022-05-25T14:39:41Z")

</div>

LAPACK has a function called ?swap to swap the values stored in two arrays

```julia
      subroutine dswap (n,dx,incx,dy,incy)
#
# interchanges two vectors.
# uses unrolled loops for increments equal one.
# jack dongarra, linpack, 3/11/78.
# modified 12/3/93, array(1) declarations changed to array(*)

```

This does not seem to be implemented in LinearAlgebra. (Maybe I have just looked in the wrong places.)

But the question is, how would this be done with the highest performance in Julia? I really do need to swap the values, not just the identifiers, by the way, because this will typically be done on slices.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [May 25, 2022, 2:53pm UTC](https://discourse.julialang.org/t/swap-swap-values-of-two-arrays-as-fast-as-you-can-dear/81661/2 "2022-05-25T14:53:00Z")

</div>

`LoopVectoriztion` should give optimal assembly for the trivial implementation.
