Skip to content

Commit

Permalink
any/all for Vcat
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty committed Apr 29, 2019
1 parent 4e717bd commit 7e941fd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/LazyArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import Base: AbstractArray, AbstractMatrix, AbstractVector,
ArithmeticWraps, floatrange, reverse, unitrange_last,
AbstractArray, AbstractVector, axes, (:), _sub2ind_recurse, broadcast, promote_eltypeof,
similar, @_gc_preserve_end, @_gc_preserve_begin,
@nexprs, @ncall, @ntuple
@nexprs, @ncall, @ntuple,
all, any

import Base.Broadcast: BroadcastStyle, AbstractArrayStyle, Broadcasted, broadcasted,
combine_eltypes, DefaultArrayStyle, instantiate, materialize,
Expand Down
8 changes: 4 additions & 4 deletions src/lazyconcat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,12 @@ _vcat_axes(a::Tuple{<:AbstractUnitRange}, b, c...) = tuple(first(a), broadcast((
_vcat_getindex_eval(y) = ()
_vcat_getindex_eval(y, a, b...) = tuple(y[a], _vcat_getindex_eval(y, b...)...)


function broadcasted(::LazyArrayStyle, op, A::Vcat{<:Any,1}, B::AbstractVector)
kr = _vcat_axes(axes.(A.arrays)...) # determine how to break up B
B_arrays = _vcat_getindex_eval(B,kr...) # evaluate B at same chunks as A
_Vcat(broadcast((a,b) -> broadcast(op,a,b), A.arrays, B_arrays))
end




function broadcasted(::LazyArrayStyle, op, A::AbstractVector, B::Vcat{<:Any,1})
kr = _vcat_axes(axes.(B.arrays)...)
A_arrays = _vcat_getindex_eval(A,kr...)
Expand Down Expand Up @@ -382,6 +378,10 @@ broadcasted(::LazyArrayStyle{1}, op, A::Vcat{T, 1, <:Tuple{<:Any,<:Any}},
####

sum(V::Vcat) = mapreduce(sum, +, V.arrays)
all(V::Vcat) = all(all.(V.arrays))
any(V::Vcat) = any(any.(V.arrays))
all(f::Function, V::Vcat) = all(all.(f, V.arrays))
any(f::Function, V::Vcat) = any(any.(f, V.arrays))

_dotplus(a,b) = broadcast(+, a, b)

Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ include("setoptests.jl")
B[1,3] = 2
@test B[1,3] == y[1,1] == 2
end

@testset "Any/All" begin
@test all(Vcat(true, Fill(true,100_000_000)))
@test any(Vcat(false, Fill(true,100_000_000)))
@test all(iseven, Vcat(2, Fill(4,100_000_000)))
@test any(iseven, Vcat(2, Fill(1,100_000_000)))
@test_throws TypeError all(Vcat(1))
@test_throws TypeError any(Vcat(1))
end
end


Expand Down

0 comments on commit 7e941fd

Please sign in to comment.