Skip to content

Commit b0474ec

Browse files
Docstrings for vboolean
1 parent d087b60 commit b0474ec

File tree

1 file changed

+103
-3
lines changed

1 file changed

+103
-3
lines changed

src/vboolean.jl

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
#
66
############################################################################################
77

8+
"""
9+
vcount([f=identity,] A::AbstractArray, dims=:)
10+
11+
Count the number of elements in `A` for which `f` return true over the given `dims`.
12+
If `f` is omitted, count the number of `true` elements in `A`
13+
(which should be `AbstractArray{Bool}`).
14+
"""
815
function vcount(f::F, A::AbstractArray{T, N}, dims::NTuple{M, Int}) where {F, T, N, M}
916
Dᴬ = size(A)
1017
Dᴮ′ = ntuple(d -> d dims ? 1 : Dᴬ[d], Val(N))
@@ -25,6 +32,11 @@ vcount(A::AbstractArray{Bool, N}, dims) where {N} = vcount(identity, A, dims)
2532
vcount(A::AbstractArray{Bool, N}) where {N} = vcount(identity, A)
2633

2734
# kwargs interface
35+
"""
36+
vcount([f=identity,] A::AbstractArray; dims=:)
37+
38+
Identical to non-keyword args version; slightly less performant due to use of kwargs.
39+
"""
2840
vcount(f, A; dims=:) = vcount(f, A, dims)
2941
vcount(A; dims=:) = vcount(A, dims)
3042

