Skip to content

Commit

Permalink
add RowVectors to to list of types included in sparse concatinations (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Aug 22, 2017
1 parent 8404314 commit d00deb7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions base/sparse/sparsevector.jl
Expand Up @@ -955,7 +955,7 @@ vcat(X::Union{Vector,SparseVector}...) = vcat(map(sparse, X)...)

# TODO: A definition similar to the third exists in base/linalg/bidiag.jl. These definitions
# should be consolidated in a more appropriate location, e.g. base/linalg/special.jl.
const _SparseArrays = Union{SparseVector, SparseMatrixCSC}
const _SparseArrays = Union{SparseVector, SparseMatrixCSC, RowVector{<:Any, <:SparseVector}}
const _SpecialArrays = Union{Diagonal, Bidiagonal, Tridiagonal, SymTridiagonal}
const _SparseConcatArrays = Union{_SpecialArrays, _SparseArrays}

Expand All @@ -970,9 +970,9 @@ const _Triangular_DenseArrays{T,A<:Matrix} = Base.LinAlg.AbstractTriangular{T,A}
const _Annotated_DenseArrays = Union{_Triangular_DenseArrays, _Symmetric_DenseArrays, _Hermitian_DenseArrays}
const _Annotated_Typed_DenseArrays{T} = Union{_Triangular_DenseArrays{T}, _Symmetric_DenseArrays{T}, _Hermitian_DenseArrays{T}}

const _SparseConcatGroup = Union{Vector, Matrix, _SparseConcatArrays, _Annotated_SparseConcatArrays, _Annotated_DenseArrays}
const _DenseConcatGroup = Union{Vector, Matrix, _Annotated_DenseArrays}
const _TypedDenseConcatGroup{T} = Union{Vector{T}, Matrix{T}, _Annotated_Typed_DenseArrays{T}}
const _SparseConcatGroup = Union{Vector, RowVector{<:Any, <:Vector}, Matrix, _SparseConcatArrays, _Annotated_SparseConcatArrays, _Annotated_DenseArrays}
const _DenseConcatGroup = Union{Vector, RowVector{<:Any, <:Vector}, Matrix, _Annotated_DenseArrays}
const _TypedDenseConcatGroup{T} = Union{Vector{T}, RowVector{T,Vector{T}}, Matrix{T}, _Annotated_Typed_DenseArrays{T}}

# Concatenations involving un/annotated sparse/special matrices/vectors should yield sparse arrays
function cat(catdims, Xin::_SparseConcatGroup...)
Expand Down
4 changes: 4 additions & 0 deletions test/arrayops.jl
Expand Up @@ -2020,6 +2020,10 @@ end # module AutoRetType
@test isa(hvcat((2,), densearray, densearray), Array)
@test isa(cat((1,2), densearray, densearray), Array)
end
@test isa([[1,2,3]'; [1,2,3]'], Matrix{Int})
@test isa([[1,2,3]' [1,2,3]'], RowVector{Int, Vector{Int}})
@test isa([Any[1.0, 2]'; Any[2.0, 2]'], Matrix{Any})
@test isa([Any[1.0, 2]' Any[2.0, 2']'], RowVector{Any, Vector{Any}})
# Test that concatenations of heterogeneous Matrix-Vector pairs yield dense matrices
@test isa(hcat(densemat, densevec), Array)
@test isa(hcat(densevec, densemat), Array)
Expand Down

0 comments on commit d00deb7

Please sign in to comment.