@@ -774,11 +774,14 @@ complex(x::AbstractSparseVector) =
774
774
775
775
# Without the first of these methods, horizontal concatenations of SparseVectors fall
776
776
# back to the horizontal concatenation method that ensures that combinations of
777
- # sparse/special/dense matrix/vector types concatenate to SparseMatrixCSCs, instead
778
- # of _absspvec_hcat below. The <:Integer qualifications are necessary for correct dispatch.
779
- hcat {Tv,Ti<:Integer} (X:: SparseVector{Tv,Ti} ...) = _absspvec_hcat (X... )
780
- hcat {Tv,Ti<:Integer} (X:: AbstractSparseVector{Tv,Ti} ...) = _absspvec_hcat (X... )
781
- function _absspvec_hcat {Tv,Ti} (X:: AbstractSparseVector{Tv,Ti} ...)
777
+ # sparse/special/dense matrix/vector types concatenate to SparseMatrixCSCs.
778
+ # The <:Integer qualifications are necessary for correct dispatch.
779
+ hcat {Tv,Ti<:Integer} (X:: SparseVector{Tv,Ti} ...) = typed_hcat (SparseMatrixCSC, X... )
780
+ hcat {Tv,Ti<:Integer} (X:: AbstractSparseVector{Tv,Ti} ...) = typed_hcat (SparseMatrixCSC, X... )
781
+
782
+ promote_indtype {Tv,Ti} (X:: SparseVector{Tv,Ti} , Xs:: SparseVector... ) = promote_type (Ti, promote_indtype (Xs... ))
783
+
784
+ function typed_hcat {Tv,Ti<:Integer} (:: Type{SparseMatrixCSC{Tv,Ti}} , X:: AbstractSparseVector... )
782
785
# check sizes
783
786
n = length (X)
784
787
m = length (X[1 ])
@@ -806,14 +809,22 @@ function _absspvec_hcat{Tv,Ti}(X::AbstractSparseVector{Tv,Ti}...)
806
809
colptr[n+ 1 ] = roff
807
810
SparseMatrixCSC {Tv,Ti} (m, n, colptr, nzrow, nzval)
808
811
end
812
+ typed_hcat (:: Type{SparseMatrixCSC} , X:: AbstractSparseVector... ) =
813
+ typed_hcat (SparseMatrixCSC{promote_eltype (X... )}, X... )
814
+ typed_hcat {Tv} (:: Type{SparseMatrixCSC{Tv}} , X:: AbstractSparseVector... ) =
815
+ typed_hcat (SparseMatrixCSC{Tv,promote_indtype (X... )}, X... )
816
+ typed_hcat {T<:SparseMatrixCSC} (:: Type{T} , Xin:: AbstractVector... ) =
817
+ typed_hcat (T, map (sparse, Xin)... )
809
818
810
819
# Without the first of these methods, vertical concatenations of SparseVectors fall
811
820
# back to the vertical concatenation method that ensures that combinations of
812
- # sparse/special/dense matrix/vector types concatenate to SparseMatrixCSCs, instead
813
- # of _absspvec_vcat below. The <:Integer qualifications are necessary for correct dispatch.
814
- vcat {Tv,Ti<:Integer} (X:: SparseVector{Tv,Ti} ...) = _absspvec_vcat (X... )
815
- vcat {Tv,Ti<:Integer} (X:: AbstractSparseVector{Tv,Ti} ...) = _absspvec_vcat (X... )
816
- function _absspvec_vcat {Tv,Ti} (X:: AbstractSparseVector{Tv,Ti} ...)
821
+ # sparse/special/dense matrix/vector types concatenate to SparseMatrixCSCs.
822
+ # The <:Integer qualifications are necessary for correct dispatch.
823
+ vcat {Tv,Ti<:Integer} (X:: SparseVector{Tv,Ti} ...) = typed_vcat (SparseVector, X... )
824
+ vcat {Tv,Ti<:Integer} (X:: AbstractSparseVector{Tv,Ti} ...) = typed_vcat (SparseVector, X... )
825
+
826
+ typed_vcat {T<:SparseVector} (:: Type{T} ) = T (0 )
827
+ function typed_vcat {Tv,Ti<:Integer} (:: Type{SparseVector{Tv,Ti}} , X:: AbstractSparseVector... )
817
828
# check sizes
818
829
n = length (X)
819
830
tnnz = 0
@@ -840,9 +851,18 @@ function _absspvec_vcat{Tv,Ti}(X::AbstractSparseVector{Tv,Ti}...)
840
851
end
841
852
SparseVector (len, rnzind, rnzval)
842
853
end
854
+ typed_vcat (:: Type{SparseVector} , X:: AbstractSparseVector... ) =
855
+ typed_vcat (SparseVector{promote_eltype (X... )}, X... )
856
+ typed_vcat {Tv} (:: Type{SparseVector{Tv}} , X:: AbstractSparseVector... ) =
857
+ typed_vcat (SparseVector{Tv,promote_indtype (X... )}, X... )
858
+ typed_vcat {T<:SparseVector} (:: Type{T} , Xin:: AbstractVector... ) =
859
+ typed_vcat (T, map (sparse, Xin)... )
860
+
843
861
844
- hcat (Xin:: Union{Vector, AbstractSparseVector} ...) = hcat (map (sparse, Xin)... )
845
- vcat (Xin:: Union{Vector, AbstractSparseVector} ...) = vcat (map (sparse, Xin)... )
862
+ hcat (Xin:: Union{Vector, AbstractSparseVector, SparseMatrixCSC} ...) = typed_hcat (SparseMatrixCSC, Xin... )
863
+ vcat (Xin:: Union{Vector, AbstractSparseVector} ...) = typed_vcat (SparseVector, Xin... )
864
+ vcat (Xin:: AbstractSparseVector... ) = typed_vcat (SparseVector, Xin... )
865
+ vcat (Xin:: Union{AbstractSparseVector, SparseMatrixCSC} ...) = typed_vcat (SparseMatrixCSC, Xin... )
846
866
847
867
848
868
# ## Concatenation of un/annotated sparse/special/dense vectors/matrices
0 commit comments