@@ -49,6 +61,19 @@ vcount(A; dims=:) = vcount(A, dims)
4961
# Unfortunately, this results in worse performance than just calling
5062
# `any` from Julia Base. It would probably be faster to do vcount
5163
# and then compare...
64+
"""
65+
vany([p=identity,] A::AbstractArray, dims=:)
66+
67+
Determine whether predicate `p` returns true for any elements over the given `dims`.
68+
If `p` is omitted, test whether any values along the given `dims` are `true`
69+
(in which case `A` should be `AbstractArray{Bool}`).
70+
71+
# Additional Notes
72+
This function suffers from the same issue as `vfindmax` and friends -- reductions
73+
which include the first dimension with zero masks are not yet supported by LoopVectorization.
74+
Notably, this function still works as intended for any reduction which does not involve
75+
the first dimension.
76+
"""
5277
function vany(f::F, A::AbstractArray{T, N}, dims::NTuple{M, Int}) where {F, T, N, M}
5378
Dᴬ = size(A)
5479
Dᴮ′ = ntuple(d -> d dims ? 1 : Dᴬ[d], Val(N))
@@ -57,6 +82,20 @@ function vany(f::F, A::AbstractArray{T, N}, dims::NTuple{M, Int}) where {F, T, N
5782
return B
5883
end
5984
vany(f, A, dims::Int) = vany(f, A, (dims,))
85+
86+
"""
87+
vall([p=identity,] A::AbstractArray, dims=:)
88+
89+
Determine whether predicate `p` returns true for all elements over the given `dims`.
90+
If `p` is omitted, test whether all values along the given `dims` are `true`
91+
(in which case `A` should be `AbstractArray{Bool}`).
92+
93+
# Additional Notes
94+
This function suffers from the same issue as `vfindmax` and friends -- reductions
95+
which include the first dimension with max masks are not yet supported by LoopVectorization.
96+
Notably, this function still works as intended for any reduction which does not involve
97+
the first dimension.
98+
"""
6099
function vall(f::F, A::AbstractArray{T, N}, dims::NTuple{M, Int}) where {F, T, N, M}
61100
Dᴬ = size(A)
62101
Dᴮ′ = ntuple(d -> d dims ? 1 : Dᴬ[d], Val(N))
@@ -70,9 +109,20 @@ vany(A::AbstractArray, dims) = vany(identity, A, dims)
70109
vall(A::AbstractArray, dims) = vall(identity, A, dims)
71110

72111
# kwargs interface
112+
"""
113+
vany([p=identity,] A::AbstractArray; dims=:)
114+
115+
Identical to non-keyword args version; slightly less performant due to use of kwargs.
116+
"""
73117
vany(f, A; dims=:) = vany(f, A, dims)
74-
vall(f, A; dims=:) = vall(f, A, dims)
75118
vany(A; dims=:) = vany(identity, A, dims)
119+
120+
"""
121+
vall([p=identity,] A::AbstractArray; dims=:)
122+
123+
Identical to non-keyword args version; slightly less performant due to use of kwargs.
124+
"""
125+
vall(f, A; dims=:) = vall(f, A, dims)
76126
vall(A; dims=:) = vall(identity, A, dims)
77127

78128
# Realistically, I would not recommend these, as they
@@ -82,7 +132,7 @@ vall(A; dims=:) = vall(identity, A, dims)
82132
# to be checked in order to exit. If one suspects that the any/all
83133
# is likely to short-circuit, then I recommend against vany/vall.
84134
function vany(f::F, A::AbstractArray{T, N}, ::Colon) where {F, T, N}
85-
# # The proper implementation, but, alas, zero_mask problems in LoopVectorization
135+
# The proper implementation, but, alas, zero_mask problems in LoopVectorization
86136
# ξ = false
87137
# @turbo for i ∈ eachindex(A)
88138
# ξ |= f(A[i])
@@ -129,6 +179,13 @@ vfindall(f::F, A::AbstractVector{T}) where {F, T} = LinearIndices(A)[vmask(f, A)
129179

130180
############################################################################################
131181

182+
"""
183+
vtcount([f=identity,] A::AbstractArray, dims=:)
184+
185+
Count the number of elements in `A` for which `f` return true over the given `dims`.
186+
If `f` is omitted, count the number of `true` elements in `A`
187+
(which should be `AbstractArray{Bool}`). Threaded.
188+
"""
132189
function vtcount(f::F, A::AbstractArray{T, N}, dims::NTuple{M, Int}) where {F, T, N, M}
133190
Dᴬ = size(A)
134191
Dᴮ′ = ntuple(d -> d dims ? 1 : Dᴬ[d], Val(N))
@@ -149,9 +206,27 @@ vtcount(A::AbstractArray{Bool, N}, dims) where {N} = vtcount(identity, A, dims)
149206
vtcount(A::AbstractArray{Bool, N}) where {N} = vtcount(identity, A)
150207

151208
# kwargs interface
209+
"""
210+
vtcount([f=identity,] A::AbstractArray; dims=:)
211+
212+
Identical to non-keyword args version; slightly less performant due to use of kwargs. Threaded.
213+
"""
152214
vtcount(f, A; dims=:) = vtcount(f, A, dims)
153215
vtcount(A; dims=:) = vtcount(A, dims)
154216

217+
"""
218+
vtany([p=identity,] A::AbstractArray, dims=:)
219+
220+
Determine whether predicate `p` returns true for any elements over the given `dims`.
221+
If `p` is omitted, test whether any values along the given `dims` are `true`
222+
(in which case `A` should be `AbstractArray{Bool}`). Threaded.
223+
224+
# Additional Notes
225+
This function suffers from the same issue as `vfindmax` and friends -- reductions
226+
which include the first dimension with zero masks are not yet supported by LoopVectorization.
227+
Notably, this function still works as intended for any reduction which does not involve
228+
the first dimension.
229+
"""
155230
function vtany(f::F, A::AbstractArray{T, N}, dims::NTuple{M, Int}) where {F, T, N, M}
156231
Dᴬ = size(A)
157232
Dᴮ′ = ntuple(d -> d dims ? 1 : Dᴬ[d], Val(N))
@@ -160,6 +235,20 @@ function vtany(f::F, A::AbstractArray{T, N}, dims::NTuple{M, Int}) where {F, T,
160235
return B
161236
end
162237
vtany(f, A, dims::Int) = vtany(f, A, (dims,))
238+
239+
"""
240+
vtall([p=identity,] A::AbstractArray, dims=:)
241+
242+
Determine whether predicate `p` returns true for all elements over the given `dims`.
243+
If `p` is omitted, test whether all values along the given `dims` are `true`
244+
(in which case `A` should be `AbstractArray{Bool}`). Threaded.
245+
246+
# Additional Notes
247+
This function suffers from the same issue as `vfindmax` and friends -- reductions
248+
which include the first dimension with max masks are not yet supported by LoopVectorization.
249+
Notably, this function still works as intended for any reduction which does not involve
250+
the first dimension.
251+
"""
163252
function vtall(f::F, A::AbstractArray{T, N}, dims::NTuple{M, Int}) where {F, T, N, M}
164253
Dᴬ = size(A)
165254
Dᴮ′ = ntuple(d -> d dims ? 1 : Dᴬ[d], Val(N))
@@ -173,9 +262,20 @@ vtany(A::AbstractArray, dims) = vtany(identity, A, dims)
173262
vtall(A::AbstractArray, dims) = vtall(identity, A, dims)
174263

175264
# kwargs interface
265+
"""
266+
vtany([p=identity,] A::AbstractArray; dims=:)
267+
268+
Identical to non-keyword args version; slightly less performant due to use of kwargs.
269+
"""
176270
vtany(f, A; dims=:) = vtany(f, A, dims)
177-
vtall(f, A; dims=:) = vtall(f, A, dims)
178271
vtany(A; dims=:) = vtany(identity, A, dims)
272+
273+
"""
274+
vtall([p=identity,] A::AbstractArray; dims=:)
275+
276+
Identical to non-keyword args version; slightly less performant due to use of kwargs.
277+
"""
278+
vtall(f, A; dims=:) = vtall(f, A, dims)
179279
vtall(A; dims=:) = vtall(identity, A, dims)
180280

181281
function vtany(f::F, A::AbstractArray{T, N}, ::Colon) where {F, T, N}

0 commit comments

Comments
 (0)