Reverse

AcceleratedKernels.reverse!Function
reverse!(
    v::AbstractArray, backend::Backend=get_backend(v);

    dims=:,

    # CPU settings
    max_tasks=Threads.nthreads(),
    min_elems=1,

    # GPU settings
    block_size=256,
)

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. The CPU and GPU settings are the same as for 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::Backend=get_backend(src);

    dims=:,

    # CPU settings
    max_tasks=Threads.nthreads(),
    min_elems=1,

    # GPU settings
    block_size=256,
)

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. The CPU and GPU settings are the same as for foreachindex.

source
AcceleratedKernels.reverseFunction
reverse(
    v::AbstractArray, backend::Backend=get_backend(v);

    dims=:,

    # CPU settings
    max_tasks=Threads.nthreads(),
    min_elems=1,

    # GPU settings
    block_size=256,
)

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 CPU and GPU settings are the same as for foreachindex.

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

source