80
80
81
81
function symsparsecsr (I,J,V,m,n,combine)
82
82
m == n || throw (DimensionMismatch (" matrix is not square: dimensions are ($m , $n )" ))
83
- indices = [ i for i in 1 : length (I) if ! (I[i]< J[i])]
84
- # Explicitly store diagonal zeros if needed
85
- SymSparseMatrixCSR (sparse (vcat (J[indices],1 : m),vcat (I[indices],1 : m),vcat (V[indices],zeros (eltype (V),m)),m,m,combine))
83
+ SymSparseMatrixCSR (sparse (J,I,V,m,n,combine))
86
84
end
87
85
88
86
89
87
"""
90
- function push_coo!(::Type{SparseMatrixCSR },I,J,V,ik,jk,vk)
88
+ function push_coo!(::Type{SymSparseMatrixCSR },I,J,V,ik,jk,vk)
91
89
92
90
Inserts entries in COO vectors for further building a SymSparseMatrixCSR.
93
91
"""
@@ -96,3 +94,26 @@ function push_coo!(::Type{SymSparseMatrixCSR},I::Vector,J::Vector,V::Vector,ik::
96
94
(push! (I, ik), push! (J, jk), push! (V, vk))
97
95
end
98
96
97
+ """
98
+ function finalize_coo!(::Type{SymSparseMatrixCSR},I,J,V,m,n)
99
+
100
+ Check and insert diagonal entries in COO vectors if needed.
101
+ """
102
+ function finalize_coo! (T:: Type{SymSparseMatrixCSR} ,I:: Vector ,J:: Vector ,V:: Vector , m:: Integer , n:: Integer )
103
+ m == n || throw (DimensionMismatch (" matrix is not square: dimensions are ($m , $n )" ))
104
+ touched = zeros (Bool,m)
105
+ for k in 1 : length (I)
106
+ Ik = I[k]
107
+ Jk = J[k]
108
+ if Ik == Jk
109
+ touched[Ik] = true
110
+ end
111
+ end
112
+ for k in 1 : m
113
+ if ! touched[k]
114
+ push_coo! (T,I,J,V,k,k,zero (eltype (V)))
115
+ end
116
+ end
117
+ end
118
+
119
+
0 commit comments