Skip to content

Commit 7bba606

Browse files
committed
add docstring and error message
1 parent 922e608 commit 7bba606

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/MappedArrays.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,22 @@ eltypes(A::AbstractArray) = Tuple{eltype(A)}
264264

265265
# mapreduce
266266

267+
"""
268+
mappedarrayreduce(f, op, A::AbstractArray...; kw...)
269+
270+
Perform a "lazy" `mapreduce` without allocating an intermediate array. This may
271+
be more performant than a standard `mapreduce`. Functionally this is equivalent to
272+
`reduce(op, mappedarray(f, A); kw...)`.
273+
274+
# Examples
275+
```jldoctest
276+
julia> mappedarrayreduce(x -> x^2, +, 1:10) # == 1^2 + 2^2 + 3^2
277+
385
278+
```
279+
"""
267280
mappedarrayreduce(f, op, A::AbstractArray...; kw...) = reduce(op, mappedarray(f, A...); kw...)
281+
mappedarrayreduce(f, finv, op, A::AbstractArray...; kw...) = error(
282+
"mappedarrayreduce does not support an inverse function, "*
283+
"please use the signature mappedarrayreduce(f, op, A::AbstractArray...; kw...)")
268284

269285
end # module

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ end
188188
@test mapreduce(f, op, x, init = zero(T), dims = 1) == mappedarrayreduce(f, op, x, init = zero(T), dims = 1)
189189
@test mapreduce(f, op, x, init = zero(T), dims = :) == mappedarrayreduce(f, op, x, init = zero(T), dims = :)
190190

191+
@test_throws Exception mappedarrayreduce(x->x^2, sqrt, op, x)
192+
191193
if VERSION >= v"1.2"
192194
f = ==; op = +
193195
@test mapreduce(f, op, x, y) == mappedarrayreduce(f, op, x, y)

0 commit comments

Comments
 (0)