5
5
#
6
6
# ###########################################################################################
7
7
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
+ """
8
15
function vcount (f:: F , A:: AbstractArray{T, N} , dims:: NTuple{M, Int} ) where {F, T, N, M}
9
16
Dᴬ = size (A)
10
17
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)
25
32
vcount (A:: AbstractArray{Bool, N} ) where {N} = vcount (identity, A)
26
33
27
34
# 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
+ """
28
40
vcount (f, A; dims= :) = vcount (f, A, dims)
29
41
vcount (A; dims= :) = vcount (A, dims)
30
42
@@ -49,6 +61,19 @@ vcount(A; dims=:) = vcount(A, dims)
49
61
# Unfortunately, this results in worse performance than just calling
50
62
# `any` from Julia Base. It would probably be faster to do vcount
51
63
# 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
+ """
52
77
function vany (f:: F , A:: AbstractArray{T, N} , dims:: NTuple{M, Int} ) where {F, T, N, M}
53
78
Dᴬ = size (A)
54
79
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
57
82
return B
58
83
end
59
84
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
+ """
60
99
function vall (f:: F , A:: AbstractArray{T, N} , dims:: NTuple{M, Int} ) where {F, T, N, M}
61
100
Dᴬ = size (A)
62
101
Dᴮ′ = ntuple (d -> d ∈ dims ? 1 : Dᴬ[d], Val (N))
@@ -70,9 +109,20 @@ vany(A::AbstractArray, dims) = vany(identity, A, dims)
70
109
vall (A:: AbstractArray , dims) = vall (identity, A, dims)
71
110
72
111
# 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
+ """
73
117
vany (f, A; dims= :) = vany (f, A, dims)
74
- vall (f, A; dims= :) = vall (f, A, dims)
75
118
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)
76
126
vall (A; dims= :) = vall (identity, A, dims)
77
127
78
128
# Realistically, I would not recommend these, as they
@@ -82,7 +132,7 @@ vall(A; dims=:) = vall(identity, A, dims)
82
132
# to be checked in order to exit. If one suspects that the any/all
83
133
# is likely to short-circuit, then I recommend against vany/vall.
84
134
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
86
136
# ξ = false
87
137
# @turbo for i ∈ eachindex(A)
88
138
# ξ |= f(A[i])
@@ -129,6 +179,13 @@ vfindall(f::F, A::AbstractVector{T}) where {F, T} = LinearIndices(A)[vmask(f, A)
129
179
130
180
# ###########################################################################################
131
181
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
+ """
132
189
function vtcount (f:: F , A:: AbstractArray{T, N} , dims:: NTuple{M, Int} ) where {F, T, N, M}
133
190
Dᴬ = size (A)
134
191
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)
149
206
vtcount (A:: AbstractArray{Bool, N} ) where {N} = vtcount (identity, A)
150
207
151
208
# 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
+ """
152
214
vtcount (f, A; dims= :) = vtcount (f, A, dims)
153
215
vtcount (A; dims= :) = vtcount (A, dims)
154
216
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
+ """
155
230
function vtany (f:: F , A:: AbstractArray{T, N} , dims:: NTuple{M, Int} ) where {F, T, N, M}
156
231
Dᴬ = size (A)
157
232
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,
160
235
return B
161
236
end
162
237
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
+ """
163
252
function vtall (f:: F , A:: AbstractArray{T, N} , dims:: NTuple{M, Int} ) where {F, T, N, M}
164
253
Dᴬ = size (A)
165
254
Dᴮ′ = ntuple (d -> d ∈ dims ? 1 : Dᴬ[d], Val (N))
@@ -173,9 +262,20 @@ vtany(A::AbstractArray, dims) = vtany(identity, A, dims)
173
262
vtall (A:: AbstractArray , dims) = vtall (identity, A, dims)
174
263
175
264
# 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
+ """
176
270
vtany (f, A; dims= :) = vtany (f, A, dims)
177
- vtall (f, A; dims= :) = vtall (f, A, dims)
178
271
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)
179
279
vtall (A; dims= :) = vtall (identity, A, dims)
180
280
181
281
function vtany (f:: F , A:: AbstractArray{T, N} , :: Colon ) where {F, T, N}
0 commit comments