@@ -1041,6 +1041,7 @@ sparse(D::Diagonal) = SparseMatrixCSC(D)
10411041
10421042"""
10431043 sparse(I, J, V,[ m, n, combine])
1044+ sparse(IJ, V,[ m, n, combine])
10441045
10451046Create a sparse matrix `S` of dimensions `m x n` such that `S[I[k], J[k]] = V[k]`. The
10461047`combine` function is used to combine duplicates. If `m` and `n` are not specified, they
@@ -1061,6 +1062,12 @@ julia> Js = [1; 2; 3];
10611062julia> Vs = [1; 2; 3];
10621063
10631064julia> sparse(Is, Js, Vs)
1065+ 3×3 SparseMatrixCSC{Int64, Int64} with 3 stored entries:
1066+ 1 ⋅ ⋅
1067+ ⋅ 2 ⋅
1068+ ⋅ ⋅ 3
1069+
1070+ julia> sparse([CartesianIndex(i,i) for i in 1:3], Vs)
106410713×3 SparseMatrixCSC{Int64, Int64} with 3 stored entries:
10651072 1 ⋅ ⋅
10661073 ⋅ 2 ⋅
@@ -1111,11 +1118,6 @@ end
11111118sparse (I:: AbstractVector , J:: AbstractVector , V:: AbstractVector , m:: Integer , n:: Integer , combine) =
11121119 sparse (AbstractVector {Int} (I), AbstractVector {Int} (J), V, m, n, combine)
11131120
1114- function sparse (IJ:: AbstractVector{CartesianIndex{2}} , V:: AbstractVector , m:: Integer , n:: Integer )
1115- IJ′ = reinterpret (Int, reshape (IJ, 1 , :))
1116- return sparse (view (IJ′, 1 , :), view (IJ′, 2 , :), V, m, n)
1117- end
1118-
11191121"""
11201122 sparse!(I::AbstractVector{Ti}, J::AbstractVector{Ti}, V::AbstractVector{Tv},
11211123 m::Integer, n::Integer, combine, klasttouch::Vector{Ti},
@@ -1336,17 +1338,27 @@ end
13361338
13371339dimlub (I) = isempty (I) ? 0 : Int (maximum (I)) # least upper bound on required sparse matrix dimension
13381340
1341+ function reinterpret_cartesian (IJ:: AbstractVector{CartesianIndex{2}} )
1342+ IJ′ = reinterpret (Int, reshape (IJ, 1 , :))
1343+ return (view (IJ′, 1 , :), view (IJ′, 2 , :))
1344+ end
1345+
13391346sparse (I,J,v:: Number ) = sparse (I, J, fill (v,length (I)))
1347+ sparse (IJ,v:: Number ) = sparse (reinterpret_cartesian (IJ)... , v)
13401348
13411349sparse (I,J,V:: AbstractVector ) = sparse (I, J, V, dimlub (I), dimlub (J))
1350+ sparse (IJ,V:: AbstractVector ) = sparse (reinterpret_cartesian (IJ)... , V)
13421351
13431352sparse (I,J,v:: Number ,m,n) = sparse (I, J, fill (v,length (I)), Int (m), Int (n))
1353+ sparse (IJ,v:: Number ,m,n) = sparse (reinterpret_cartesian (IJ)... , v, m, n)
13441354
13451355sparse (I,J,V:: AbstractVector ,m,n) = sparse (I, J, V, Int (m), Int (n), + )
1356+ sparse (IJ,V:: AbstractVector ,m,n) = sparse (reinterpret_cartesian (IJ)... , V, m, n)
13461357
13471358sparse (I,J,V:: AbstractVector{Bool} ,m,n) = sparse (I, J, V, Int (m), Int (n), | )
13481359
13491360sparse (I,J,v:: Number ,m,n,combine:: Function ) = sparse (I, J, fill (v,length (I)), Int (m), Int (n), combine)
1361+ sparse (IJ,v:: Number ,m,n,combine:: Function ) = sparse (reinterpret_cartesian (IJ)... , v, m, n, combine)
13501362
13511363# # Transposition and permutation methods
13521364
0 commit comments