@@ -720,7 +720,13 @@ complex(x::AbstractSparseVector) =
720
720
721
721
# ## Concatenation
722
722
723
- function hcat {Tv,Ti} (X:: AbstractSparseVector{Tv,Ti} ...)
723
+ # Without the first of these methods, horizontal concatenations of SparseVectors fall
724
+ # back to the horizontal concatenation method that ensures that combinations of
725
+ # sparse/special/dense matrix/vector types concatenate to SparseMatrixCSCs, instead
726
+ # of _absspvec_hcat below. The <:Integer qualifications are necessary for correct dispatch.
727
+ hcat {Tv,Ti<:Integer} (X:: SparseVector{Tv,Ti} ...) = _absspvec_hcat (X... )
728
+ hcat {Tv,Ti<:Integer} (X:: AbstractSparseVector{Tv,Ti} ...) = _absspvec_hcat (X... )
729
+ function _absspvec_hcat {Tv,Ti} (X:: AbstractSparseVector{Tv,Ti} ...)
724
730
# check sizes
725
731
n = length (X)
726
732
m = length (X[1 ])
@@ -749,7 +755,13 @@ function hcat{Tv,Ti}(X::AbstractSparseVector{Tv,Ti}...)
749
755
SparseMatrixCSC {Tv,Ti} (m, n, colptr, nzrow, nzval)
750
756
end
751
757
752
- function vcat {Tv,Ti} (X:: AbstractSparseVector{Tv,Ti} ...)
758
+ # Without the first of these methods, vertical concatenations of SparseVectors fall
759
+ # back to the vertical concatenation method that ensures that combinations of
760
+ # sparse/special/dense matrix/vector types concatenate to SparseMatrixCSCs, instead
761
+ # of _absspvec_vcat below. The <:Integer qualifications are necessary for correct dispatch.
762
+ vcat {Tv,Ti<:Integer} (X:: SparseVector{Tv,Ti} ...) = _absspvec_vcat (X... )
763
+ vcat {Tv,Ti<:Integer} (X:: AbstractSparseVector{Tv,Ti} ...) = _absspvec_vcat (X... )
764
+ function _absspvec_vcat {Tv,Ti} (X:: AbstractSparseVector{Tv,Ti} ...)
753
765
# check sizes
754
766
n = length (X)
755
767
tnnz = 0
@@ -777,11 +789,49 @@ function vcat{Tv,Ti}(X::AbstractSparseVector{Tv,Ti}...)
777
789
SparseVector (len, rnzind, rnzval)
778
790
end
779
791
780
- hcat (Xin:: Union{AbstractSparseVector, SparseMatrixCSC} ...) = hcat (map (SparseMatrixCSC, Xin)... )
781
- vcat (Xin:: Union{AbstractSparseVector, SparseMatrixCSC} ...) = vcat (map (SparseMatrixCSC, Xin)... )
782
792
hcat (Xin:: Union{Vector, AbstractSparseVector} ...) = hcat (map (sparse, Xin)... )
783
793
vcat (Xin:: Union{Vector, AbstractSparseVector} ...) = vcat (map (sparse, Xin)... )
784
794
795
+
796
+ # ## Sparse/special/dense vector/matrix concatenation
797
+
798
+ # TODO : These methods should be moved to a more appropriate location, particularly some
799
+ # future equivalent of base/linalg/special.jl dedicated to interactions between a broader
800
+ # set of matrix types.
801
+
802
+ # TODO : A similar definition also exists in base/linalg/bidiag.jl. These definitions should
803
+ # be consolidated in a more appropriate location, for example base/linalg/special.jl.
804
+ SpecialArrays = Union{Diagonal, Bidiagonal, Tridiagonal, SymTridiagonal}
805
+
806
+ function hcat (Xin:: Union{Vector, Matrix, SparseVector, SparseMatrixCSC, SpecialArrays} ...)
807
+ X = SparseMatrixCSC[issparse (x) ? x : sparse (x) for x in Xin]
808
+ hcat (X... )
809
+ end
810
+
811
+ function vcat (Xin:: Union{Vector, Matrix, SparseVector, SparseMatrixCSC, SpecialArrays} ...)
812
+ X = SparseMatrixCSC[issparse (x) ? x : sparse (x) for x in Xin]
813
+ vcat (X... )
814
+ end
815
+
816
+ function hvcat (rows:: Tuple{Vararg{Int}} , X:: Union{Vector, Matrix, SparseVector, SparseMatrixCSC, SpecialArrays} ...)
817
+ nbr = length (rows) # number of block rows
818
+
819
+ tmp_rows = Array {SparseMatrixCSC} (nbr)
820
+ k = 0
821
+ @inbounds for i = 1 : nbr
822
+ tmp_rows[i] = hcat (X[(1 : rows[i]) + k]. .. )
823
+ k += rows[i]
824
+ end
825
+ vcat (tmp_rows... )
826
+ end
827
+
828
+ function cat (catdims, Xin:: Union{Vector, Matrix, SparseVector, SparseMatrixCSC, SpecialArrays} ...)
829
+ X = SparseMatrixCSC[issparse (x) ? x : sparse (x) for x in Xin]
830
+ T = promote_eltype (Xin... )
831
+ Base. cat_t (catdims, T, X... )
832
+ end
833
+
834
+
785
835
# ## math functions
786
836
787
837
# ## Unary Map
0 commit comments