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 AK
using Metal
v = MtlArray(rand(Int32(1):Int32(100), 100_000))
s = AK.sum(v) # an Int
s = AK.sum(v; init=Int32(0)) # an Int as well
s = AK.sum(v; acctype=Int32) # an Int32, summed as Int32
m = MtlArray(rand(Int32(1):Int32(100), 10, 100_000))
s = AK.sum(m; dims=1) # row-wiseAcceleratedKernels.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 AK
using AMDGPU
v = 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)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 AK
using CUDA
v = 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)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 AK
using oneAPI
v = 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)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 AK
using CUDA
v = 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)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 AK
using AMDGPU
v = ROCArray(rand(Int32(1):Int32(100), 100_000))
s = AK.cumsum(v)Row-wise cumulative sum of a matrix:
m = ROCArray(rand(Int32(1):Int32(100), 10, 100_000))
s = AK.cumsum(m, dims=1)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 AK
using oneAPI
v = oneArray(rand(Int32(1):Int32(100), 100_000))
p = AK.cumprod(v)Row-wise cumulative product of a matrix:
m = oneArray(rand(Int32(1):Int32(100), 10, 100_000))
p = AK.cumprod(m, dims=1)