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
3 changes: 2 additions & 1 deletion src/SparseArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ function issparse(A::AbstractArray)
# Handle wrapper arrays: sparse if it is wrapping a sparse array.
# This gets compiled away during specialization.
p = parent(A)
if p === A
if p === A || !(p isa AbstractArray)
# have reached top of wrapping without finding a sparse array, assume it is not.
# The parent of an array need not be an array.
return false
else
return issparse(p)
Expand Down
10 changes: 9 additions & 1 deletion test/SparseTestHelpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module SparseTestHelpers
export COMPREHENSIVE, STD_ELTYPES, itypes, core_itypes, eachvalue, pairwise,
same_pattern, exact_equal, WrappedSparseVector, OpCount, mulcount, eqcount,
opcount_sparse, CountedReads, hasunionlocal, quaternion_type, SimpleSMatrix,
NonCSCSparse, LegacyCSC, ConcatArray, AllBut, MockTropical, Variable, Expression, Meters,
NonCSCSparse, LegacyCSC, ConcatArray, KeysVector, AllBut, MockTropical, Variable, Expression, Meters,
OneSided, Tagged, CustomType, UndefElt, Positive,
check_trisolve, check_scalar_broadcast, allocated_bytes,
show_plain, show_contents,
Expand Down Expand Up @@ -242,6 +242,14 @@ Base.hvcat(rows::Tuple{Vararg{Int}}, x::AbstractMatrix, y::ConcatArray{<:Any,2})
Base.vcat(x::AbstractVector, y::ConcatArray{<:Any,1}) = ConcatArray(vcat(x, y.data))
Base.hcat(x::AbstractVector, y::ConcatArray{<:Any,1}) = ConcatArray(hcat(x, y.data))

# An array whose `parent` is not an array.
struct KeysVector{K} <: AbstractVector{K}
parent::Dict{K,Int}
end
Base.size(k::KeysVector) = (length(k.parent),)
Base.getindex(k::KeysVector, i::Int) = sort!(collect(keys(k.parent)))[i]
Base.parent(k::KeysVector) = k.parent

# An index type lowered by `to_indices`, like `InvertedIndices.Not`.
struct AllBut; i::Int; end
Base.to_indices(A, inds, I::Tuple{AllBut,Vararg}) =
Expand Down
12 changes: 12 additions & 0 deletions test/issues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,18 @@ end
@test mismatch(S .* x', Matrix(S) .* Vector(x)') === nothing
end

@testset "concatenating arrays whose parent is not an array (issue #1191)" begin
for k in (KeysVector(Dict("a" => 1, "b" => 2)), KeysVector(Dict(1.0 => 1, 2.0 => 2)))
@test !issparse(k)
@test vcat(k, k)::Vector == vcat(collect(k), collect(k))
@test hcat(k, k)::Matrix == hcat(collect(k), collect(k))
@test hvcat((2,), k, k)::Matrix == hcat(collect(k), collect(k))
@test cat(k, k; dims=1)::Vector == vcat(collect(k), collect(k))
end
@test mismatch(vcat(KeysVector(Dict(1.0 => 1, 2.0 => 2)), sparsevec([3.0, 0.0])),
[1.0, 2.0, 3.0, 0.0]) === nothing
end

end # SparseTestsBase

end # module
Loading