Reverse

AcceleratedKernels.reverse! — Function
reverse!(
    v::AbstractArray;
    backend=nothing,
    dims=:,
    block_size::Int=256,
    max_tasks::Int=Threads.nthreads(),
    min_elems::Int=1,
) -> v

Reverse v in-place and return it. With dims=: (the default) the whole array is reversed; pass dims=d (an integer or an iterable of distinct integers in 1:ndims(v)) to reverse only along those dimensions. dims=() leaves v unchanged. backend is derived from v; the other keywords are those of foreachindex.

No temporary array is allocated.

To reverse a contiguous sub-range of a vector, reverse a view: AK.reverse!(@view v[lo:hi]).

Examples

import CUDA
import AcceleratedKernels as AK

v = CUDA.CuArray(1:100_000)
AK.reverse!(v)

m = CUDA.CuArray(reshape(1:12, 3, 4))
AK.reverse!(m; dims=2)          # reverse the columns
source
reverse!(
    dst::AbstractArray, src::AbstractArray;
    backend=nothing,
    dims=:,
    block_size::Int=256,
    max_tasks::Int=Threads.nthreads(),
    min_elems::Int=1,
) -> dst

Write the reverse of src into dst and return dst; src is left unchanged. dst and src must not alias. With dims=: (the default), the whole array is reversed and only the lengths must match. With an integer or iterable of distinct dimensions, the sizes must match. dims=() copies src unchanged. Elements are converted to the destination element type on assignment. backend is derived from dst and src; the other keywords are those of foreachindex.

source
AcceleratedKernels.reverse — Function
reverse(v::AbstractArray; kwargs...)

Return a reversed copy of v, leaving v unchanged. With dims=: (the default) the whole array is reversed; pass dims=d to reverse only along those dimensions, matching Base.reverse. The keywords are those of reverse!.

Prefer reverse! when you do not need to keep v; it avoids the allocation.

source