Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/higherorderfns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1349,8 +1349,12 @@ end
function _densenonzero(bc::Broadcasted, f::F, args::Vararg{Any,N}) where {F,N}
T = Base.promote_typejoin_union(Base.promote_op(f, map(eltype, args)...))
(isconcretetype(T) && T !== Bool) || return _densebroadcast(bc)
return _storedasdense(_copy(f, map(_sparsifystructured, args)...))
As = map(_sparsifystructured, args)
# the kernels store every entry, which the index type of the arguments may not address
_addresses(_promote_indtype(As...), map(length, axes(bc))) || return _densebroadcast(bc)
return _storedasdense(_copy(f, As...))
end
_addresses(::Type{Ti}, shape) where {Ti} = !(Ti <: Base.BitInteger) || prod(Int64, shape) < typemax(Ti)
_storedasdense(C::Union{SparseVector,SparseMatrixCSC}) =
length(getnzval(C)) == nnz(C) == length(C) ? reshape(getnzval(C), size(C)) : Array(C)
_storedasdense(C) = Array(C)
Expand Down
3 changes: 3 additions & 0 deletions test/higherorderfns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,9 @@ end
B = sparse(BigFloat[1 0; 0 2])
@test @inferred(broadcast(*, B, B))::SparseMatrixCSC == Array(B) .* Array(B)
@test cos.(B)::Matrix{BigFloat} == cos.(Array(B))
# an index type that cannot address every entry of the dense result
S8 = sparse(Int8[1], Int8[1], [1.0], 12, 12)
@test cos.(S8)::Matrix{Float64} == cos.(Array(S8))
# a function that throws at zero is left to the sparse kernels: only a matrix with a
# structural zero evaluates it there
shifted(x) = sqrt(x - 1)
Expand Down
Loading