VectorizedReduction.jl Documentation
Functions
VectorizedReduction.vall
— Methodvall([p=identity,] A::AbstractArray; dims=:)
Identical to non-keyword args version; slightly less performant due to use of kwargs.
VectorizedReduction.vall
— Methodvall([p=identity,] A::AbstractArray, dims=:)
Determine whether predicate p
returns true for all elements over the given dims
. If p
is omitted, test whether all values along the given dims
are true
(in which case A
should be AbstractArray{Bool}
).
Usage Recommendation
If A
is reasonably small, vall
may be faster than all
; however, as the size of A
grows, the probability of all element returning false
inevitably increases (it is repeated Bernoulli sampling, thus, even with a very small success probability, a large number of tries makes may yield a scenario where the break
of all
wins out). Consequently, the probability of individual elements being true
should determine choice – if one suspects a reasonable success probability, then all
may be preferable, depending on the size A
. More testing is needed to determine potential breakpoints.
Additional Notes
This function suffers from the same issue as vfindmax
and friends – reductions which include the first dimension with max masks are not yet supported by LoopVectorization. Notably, this function still works as intended for any reduction which does not involve the first dimension.
VectorizedReduction.vany
— Methodvany([p=identity,] A::AbstractArray; dims=:)
Identical to non-keyword args version; slightly less performant due to use of kwargs.
VectorizedReduction.vany
— Methodvany([p=identity,] A::AbstractArray, dims=:)
Determine whether predicate p
returns true for any elements over the given dims
. If p
is omitted, test whether any values along the given dims
are true
(in which case A
should be AbstractArray{Bool}
).
Usage Recommendation
If A
is reasonably small, vany
may be faster than any
; however, as the size of A
grows, the probability of any element returning true
inevitably increases (it is repeated Bernoulli sampling, thus, even with a very small success probability, a large number of tries makes may yield a scenario where the break
of any
wins out). Consequently, the probability of individual elements being true
should determine choice – if one suspects a reasonable success probability, then any
may be preferable, depending on the size A
. More testing is needed to determine potential breakpoints.
Additional Notes
This function suffers from the same issue as vfindmax
and friends – reductions which include the first dimension with zero masks are not yet supported by LoopVectorization. Notably, this function still works as intended for any reduction which does not involve the first dimension.
VectorizedReduction.vargmax
— Methodvargmax(A::AbstractArray, dims=:)
Return the index of the maximal value of A
over the dimensions dims
.
VectorizedReduction.vargmax
— Methodvargmax(f, A; dims)
vargmax(A; dims)
Identical to non-keywords args version; slightly less performant due to use of kwargs.
VectorizedReduction.vargmax
— Methodvargmax(f, A::AbstractArray, dims=:)
Return the index of the argument which maximizes f
over the dimensions dims
, which may be ::Int
, ::NTuple{M, Int} where {M}
or ::Colon
. Expands upon the functionality provided in Julia Base.
Additional Notes
Due to the current limitations of LoopVectorization, searches over the first dimension of an array are not well-supported. A workaround is possible by reshaping A
but the resultant performance is often only on par with argmax
. As a temporary convenience, vargmax1
is provided for explicit uses of the re-shaping strategy, though the user is cautioned as to the performance problems.
VectorizedReduction.vargmax
— Methodvargmax(f, As::Vararg{AbstractArray, N}; dims=:) where {N}
Return the index of the arguments which maximize f
: ℝᴺ → ℝ over the dimensions dims
. This expands upon the functionality which exists in Julia Base.
VectorizedReduction.vargmin
— Methodvargmin(A::AbstractArray, dims=:)
Return the index of the minimal value of A
over the dimensions dims
.
VectorizedReduction.vargmin
— Methodvargmin(f, A; dims)
vargmin(A; dims)
Identical to non-keywords args version; slightly less performant due to use of kwargs.
VectorizedReduction.vargmin
— Methodvargmin(f, A::AbstractArray, dims=:)
Return the index of the argument which minimizes f
over the dimensions dims
, which may be ::Int
, ::NTuple{M, Int} where {M}
or ::Colon
. Expands upon the functionality provided in Julia Base.
Additional Notes
Due to the current limitations of LoopVectorization, searches over the first dimension of an array are not well-supported. A workaround is possible by reshaping A
but the resultant performance is often only on par with argmin
. As a temporary convenience, vargmin1
is provided for explicit uses of the re-shaping strategy, though the user is cautioned as to the performance problems.
VectorizedReduction.vargmin
— Methodvargmin(f, As::Vararg{AbstractArray, N}; dims=:) where {N}
Return the index of the arguments which minimize f
: ℝᴺ → ℝ over the dimensions dims
. This expands upon the functionality which exists in Julia Base.
VectorizedReduction.vchebyshev
— Methodvchebyshev(x::AbstractArray, y::AbstractArray; dims=:)
Compute the Chebyshev distance between the vectors corresponding to the slices along the dimensions dims
.
See also: vmanhattan
, veuclidean
, vminkowski
VectorizedReduction.vcount
— Methodvcount([f=identity,] A::AbstractArray; dims=:)
Identical to non-keyword args version; slightly less performant due to use of kwargs.
VectorizedReduction.vcount
— Methodvcount([f=identity,] A::AbstractArray, dims=:)
Count the number of elements in A
for which f
return true over the given dims
. If f
is omitted, count the number of true
elements in A
(which should be AbstractArray{Bool}
).
VectorizedReduction.vcounteq
— Methodvcounteq(x::AbstractArray, y::AbstractArray; dims=:)
Count the number of elements for which xᵢ == yᵢ
returns true
on the vectors corresponding to the slices along the dimension dims
.
See also: vcountne
VectorizedReduction.vcountne
— Methodvcountne(x::AbstractArray, y::AbstractArray; dims=:)
Count the number of elements for which xᵢ != yᵢ
returns true
on the vectors corresponding to the slices along the dimension dims
.
See also: vcounteq
VectorizedReduction.veuclidean
— Methodveuclidean(x::AbstractArray, y::AbstractArray; dims=:)
Compute the Euclidean distance between the vectors corresponding to the slices along the dimensions dims
.
See also: vmanhattan
, vchebyshev
, vminkowski
VectorizedReduction.vfindmax
— Methodvfindmax(A::AbstractArray, dims=:) -> (x, index)
Return the maximal element and its index over the dimensions dims
.
VectorizedReduction.vfindmax
— Methodvfindmax(f, A; dims) -> (f(x), index)
vfindmax(A; dims) -> (x, index)
Identical to non-keywords args version; slightly less performant due to use of kwargs.
VectorizedReduction.vfindmax
— Methodvfindmax(f, A::AbstractArray, dims=:) -> (f(x), index)
Return the value and the index of the argument which maximizes f
over the dimensions dims
, which may be ::Int
, ::NTuple{M, Int} where {M}
or ::Colon
. Expands upon the functionality provided in Julia (v1.8) Base.
Additional Notes
Due to the current limitations of LoopVectorization, searches over the first dimension of an array are not well-supported. A workaround is possible by reshaping A
but the resultant performance is often only on par with findmax
. As a temporary convenience, vfindmax1
is provided for explicit uses of the re-shaping strategy, though the user is cautioned as to the performance problems.
Warning
NaN
values are not handled!
VectorizedReduction.vfindmax
— Methodvfindmax(f, As::Vararg{AbstractArray, N}; dims=:) where {N} -> (f(x,y,z,...), index)
Return the value and index of the arguments which maximize f
: ℝᴺ → ℝ over the dimensions dims
. This expands upon the functionality which exists in Julia Base.
VectorizedReduction.vfindmin
— Methodvfindmin(A::AbstractArray, dims=:) -> (x, index)
Return the minimal element and its index over the dimensions dims
.
VectorizedReduction.vfindmin
— Methodvfindmin(f, A; dims) -> (f(x), index)
vfindmin(A; dims) -> (x, index)
Identical to non-keywords args versions; slightly less performant due to use of kwargs.
VectorizedReduction.vfindmin
— Methodvfindmin(f, A::AbstractArray, dims=:) -> (f(x), index)
Return the value and the index of the argument which minimizes f
over the dimensions dims
, which may be ::Int
, ::NTuple{M, Int} where {M}
or ::Colon
. Expands upon the functionality provided in Julia (v1.8) Base.
Additional Notes
Due to the current limitations of LoopVectorization, searches over the first dimension of an array are not well-supported. A workaround is possible by reshaping A
but the resultant performance is often only on par with findmin
. As a temporary convenience, vfindmin1
is provided for explicit uses of the re-shaping strategy, though the user is cautioned as to the performance problems.
Warning
NaN
values are not handled!
VectorizedReduction.vfindmin
— Methodvfindmin(f, As::Vararg{AbstractArray, N}; dims=:) where {N} -> (f(x,y,z,...), index)
Return the value and index of the arguments which minimize f
: ℝᴺ → ℝ over the dimensions dims
. This expands upon the functionality which exists in Julia Base.
VectorizedReduction.vlogsoftmax
— Methodvlogsoftmax(A::AbstractArray)
Compute the log of the softmax function, treating the entire array as a single vector. Care is taken to ensure that the computation will not overflow/underflow, but the caller should be aware that +Inf
and NaN
are not handled.
See also: vsoftmax
VectorizedReduction.vlogsoftmax
— Methodvlogsoftmax(A::AbstractArray; dims=:)
Identical to non-keyword args version; slightly less performant due to use of kwargs.
VectorizedReduction.vlogsoftmax
— Methodvlogsoftmax(A::AbstractArray, dims)
Compute the log of the softmax function, treating each slice of A
specified by dims
as if it were a single vector; dims
may be ::Int
, ::NTuple{M, Int} where {M}
or ::Colon
. Avoids overflow/underflow, but +Inf
and NaN
are not handled.
VectorizedReduction.vlogsumexp
— Methodvlogsumexp(A::AbstractArray)
Compute the log of the sum of exponentials of each element of A
. Care is taken to ensure that the computation will not overflow/underflow, but the caller should be aware that +Inf
and NaN
are not handled.
VectorizedReduction.vlogsumexp
— Methodvlogsumexp(A::AbstractArray; dims=:)
Identical to non-keyword args version; slightly less performant due to use of kwargs.
VectorizedReduction.vlogsumexp
— Methodvlogsumexp(A::AbstractArray, dims)
Compute the log of the sum of exponentials of each element of A
along the dimensions dims
, which may be ::Int
, ::NTuple{M, Int} where {M}
or ::Colon
. Avoids overflow/underflow, but +Inf
and NaN
are not handled.
VectorizedReduction.vmanhattan
— Methodvmanhattan(x::AbstractArray, y::AbstractArray; dims=:)
Compute the Manhattan distance between the vectors corresponding to the slices along the dimensions dims
.
See also: veuclidean
, vchebyshev
, vminkowski
VectorizedReduction.vmapreducethen
— Methodvmapreducethen(f, op, g, A::AbstractArray; dims=:, init)
Apply function f
to each element of A
, reduce the result over the dimensions dims
using the binary function op
, then apply g
to the result. Equivalent to g.(mapreduce(f, op, A, dims=dims, init=init))
but avoids the intermediate implied by said expression while also fusing the post-transform g
such that the output array is populated in a single pass.
The reduction necessitates an initial value init
which may be <:Number
or a function which accepts a single type argument (e.g. zero
); init
is optional for binary operators +
, *
, min
, and max
.
Examples
julia> vmapreducethen(abs2, +, √, [1 2; 3 4], dims=1) # L₂-norm; see `vnorm`
1×2 Matrix{Float64}:
3.16228 4.47214
julia> vmapreducethen(abs2, +, √, [1 2; 3 4], dims=2, init=1000.0)
2×1 Matrix{Float64}:
31.701734968294716
32.01562118716424
julia> vmapreducethen(exp, +, log, [5 6; 7 8], dims=1) # LSE, but recommend `vlogsumexp`
1×2 Matrix{Float64}:
7.12693 8.12693
VectorizedReduction.vmapreducethen
— Methodvmapreducethen(f, op, g, As::Vararg{AbstractArray, N}; dims=:, init) where {N}
Version of mapreducethen
wherein f
: ℝᴺ → ℝ, then g
: ℝ → ℝ, with reduction over the dimensions dims
.
Examples
julia> x, y, z = [1 2; 3 4], [5 6; 7 8], [9 10; 11 12];
julia> vmapreducethen((a, b) -> abs2(a - b), +, √, x, y, dims=2) # Euclidean distance
2×1 Matrix{Float64}:
5.656854249492381
5.656854249492381
julia> vmapreducethen(*, *, exp, x, y, z, dims=2, init=-1.0)
2×1 Matrix{Float64}:
0.0
0.0
VectorizedReduction.vmaxad
— Methodvmaxad(x::AbstractArray, y::AbstractArray; dims=:)
Compute the maximum absolute deviation between the vectors corresponding to the slices along the dimension dims
.
See also: vmeanad
VectorizedReduction.vmeanad
— Methodvmeanad(x::AbstractArray, y::AbstractArray; dims=:)
Compute the mean absolute deviation between the vectors corresponding to the slices along the dimension dims
.
See also: vmaxad
VectorizedReduction.vminkowski
— Methodvminkowski(x::AbstractArray, y::AbstractArray, p::Real; dims=:)
Compute the Minkowski distance between the vectors corresponding to the slices along the dimensions dims
.
p
can assume any numeric value (even though not all values produce a mathematically valid vector norm). vminkowski(x, y, Inf)
returns the largest value in abs.(x .- y)
, whereas vminkowski(x, y, -Inf)
returns the smallest.
See also: vmanhattan
, veuclidean
, vchebyshev
VectorizedReduction.vmse
— Methodvmse(x::AbstractArray, y::AbstractArray; dims=:)
Compute the mean squared error between the vectors corresponding to the slices along the dimension dims
.
See also: vrmse
VectorizedReduction.vnorm
— Functionvnorm(A::AbstractArray, p::Real=2; dims=:)
Compute the p
-norm of A
along the dimensions dims
as if the corresponding slices were vectors.
p
can assume any numeric value (even though not all values produce a mathematically valid vector norm). vnorm(A, Inf)
returns the largest value in abs.(A)
, whereas vnorm(A, -Inf)
returns the smallest; vnorm(A, 0)
matches the behavior of LinearAlgebra.norm(A, 0)
.
See also: vtnorm
VectorizedReduction.vrmse
— Methodvrmse(x::AbstractArray, y::AbstractArray; dims=:)
Compute the square root of the mean squared error between the vectors corresponding to the slices along the dimension dims
. More efficient than sqrt.(vmse(...))
as the sqrt
operation is performed at the point of generation, thereby eliminating the full traversal which would otherwise occur.
See also: vmse
VectorizedReduction.vsoftmax
— Methodvsoftmax(A::AbstractArray)
Compute the softmax function, treating the entire array as a single vector. Care is taken to ensure that the computation will not overflow/underflow, but the caller should be aware that +Inf
and NaN
are not handled.
See also: vlogsoftmax
VectorizedReduction.vsoftmax
— Methodvsoftmax(A::AbstractArray; dims=:)
Identical to non-keyword args version; slightly less performant due to use of kwargs.
VectorizedReduction.vsoftmax
— Methodvsoftmax(A::AbstractArray, dims)
Compute the softmax function, treating each slice of A
specified by dims
as if it were a single vector; dims
may be ::Int
, ::NTuple{M, Int} where {M}
or ::Colon
. Avoids overflow/underflow, but +Inf
and NaN
are not handled.
VectorizedReduction.vtall
— Methodvtall([p=identity,] A::AbstractArray; dims=:)
Identical to non-keyword args version; slightly less performant due to use of kwargs.
VectorizedReduction.vtall
— Methodvtall([p=identity,] A::AbstractArray, dims=:)
Determine whether predicate p
returns true for all elements over the given dims
. If p
is omitted, test whether all values along the given dims
are true
(in which case A
should be AbstractArray{Bool}
). Threaded.
Additional Notes
This function suffers from the same issue as vfindmax
and friends – reductions which include the first dimension with max masks are not yet supported by LoopVectorization. Notably, this function still works as intended for any reduction which does not involve the first dimension.
VectorizedReduction.vtany
— Methodvtany([p=identity,] A::AbstractArray; dims=:)
Identical to non-keyword args version; slightly less performant due to use of kwargs.
VectorizedReduction.vtany
— Methodvtany([p=identity,] A::AbstractArray, dims=:)
Determine whether predicate p
returns true for any elements over the given dims
. If p
is omitted, test whether any values along the given dims
are true
(in which case A
should be AbstractArray{Bool}
). Threaded.
Additional Notes
This function suffers from the same issue as vfindmax
and friends – reductions which include the first dimension with zero masks are not yet supported by LoopVectorization. Notably, this function still works as intended for any reduction which does not involve the first dimension.
VectorizedReduction.vtargmax
— Methodvtargmax(A::AbstractArray, dims=:)
Return the index of the maximal element over the dimensions dims
. Threaded.
VectorizedReduction.vtargmax
— Methodvtargmax(f, A; dims)
vtargmax(A; dims)
Identical to non-keywords args version; slightly less performant due to use of kwargs. Threaded.
VectorizedReduction.vtargmax
— Methodvtargmax(f, A::AbstractArray, dims=:)
Return the index of the argument which maximizes f
over the dimensions dims
, which may be ::Int
, ::NTuple{M, Int} where {M}
or ::Colon
. Threaded.
See also: vargmax
VectorizedReduction.vtargmax
— Methodvargmax(f, As::Vararg{AbstractArray, N}; dims=:) where {N}
Return the index of the arguments which maximize f
: ℝᴺ → ℝ over the dimensions dims
. Threaded.
VectorizedReduction.vtargmin
— Methodvtargmin(A::AbstractArray, dims=:)
Return the index of the minimal element over the dimensions dims
. Threaded.
VectorizedReduction.vtargmin
— Methodvtargmin(f, A; dims)
vtargmin(A; dims)
Identical to non-keywords args version; slightly less performant due to use of kwargs. Threaded.
VectorizedReduction.vtargmin
— Methodvtargmin(f, A::AbstractArray, dims=:)
Return the index of the argument which minimizes f
over the dimensions dims
, which may be ::Int
, ::NTuple{M, Int} where {M}
or ::Colon
. Threaded.
See also: vargmin
VectorizedReduction.vtargmin
— Methodvargmin(f, As::Vararg{AbstractArray, N}; dims=:) where {N}
Return the index of the arguments which minimize f
: ℝᴺ → ℝ over the dimensions dims
. Threaded.
VectorizedReduction.vtchebyshev
— Methodvtchebyshev(x::AbstractArray, y::AbstractArray; dims=:)
Compute the Chebyshev distance between the vectors corresponding to the slices along the dimensions dims
. Threaded.
See also: vtmanhattan
, vteuclidean
, vtminkowski
VectorizedReduction.vtcount
— Methodvtcount([f=identity,] A::AbstractArray; dims=:)
Identical to non-keyword args version; slightly less performant due to use of kwargs. Threaded.
VectorizedReduction.vtcount
— Methodvtcount([f=identity,] A::AbstractArray, dims=:)
Count the number of elements in A
for which f
return true over the given dims
. If f
is omitted, count the number of true
elements in A
(which should be AbstractArray{Bool}
). Threaded.
VectorizedReduction.vtcounteq
— Methodvtcounteq(x::AbstractArray, y::AbstractArray; dims=:)
Count the number of elements for which xᵢ == yᵢ
returns true
on the vectors corresponding to the slices along the dimension dims
. Threaded.
See also: vtcountne
VectorizedReduction.vtcountne
— Methodvtcountne(x::AbstractArray, y::AbstractArray; dims=:)
Count the number of elements for which xᵢ != yᵢ
returns true
on the vectors corresponding to the slices along the dimension dims
. Threaded.
See also: vtcounteq
VectorizedReduction.vteuclidean
— Methodvteuclidean(x::AbstractArray, y::AbstractArray; dims=:)
Compute the Euclidean distance between the vectors corresponding to the slices along the dimensions dims
. Threaded.
See also: vtmanhattan
, vtchebyshev
, vtminkowski
VectorizedReduction.vtextrema
— Methodvtextrema([f=identity], A::AbstractArray, dims=:)
Compute the minimum and maximum values by calling f
on each element of of A
over the given dims
. Threaded.
VectorizedReduction.vtextrema
— Methodvtextrema([f=identity], A::AbstractArray; [dims=:], [init=(mn,mx)])
Compute the minimum and maximum values by calling f
on each element of of A
over the given dims
, with the mn
and mn
initialized by the respective arguments of the 2-tuple init
, which can be any combination of values (<:Number
) or functions which accept a single type argument. Threaded.
Warning
NaN
values are not handled!
Examples
julia> A = reshape(Vector(1:2:16), (2,2,2))
2×2×2 Array{Int64, 3}:
[:, :, 1] =
1 5
3 7
[:, :, 2] =
9 13
11 15
julia> vtextrema(abs2, A, dims=(1,2), init=(typemax, 100))
1×1×2 Array{Tuple{Int64, Int64}, 3}:
[:, :, 1] =
(1, 100)
[:, :, 2] =
(81, 225)
julia> vtextrema(abs2, A, init=(typemax, 100))
(1, 225)
VectorizedReduction.vtfindmax
— Methodvtfindmax(A::AbstractArray, dims=:) -> (x, index)
Return the maximal element and its index over the dimensions dims
. Threaded.
VectorizedReduction.vtfindmax
— Methodvtfindmax(f, A; dims) -> (f(x), index)
vtfindmax(A; dims) -> (x, index)
Identical to non-keywords args version; slightly less performant due to use of kwargs. Threaded.
VectorizedReduction.vtfindmax
— Methodvtfindmax(f, A::AbstractArray, dims=:) -> (f(x), index)
Return the value and the index of the argument which maximizes f
over the dimensions dims
, which may be ::Int
, ::NTuple{M, Int} where {M}
or ::Colon
. Threaded.
See also: vfindmax
Warning
NaN
values are not handled!
VectorizedReduction.vtfindmax
— Methodvtfindmax(f, As::Vararg{AbstractArray, N}; dims=:) where {N} -> (f(x,y,z,...), index)
Return the value and index of the arguments which maximize f
: ℝᴺ → ℝ over the dimensions dims
. Threaded.
VectorizedReduction.vtfindmin
— Methodvtfindmin(A::AbstractArray, dims=:) -> (x, index)
Return the minimal element and its index over the dimensions dims
. Threaded.
VectorizedReduction.vtfindmin
— Methodvtfindmin(f, A; dims) -> (f(x), index)
vtfindmin(A; dims) -> (x, index)
Identical to non-keywords args version; slightly less performant due to use of kwargs. Threaded.
VectorizedReduction.vtfindmin
— Methodvtfindmin(f, A::AbstractArray, dims=:) -> (f(x), index)
Return the value and the index of the argument which minimizes f
over the dimensions dims
, which may be ::Int
, ::NTuple{M, Int} where {M}
or ::Colon
. Threaded.
See also: vfindmin
Warning
NaN
values are not handled!
VectorizedReduction.vtfindmin
— Methodvtfindmin(f, As::Vararg{AbstractArray, N}; dims=:) where {N} -> (f(x,y,z,...), index)
Return the value and index of the arguments which minimize f
: ℝᴺ → ℝ over the dimensions dims
. Threaded.
VectorizedReduction.vtlogsoftmax
— Methodvtlogsoftmax(A::AbstractArray; dims=:)
Identical to non-keyword args version; slightly less performant due to use of kwargs. Threaded.
VectorizedReduction.vtlogsoftmax
— Methodvtlogsoftmax(A::AbstractArray, dims)
Compute the log of the softmax function, treating each slice of A
specified by dims
as if it were a single vector; dims
may be ::Int
, ::NTuple{M, Int} where {M}
or ::Colon
. Threaded. Avoids overflow/underflow, but +Inf
and NaN
are not handled.
VectorizedReduction.vtlogsoftmax
— Methodvtlogsoftmax(A::AbstractArray)
Compute the log of the softmax function, treating the entire array as a single vector. Threaded. Care is taken to ensure that the computation will not overflow/underflow, but the caller should be aware that +Inf
and NaN
are not handled.
See also: vtsoftmax
VectorizedReduction.vtlogsumexp
— Methodvtlogsumexp(A::AbstractArray)
Compute the log of the sum of exponentials of each element of A
. Threaded. Care is taken to ensure that the computation will not overflow/underflow, but the caller should be aware that +Inf
and NaN
are not handled.
VectorizedReduction.vtlogsumexp
— Methodvtlogsumexp(A::AbstractArray; dims=:)
Identical to non-keyword args version; slightly less performant due to use of kwargs. Threaded.
VectorizedReduction.vtlogsumexp
— Methodvtlogsumexp(A::AbstractArray, dims)
Compute the log of the sum of exponentials of each element of A
along the dimensions dims
, which may be ::Int
, ::NTuple{M, Int} where {M}
or ::Colon
. Threaded. Avoids overflow/underflow, but +Inf
and NaN
are not handled.
VectorizedReduction.vtmanhattan
— Methodvtmanhattan(x::AbstractArray, y::AbstractArray; dims=:)
Compute the Manhattan distance between the vectors corresponding to the slices along the dimensions dims
. Threaded.
See also: vteuclidean
, vtchebyshev
, vtminkowski
VectorizedReduction.vtmapreduce
— Methodvtmapreduce(f, op, A; dims=:, init)
Identical to non-keyword args version; slightly less performant due to use of kwargs. Threaded.
VectorizedReduction.vtmapreduce
— Methodvtmapreduce(f, op, init, A::AbstractArray, dims=:)
Apply function f
to each element of A
, then reduce the result over the dimensions dims
using the binary function op
. Threaded. See vvmapreduce
for description of dims
. init
need not be provided when op
is one of +
, *
, min
, max
.
VectorizedReduction.vtmapreduce
— Methodvtmapreduce(f, op, init, As::Vararg{AbstractArray, N}; dims=:, init) where {N}
Version for f
: ℝᴺ → ℝ, with reduction over dims
. Threaded.
VectorizedReduction.vtmapreduce
— Methodvtmapreduce(f, op, init, As::Tuple{Vararg{AbstractArray}}, dims=:)
Version for f
: ℝᴺ → ℝ, with reduction over dims
. Threaded.
VectorizedReduction.vtmapreducethen
— Methodvtmapreducethen(f, op, g, A::AbstractArray; dims=:, init)
Apply function f
to each element of A
, reduce the result over the dimensions dims
using the binary function op
, then apply g
to the result. Equivalent to g.(mapreduce(f, op, A, dims=dims, init=init))
but avoids the intermediate implied by said expression while also fusing the post-transform g
such that the output array is populated in a single pass. Threaded.
The reduction necessitates an initial value init
which may be <:Number
or a function which accepts a single type argument (e.g. zero
); init
is optional for binary operators +
, *
, min
, and max
.
Examples
julia> vtmapreducethen(abs2, +, √, [1 2; 3 4], dims=1) # L₂-norm; see `vnorm`
1×2 Matrix{Float64}:
3.16228 4.47214
julia> vtmapreducethen(abs2, +, √, [1 2; 3 4], dims=2, init=1000.0)
2×1 Matrix{Float64}:
31.701734968294716
32.01562118716424
julia> vtmapreducethen(exp, +, log, [5 6; 7 8], dims=1) # LSE, but recommend `vlogsumexp`
1×2 Matrix{Float64}:
7.12693 8.12693
VectorizedReduction.vtmapreducethen
— Methodvtmapreducethen(f, op, g, As::Vararg{AbstractArray, N}; dims=:, init) where {N}
Keyword args version for f
: ℝᴺ → ℝ, then g
: ℝ → ℝ.
VectorizedReduction.vtmapreducethen
— Methodvtmapreducethen(f, op, g, init, As::Vararg{AbstractArray, N}) where {N}
Version of mapreducethen
for f
: ℝᴺ → ℝ, then g
: ℝ → ℝ, with reduction occurring over all dimensions.
VectorizedReduction.vtmapreducethen
— Methodvtmapreducethen(f, op, g, init, As::Tuple{Vararg{AbstractArray}}, dims=:)
Version of mapreducethen
for f
: ℝᴺ → ℝ, then g
: ℝ → ℝ, with reduction over given dims
.
VectorizedReduction.vtmaxad
— Methodvtmaxad(x::AbstractArray, y::AbstractArray; dims=:)
Compute the maximum absolute deviation between the vectors corresponding to the slices along the dimension dims
. Threaded.
See also: vtmeanad
VectorizedReduction.vtmaximum
— Methodvtmaximum(A::AbstractArray, dims=:)
Compute the maximum value of A
over the given dims
.
VectorizedReduction.vtmaximum
— Methodvtmaximum(f, A; dims=:, init=typemin)
Compute the maximum value of calling f
on each element of A
over the given dims
, with the max initialized by init
, which may be a value <:Number
or a function which accepts a single type argument.
VectorizedReduction.vtmaximum
— Methodvtmaximum(A; dims=:, init=typemin)
Compute the maximum value of A
over the given dims
, with the max initialized by init
.
VectorizedReduction.vtmaximum
— Methodvtmaximum(f, A::AbstractArray, dims=:)
Compute the maximum value by calling f
on each element of A
over the given dims
.
Warning
NaN
values are not handled!
VectorizedReduction.vtmeanad
— Methodvtmeanad(x::AbstractArray, y::AbstractArray; dims=:)
Compute the mean absolute deviation between the vectors corresponding to the slices along the dimension dims
. Threaded.
See also: vtmaxad
VectorizedReduction.vtminimum
— Methodvtminimum(A::AbstractArray, dims=:)
Compute the minimum value of A
over the given dims
.
VectorizedReduction.vtminimum
— Methodvtminimum(f, A; dims=:, init=typemax)
Compute the minimum value of calling f
on each element of A
over the given dims
, with the min initialized by init
, which may be a value <:Number
or a function which accepts a single type argument.
VectorizedReduction.vtminimum
— Methodvtminimum(A; dims=:, init=typemax)
Compute the minimum value of A
over the given dims
, with the min initialized by init
.
VectorizedReduction.vtminimum
— Methodvtminimum(f, A::AbstractArray, dims=:)
Compute the minimum value by calling f
on each element of A
over the given dims
.
Warning
NaN
values are not handled!
VectorizedReduction.vtminkowski
— Methodvtminkowski(x::AbstractArray, y::AbstractArray, p::Real; dims=:)
Compute the Minkowski distance between the vectors corresponding to the slices along the dimensions dims
. Threaded.
p
can assume any numeric value (even though not all values produce a mathematically valid vector norm). vtminkowski(x, y, Inf)
returns the largest value in abs.(x .- y)
, whereas vtminkowski(x, y, -Inf)
returns the smallest.
See also: vtmanhattan
, vteuclidean
, vtchebyshev
VectorizedReduction.vtmse
— Methodvtmse(x::AbstractArray, y::AbstractArray; dims=:)
Compute the mean squared error between the vectors corresponding to the slices along the dimension dims
. Threaded.
See also: vtrmse
VectorizedReduction.vtnorm
— Functionvtnorm(A::AbstractArray, p::Real=2; dims=:)
Compute the p
-norm of A
along the dimensions dims
as if the corresponding slices were vectors. Threaded.
p
can assume any numeric value (even though not all values produce a mathematically valid vector norm). vtnorm(A, Inf)
returns the largest value in abs.(A)
, whereas vtnorm(A, -Inf)
returns the smallest; vnorm(A, 0)
matches the behavior of LinearAlgebra.norm(A, 0)
.
See also: vnorm
VectorizedReduction.vtprod
— Methodvtprod(A::AbstractArray, dims=:)
Multiply the elements of A
over the given dims
.
VectorizedReduction.vtprod
— Methodvtprod(f, A; dims=:, init=one)
Multiply the results of calling f
on each element of A
over the given dims
, with the product initialized by init
, which may be a value <:Number
or a function which accepts a single type argument.
VectorizedReduction.vtprod
— Methodvtprod(A; dims=:, init=one)
Multiply the elements of A
over the given dims
, with the product initialized by init
.
VectorizedReduction.vtprod
— Methodvtprod(f, A::AbstractArray, dims=:)
Multiply the results of calling f
on each element of A
over the given dims
.
VectorizedReduction.vtreduce
— Methodvtreduce(op, A; dims=:, init)
Identical to non-keyword args version; slightly less performant due to use of kwargs. Threaded.
VectorizedReduction.vtreduce
— Methodvtreduce(op, init, A::AbstractArray, dims=:)
Reduce A
over the dimensions dims
using the binary function op
. See vtmapreduce
for description of op
, init
, dims
.
VectorizedReduction.vtrmse
— Methodvtrmse(x::AbstractArray, y::AbstractArray; dims=:)
Compute the square root of the mean squared error between the vectors corresponding to the slices along the dimension dims
. More efficient than sqrt.(vmse(...))
as the sqrt
operation is performed at the point of generation, thereby eliminating the full traversal which would otherwise occur. Threaded.
See also: vtmse
VectorizedReduction.vtsoftmax
— Methodvtsoftmax(A::AbstractArray)
Compute the softmax function, treating the entire array as a single vector. Threaded. Care is taken to ensure that the computation will not overflow/underflow, but the caller should be aware that +Inf
and NaN
are not handled.
See also: vtlogsoftmax
VectorizedReduction.vtsoftmax
— Methodvtsoftmax(A::AbstractArray; dims=:)
Identical to non-keyword args version; slightly less performant due to use of kwargs. Threaded.
VectorizedReduction.vtsoftmax
— Methodvtsoftmax(A::AbstractArray, dims)
Compute the softmax function, treating each slice of A
specified by dims
as if it were a single vector; dims
may be ::Int
, ::NTuple{M, Int} where {M}
or ::Colon
. Threaded. Avoids overflow/underflow, but +Inf
and NaN
are not handled.
VectorizedReduction.vtsum
— Methodvtsum(A::AbstractArray, dims=:)
Sum the elements of A
over the given dims
.
VectorizedReduction.vtsum
— Methodvtsum(f, A; dims=:, init=zero)
Sum the results of calling f
on each element of A
over the given dims
, with the sum initialized by init
, which may be a value <:Number
or a function which accepts a single type argument.
VectorizedReduction.vtsum
— Methodvtsum(A; dims=:, init=zero)
Sum the elements of A
over the given dims
, with the sum initialized by init
.
VectorizedReduction.vtsum
— Methodvtsum(f, A::AbstractArray, dims=:)
Sum the results of calling f
on each element of A
over the given dims
.
VectorizedReduction.vvextrema
— Methodvvextrema([f=identity], A::AbstractArray, dims=:)
Compute the minimum and maximum values by calling f
on each element of of A
over the given dims
.
VectorizedReduction.vvextrema
— Methodvvextrema([f=identity], A::AbstractArray; [dims=:], [init=(mn,mx)])
Compute the minimum and maximum values by calling f
on each element of of A
over the given dims
, with the mn
and mx
initialized by the respective arguments of the 2-tuple init
, which can be any combination of values (<:Number
) or functions which accept a single type argument.
Warning
NaN
values are not handled!
Examples
julia> A = reshape(Vector(1:2:16), (2,2,2))
2×2×2 Array{Int64, 3}:
[:, :, 1] =
1 5
3 7
[:, :, 2] =
9 13
11 15
julia> vvextrema(abs2, A, dims=(1,2), init=(typemax, 100))
1×1×2 Array{Tuple{Int64, Int64}, 3}:
[:, :, 1] =
(1, 100)
[:, :, 2] =
(81, 225)
julia> vvextrema(abs2, A, init=(typemax, 100))
(1, 225)
VectorizedReduction.vvmapreduce
— Methodvvmapreduce(f, op, A; dims=:, init)
Identical to non-keyword args version; slightly less performant due to use of kwargs.
VectorizedReduction.vvmapreduce
— Methodvvmapreduce(f, op, init, A::AbstractArray, dims=:)
Apply function f
to each element of A
, then reduce the result over the dimensions dims
using the binary function op
. The reduction necessitates an initial value init
which may be <:Number
or a function which accepts a single type argument (e.g. zero
); init
is optional for binary operators +
, *
, min
, and max
. dims
may be ::Int
, ::NTuple{M, Int} where {M}
or ::Colon
.
VectorizedReduction.vvmapreduce
— Methodvvmapreduce(f, op, As::Vararg{AbstractArray, N}; dims=:, init) where {N}
Keyword args version for f
: ℝᴺ → ℝ.
VectorizedReduction.vvmapreduce
— Methodvvmapreduce(f, op, init, As::Vararg{AbstractArray, N}) where {N}
Version of mapreduce for f
: ℝᴺ → ℝ, with reduction occurring over all dimensions.
VectorizedReduction.vvmapreduce
— Methodvvmapreduce(f, op, init, As::Tuple{Vararg{AbstractArray}}, dims=:)
Version of mapreduce for f
: ℝᴺ → ℝ, with reduction over given dims
.
VectorizedReduction.vvmaximum
— Methodvvmaximum(A::AbstractArray, dims=:)
Compute the maximum value of A
over the given dims
.
VectorizedReduction.vvmaximum
— Methodvvmaximum(f, A; dims=:, init=typemin)
Compute the maximum value of calling f
on each element of A
over the given dims
, with the max initialized by init
, which may be a value <:Number
or a function which accepts a single type argument.
VectorizedReduction.vvmaximum
— Methodvvmaximum(A; dims=:, init=typemin)
Compute the maximum value of A
over the given dims
, with the max initialized by init
.
VectorizedReduction.vvmaximum
— Methodvvmaximum(f, A::AbstractArray, dims=:)
Compute the maximum value by calling f
on each element of A
over the given dims
.
Warning
NaN
values are not handled!
VectorizedReduction.vvminimum
— Methodvvminimum(A::AbstractArray, dims=:)
Compute the minimum value of A
over the given dims
.
VectorizedReduction.vvminimum
— Methodvvminimum(f, A; dims=:, init=typemax)
Compute the minimum value of calling f
on each element of A
over the given dims
, with the min initialized by init
, which may be a value <:Number
or a function which accepts a single type argument.
VectorizedReduction.vvminimum
— Methodvvminimum(A; dims=:, init=typemax)
Compute the minimum value of A
over the given dims
, with the min initialized by init
.
VectorizedReduction.vvminimum
— Methodvvminimum(f, A::AbstractArray, dims=:)
Compute the minimum value by calling f
on each element of A
over the given dims
.
Warning
NaN
values are not handled!
VectorizedReduction.vvprod
— Methodvvprod(A::AbstractArray, dims=:)
Multiply the elements of A
over the given dims
.
VectorizedReduction.vvprod
— Methodvvprod(f, A; dims=:, init=one)
Multiply the results of calling f
on each element of A
over the given dims
, with the product initialized by init
, which may be a value <:Number
or a function which accepts a single type argument.
VectorizedReduction.vvprod
— Methodvvprod(A; dims=:, init=one)
Multiply the elements of A
over the given dims
, with the product initialized by init
.
VectorizedReduction.vvprod
— Methodvvprod(f, A::AbstractArray, dims=:)
Multiply the results of calling f
on each element of A
over the given dims
.
VectorizedReduction.vvreduce
— Methodvvreduce(op, A; dims=:, init)
Identical to non-keyword args version; slightly less performant due to use of kwargs.
VectorizedReduction.vvreduce
— Methodvvreduce(op, init, A::AbstractArray, dims=:)
Reduce A
over the dimensions dims
using the binary function op
. See vvmapreduce
for description of op
, init
, dims
.
VectorizedReduction.vvsum
— Methodvvsum(A::AbstractArray, dims=:)
Sum the elements of A
over the given dims
.
VectorizedReduction.vvsum
— Methodvvsum(f, A; dims=:, init=zero)
Sum the results of calling f
on each element of A
over the given dims
, with the sum initialized by init
, which may be a value <:Number
or a function which accepts a single type argument.
VectorizedReduction.vvsum
— Methodvvsum(A; dims=:, init=zero)
Sum the elements of A
over the given dims
, with the sum initialized by init
.
VectorizedReduction.vvsum
— Methodvvsum(f, A::AbstractArray, dims=:)
Sum the results of calling f
on each element of A
over the given dims
.
Index
VectorizedReduction.vall
VectorizedReduction.vall
VectorizedReduction.vany
VectorizedReduction.vany
VectorizedReduction.vargmax
VectorizedReduction.vargmax
VectorizedReduction.vargmax
VectorizedReduction.vargmax
VectorizedReduction.vargmin
VectorizedReduction.vargmin
VectorizedReduction.vargmin
VectorizedReduction.vargmin
VectorizedReduction.vchebyshev
VectorizedReduction.vcount
VectorizedReduction.vcount
VectorizedReduction.vcounteq
VectorizedReduction.vcountne
VectorizedReduction.veuclidean
VectorizedReduction.vfindmax
VectorizedReduction.vfindmax
VectorizedReduction.vfindmax
VectorizedReduction.vfindmax
VectorizedReduction.vfindmin
VectorizedReduction.vfindmin
VectorizedReduction.vfindmin
VectorizedReduction.vfindmin
VectorizedReduction.vlogsoftmax
VectorizedReduction.vlogsoftmax
VectorizedReduction.vlogsoftmax
VectorizedReduction.vlogsumexp
VectorizedReduction.vlogsumexp
VectorizedReduction.vlogsumexp
VectorizedReduction.vmanhattan
VectorizedReduction.vmapreducethen
VectorizedReduction.vmapreducethen
VectorizedReduction.vmaxad
VectorizedReduction.vmeanad
VectorizedReduction.vminkowski
VectorizedReduction.vmse
VectorizedReduction.vnorm
VectorizedReduction.vrmse
VectorizedReduction.vsoftmax
VectorizedReduction.vsoftmax
VectorizedReduction.vsoftmax
VectorizedReduction.vtall
VectorizedReduction.vtall
VectorizedReduction.vtany
VectorizedReduction.vtany
VectorizedReduction.vtargmax
VectorizedReduction.vtargmax
VectorizedReduction.vtargmax
VectorizedReduction.vtargmax
VectorizedReduction.vtargmin
VectorizedReduction.vtargmin
VectorizedReduction.vtargmin
VectorizedReduction.vtargmin
VectorizedReduction.vtchebyshev
VectorizedReduction.vtcount
VectorizedReduction.vtcount
VectorizedReduction.vtcounteq
VectorizedReduction.vtcountne
VectorizedReduction.vteuclidean
VectorizedReduction.vtextrema
VectorizedReduction.vtextrema
VectorizedReduction.vtfindmax
VectorizedReduction.vtfindmax
VectorizedReduction.vtfindmax
VectorizedReduction.vtfindmax
VectorizedReduction.vtfindmin
VectorizedReduction.vtfindmin
VectorizedReduction.vtfindmin
VectorizedReduction.vtfindmin
VectorizedReduction.vtlogsoftmax
VectorizedReduction.vtlogsoftmax
VectorizedReduction.vtlogsoftmax
VectorizedReduction.vtlogsumexp
VectorizedReduction.vtlogsumexp
VectorizedReduction.vtlogsumexp
VectorizedReduction.vtmanhattan
VectorizedReduction.vtmapreduce
VectorizedReduction.vtmapreduce
VectorizedReduction.vtmapreduce
VectorizedReduction.vtmapreduce
VectorizedReduction.vtmapreducethen
VectorizedReduction.vtmapreducethen
VectorizedReduction.vtmapreducethen
VectorizedReduction.vtmapreducethen
VectorizedReduction.vtmaxad
VectorizedReduction.vtmaximum
VectorizedReduction.vtmaximum
VectorizedReduction.vtmaximum
VectorizedReduction.vtmaximum
VectorizedReduction.vtmeanad
VectorizedReduction.vtminimum
VectorizedReduction.vtminimum
VectorizedReduction.vtminimum
VectorizedReduction.vtminimum
VectorizedReduction.vtminkowski
VectorizedReduction.vtmse
VectorizedReduction.vtnorm
VectorizedReduction.vtprod
VectorizedReduction.vtprod
VectorizedReduction.vtprod
VectorizedReduction.vtprod
VectorizedReduction.vtreduce
VectorizedReduction.vtreduce
VectorizedReduction.vtrmse
VectorizedReduction.vtsoftmax
VectorizedReduction.vtsoftmax
VectorizedReduction.vtsoftmax
VectorizedReduction.vtsum
VectorizedReduction.vtsum
VectorizedReduction.vtsum
VectorizedReduction.vtsum
VectorizedReduction.vvextrema
VectorizedReduction.vvextrema
VectorizedReduction.vvmapreduce
VectorizedReduction.vvmapreduce
VectorizedReduction.vvmapreduce
VectorizedReduction.vvmapreduce
VectorizedReduction.vvmapreduce
VectorizedReduction.vvmaximum
VectorizedReduction.vvmaximum
VectorizedReduction.vvmaximum
VectorizedReduction.vvmaximum
VectorizedReduction.vvminimum
VectorizedReduction.vvminimum
VectorizedReduction.vvminimum
VectorizedReduction.vvminimum
VectorizedReduction.vvprod
VectorizedReduction.vvprod
VectorizedReduction.vvprod
VectorizedReduction.vvprod
VectorizedReduction.vvreduce
VectorizedReduction.vvreduce
VectorizedReduction.vvsum
VectorizedReduction.vvsum
VectorizedReduction.vvsum
VectorizedReduction.vvsum