Arithmetics

AcceleratedKernels.sum — Function
sum(src::AbstractArray; kwargs...)

Sum of the elements of an array, with Base's add_sum, so that small integers are summed as Int. The keywords are those of mapreduce. Without init, an empty array, or along dims an empty slice, sums to zero of the accumulator type.

import AcceleratedKernels as AKusing Metalv = MtlArray(rand(Int32(1):Int32(100), 100_000))s = AK.sum(v)                           # an Ints = AK.sum(v; init=Int32(0))            # an Int as wells = AK.sum(v; acctype=Int32)            # an Int32, summed as Int32m = MtlArray(rand(Int32(1):Int32(100), 10, 100_000))s = AK.sum(m; dims=1)                   # column sums, a 1×100_000 MtlArray
source
AcceleratedKernels.prod — Function
prod(src::AbstractArray; kwargs...)

Product of the elements of an array, with Base's mul_prod. The keywords are those of mapreduce. Without init, an empty array, or along dims an empty slice, has the product one of the accumulator type.

import AcceleratedKernels as AKusing AMDGPUv = ROCArray(rand(Int32(1):Int32(100), 100_000))p = AK.prod(v)p = AK.prod(ROCArray(rand(Int32(1):Int32(100), 10, 100_000)); dims=1)
source
AcceleratedKernels.minimum — Function
minimum(src::AbstractArray; kwargs...)

Minimum of the elements of an array; the minimum of an empty array, or along dims of an empty slice, is an error unless init is given. The keywords are those of mapreduce.

import AcceleratedKernels as AKusing CUDAv = CuArray(rand(Int32(1):Int32(100), 100_000))m = AK.minimum(v)m = AK.minimum(CuArray(rand(Int32(1):Int32(100), 10, 100_000)); dims=1)
source
AcceleratedKernels.maximum — Function
maximum(src::AbstractArray; kwargs...)

Maximum of the elements of an array; the maximum of an empty array, or along dims of an empty slice, is an error unless init is given. The keywords are those of mapreduce.

import AcceleratedKernels as AKusing oneAPIv = oneArray(rand(Int32(1):Int32(100), 100_000))m = AK.maximum(v)m = AK.maximum(oneArray(rand(Int32(1):Int32(100), 10, 100_000)); dims=1)
source
AcceleratedKernels.count — Function
count([f=identity,] src::AbstractArray; init=0, kwargs...)

Count the elements of src for which f returns true: f must return a Bool, and the count is added to init (so an empty array counts init). The keywords are those of mapreduce.

import AcceleratedKernels as AKusing CUDAv = CuArray(rand(Float32, 100_000))c = AK.count(x -> x > 0.5, v)c = AK.count(CuArray(rand(Bool, 10, 100_000)); init=Int32(0), dims=2)
source
AcceleratedKernels.cumsum — Function
cumsum(src::AbstractArray; kwargs...)

Cumulative sum of elements of an array, as Base.cumsum (Base's add_sum, so small integers are summed as Int), except that without dims a multidimensional array is summed in linear order. The keywords are those of accumulate.

Examples

Simple cumulative sum of elements in a vector:

import AcceleratedKernels as AKusing AMDGPUv = ROCArray(rand(Int32(1):Int32(100), 100_000))s = AK.cumsum(v)

Cumulative sum down each column of a matrix:

m = ROCArray(rand(Int32(1):Int32(100), 10, 100_000))s = AK.cumsum(m, dims=1)
source
AcceleratedKernels.cumprod — Function
cumprod(src::AbstractArray; kwargs...)

Cumulative product of elements of an array, as Base.cumprod (Base's mul_prod), except that without dims a multidimensional array is multiplied in linear order. The keywords are those of accumulate.

Examples

Simple cumulative product of elements in a vector:

import AcceleratedKernels as AKusing oneAPIv = oneArray(rand(Int32(1):Int32(100), 100_000))p = AK.cumprod(v)

Cumulative product down each column of a matrix:

m = oneArray(rand(Int32(1):Int32(100), 10, 100_000))p = AK.cumprod(m, dims=1)
source