|
3 | 3 |
|
4 | 4 | Create a GraphBLAS matrix of dimensions nrows x ncols such that A[I[k], J[k]] = X[k]. |
5 | 5 | dup is a GraphBLAS binary operator used to combine duplicates, it defaults to `FIRST`. |
6 | | -If nrows and ncols are not specified, they are set to maximum(I)+1 and maximum(J)+1 (because of 0-based indexing) |
7 | | -respectively. nvals is set to length(I) is not specified. |
| 6 | +If nrows and ncols are not specified, they are set to maximum(I) and maximum(J) (for one based indices). |
| 7 | +respectively. nvals is set to min(length(I), length(J)) if not specified. |
8 | 8 | """ |
9 | 9 | function GrB_Matrix( |
10 | 10 | I::Vector{U}, |
11 | 11 | J::Vector{U}, |
12 | 12 | X::Vector{T}; |
13 | | - nrows::U = maximum(I)+1, |
14 | | - ncols::U = maximum(J)+1, |
15 | | - nvals::U = length(I), |
16 | | - dup::GrB_BinaryOp = default_dup(T)) where {T, U <: GrB_Index} |
| 13 | + nrows::Union{Int64, UInt64} = maximum(I).x, |
| 14 | + ncols::Union{Int64, UInt64} = maximum(J).x, |
| 15 | + nvals::Union{Int64, UInt64} = min(length(I), length(J)), |
| 16 | + dup::GrB_BinaryOp = default_dup(T)) where {T, U <: Abstract_GrB_Index} |
17 | 17 |
|
18 | 18 | A = GrB_Matrix{T}() |
19 | 19 | GrB_T = get_GrB_Type(T) |
| 20 | + if U <: ZeroBasedIndex |
| 21 | + nrows += 1 |
| 22 | + ncols += 1 |
| 23 | + end |
20 | 24 | res = GrB_Matrix_new(A, GrB_T, nrows, ncols) |
21 | 25 | if res != GrB_SUCCESS |
22 | 26 | error(res) |
|
32 | 36 | GrB_Matrix(T, nrows, ncols) |
33 | 37 |
|
34 | 38 | Create an empty GraphBLAS matrix of type T and dimensions nrows x ncols. |
35 | | -
|
36 | | -# Examples |
37 | | -```jldoctest |
38 | | -julia> using SuiteSparseGraphBLAS |
39 | | -
|
40 | | -julia> GrB_init(GrB_NONBLOCKING) |
41 | | -GrB_SUCCESS::GrB_Info = 0 |
42 | | -
|
43 | | -julia> A = GrB_Matrix(Float64, 4, 4) |
44 | | -GrB_Matrix{Float64} |
45 | | -
|
46 | | -julia> nnz(A) |
47 | | -0 |
48 | | -``` |
49 | 39 | """ |
50 | | -function GrB_Matrix(T, nrows::GrB_Index, ncols::GrB_Index) |
| 40 | +function GrB_Matrix(T, nrows::Union{Int64, UInt64}, ncols::Union{Int64, UInt64}) |
51 | 41 | A = GrB_Matrix{T}() |
52 | 42 | GrB_T = get_GrB_Type(T) |
53 | 43 | res = GrB_Matrix_new(A, GrB_T, nrows, ncols) |
|
61 | 51 | ==(A, B) |
62 | 52 |
|
63 | 53 | Check if two GraphBLAS matrices are equal. |
64 | | -
|
65 | | -# Examples |
66 | | -```jldoctest |
67 | | -julia> using SuiteSparseGraphBLAS |
68 | | -
|
69 | | -julia> GrB_init(GrB_NONBLOCKING) |
70 | | -GrB_SUCCESS::GrB_Info = 0 |
71 | | -
|
72 | | -julia> A = GrB_Matrix([1, 2, 3], [2, 4, 5], [1, 1, 1]) |
73 | | -GrB_Matrix{Int64} |
74 | | -
|
75 | | -julia> B = GrB_Matrix([1, 2, 3], [2, 4, 5], [1, 1, 1]) |
76 | | -GrB_Matrix{Int64} |
77 | | -
|
78 | | -julia> A == B |
79 | | -true |
80 | | -
|
81 | | -julia> B = GrB_Matrix([1, 2, 3], [2, 4, 5], [1, 1, 2]) |
82 | | -GrB_Matrix{Int64} |
83 | | -
|
84 | | -julia> A == B |
85 | | -false |
86 | | -
|
87 | | -julia> B = GrB_Matrix([1, 2, 3], [2, 4, 3], [1, 1, 1]) |
88 | | -GrB_Matrix{Int64} |
89 | | -
|
90 | | -julia> A == B |
91 | | -false |
92 | | -``` |
93 | 54 | """ |
94 | 55 | function ==(A::GrB_Matrix{T}, B::GrB_Matrix{U}) where {T, U} |
95 | 56 | T != U && return false |
@@ -127,27 +88,13 @@ function ==(A::GrB_Matrix{T}, B::GrB_Matrix{U}) where {T, U} |
127 | 88 | end |
128 | 89 |
|
129 | 90 | """ |
130 | | - findnz(A) |
| 91 | + findnz(A, [index_type]) |
131 | 92 |
|
132 | 93 | Return a tuple (I, J, X) where I and J are the row and column indices of the stored values in GraphBLAS matrix A, |
133 | | -and X is a vector of the values. |
134 | | -
|
135 | | -# Examples |
136 | | -```jldoctest |
137 | | -julia> using SuiteSparseGraphBLAS |
138 | | -
|
139 | | -julia> GrB_init(GrB_NONBLOCKING) |
140 | | -GrB_SUCCESS::GrB_Info = 0 |
141 | | -
|
142 | | -julia> A = GrB_Matrix([1, 2, 3], [1, 2, 3], [1, 1, 1]) |
143 | | -GrB_Matrix{Int64} |
144 | | -
|
145 | | -julia> findnz(A) |
146 | | -([1, 2, 3], [1, 2, 3], [1, 1, 1]) |
147 | | -``` |
| 94 | +and X is a vector of the values. Indices are zero based by default if not specified. |
148 | 95 | """ |
149 | | -function findnz(A::GrB_Matrix) |
150 | | - res = GrB_Matrix_extractTuples(A) |
| 96 | +function findnz(A::GrB_Matrix, index_type::Type{<:Abstract_GrB_Index} = ZeroBasedIndex) |
| 97 | + res = GrB_Matrix_extractTuples(A, index_type) |
151 | 98 | if typeof(res) == GrB_Info |
152 | 99 | error(res) |
153 | 100 | end |
|
159 | 106 | nnz(A) |
160 | 107 |
|
161 | 108 | Return the number of stored (filled) elements in a GraphBLAS matrix. |
162 | | -
|
163 | | -# Examples |
164 | | -```jldoctest |
165 | | -julia> using SuiteSparseGraphBLAS |
166 | | -
|
167 | | -julia> GrB_init(GrB_NONBLOCKING) |
168 | | -GrB_SUCCESS::GrB_Info = 0 |
169 | | -
|
170 | | -julia> A = GrB_Matrix([1, 2, 3], [1, 2, 3], [1, 1, 1]) |
171 | | -GrB_Matrix{Int64} |
172 | | -
|
173 | | -julia> nnz(A) |
174 | | -3 |
175 | | -``` |
176 | 109 | """ |
177 | 110 | function nnz(A::GrB_Matrix) |
178 | 111 | nvals = GrB_Matrix_nvals(A) |
|
186 | 119 | size(A,[ dim]) |
187 | 120 |
|
188 | 121 | Return number of rows or/and columns in a GraphBLAS matrix. |
189 | | -
|
190 | | -# Examples |
191 | | -```jldoctest |
192 | | -julia> using SuiteSparseGraphBLAS |
193 | | -
|
194 | | -julia> GrB_init(GrB_NONBLOCKING) |
195 | | -GrB_SUCCESS::GrB_Info = 0 |
196 | | -
|
197 | | -julia> A = GrB_Matrix([0, 1, 2], [0, 1, 2], [1, 1, 1]) |
198 | | -GrB_Matrix{Int64} |
199 | | -
|
200 | | -julia> size(A) |
201 | | -(3, 3) |
202 | | -
|
203 | | -julia> size(A, 1) |
204 | | -3 |
205 | | -
|
206 | | -julia> size(A, 2) |
207 | | -3 |
208 | | -``` |
209 | 122 | """ |
210 | 123 | function size(A::GrB_Matrix) |
211 | 124 | nrows = GrB_Matrix_nrows(A) |
|
245 | 158 | getindex(A, row_index, col_index) |
246 | 159 |
|
247 | 160 | Return A[row_index, col_index] where A is a GraphBLAS matrix. |
248 | | -
|
249 | | -# Examples |
250 | | -```jldoctest |
251 | | -julia> using SuiteSparseGraphBLAS |
252 | | -
|
253 | | -julia> GrB_init(GrB_NONBLOCKING) |
254 | | -GrB_SUCCESS::GrB_Info = 0 |
255 | | -
|
256 | | -julia> A = GrB_Matrix([1, 2, 3], [1, 2, 3], [1, 1, 1]) |
257 | | -GrB_Matrix{Int64} |
258 | | -
|
259 | | -julia> A[1, 1] |
260 | | -1 |
261 | | -``` |
262 | 161 | """ |
263 | | -function getindex(A::GrB_Matrix, row_index::GrB_Index, col_index::GrB_Index) |
| 162 | +function getindex(A::GrB_Matrix, row_index::Abstract_GrB_Index, col_index::Abstract_GrB_Index) |
264 | 163 | res = GrB_Matrix_extractElement(A, row_index, col_index) |
265 | 164 | if typeof(res) == GrB_Info |
266 | 165 | error(res) |
|
272 | 171 | setindex!(A, X, I, J) |
273 | 172 |
|
274 | 173 | Set A[I, J] = X where A is a GraphBLAS matrix. |
275 | | -
|
276 | | -# Examples |
277 | | -```jldoctest |
278 | | -julia> using SuiteSparseGraphBLAS |
279 | | -
|
280 | | -julia> GrB_init(GrB_NONBLOCKING) |
281 | | -GrB_SUCCESS::GrB_Info = 0 |
282 | | -
|
283 | | -julia> A = GrB_Matrix([1, 2, 3], [1, 2, 3], [1, 1, 1]) |
284 | | -GrB_Matrix{Int64} |
285 | | -
|
286 | | -julia> A[1, 1] |
287 | | -1 |
288 | | -
|
289 | | -julia> A[1, 1] = 5 |
290 | | -5 |
291 | | -
|
292 | | -julia> A[1, 1] |
293 | | -5 |
294 | | -``` |
295 | 174 | """ |
296 | | -function setindex!(A::GrB_Matrix{T}, X::T, I::GrB_Index, J::GrB_Index) where T |
| 175 | +function setindex!(A::GrB_Matrix{T}, X::T, I::Abstract_GrB_Index, J::Abstract_GrB_Index) where T |
297 | 176 | res = GrB_Matrix_setElement(A, X, I, J) |
298 | 177 | if res != GrB_SUCCESS |
299 | 178 | error(res) |
|
304 | 183 | empty!(A) |
305 | 184 |
|
306 | 185 | Remove all stored entries from GraphBLAS matrix A. |
307 | | -
|
308 | | -# Examples |
309 | | -```jldoctest |
310 | | -julia> using SuiteSparseGraphBLAS |
311 | | -
|
312 | | -julia> GrB_init(GrB_NONBLOCKING) |
313 | | -GrB_SUCCESS::GrB_Info = 0 |
314 | | -
|
315 | | -julia> A = GrB_Matrix([1, 2, 3], [1, 2, 3], [1, 1, 1]) |
316 | | -GrB_Matrix{Int64} |
317 | | -
|
318 | | -julia> nnz(A) |
319 | | -3 |
320 | | -
|
321 | | -julia> empty!(A) |
322 | | -
|
323 | | -julia> nnz(A) |
324 | | -0 |
325 | | -``` |
326 | 186 | """ |
327 | 187 | function empty!(A::GrB_Matrix) |
328 | 188 | res = GrB_Matrix_clear(A) |
|
335 | 195 | copy(A) |
336 | 196 |
|
337 | 197 | Create a new GraphBLAS matrix with the same domain, dimensions, and contents as GraphBLAS matrix A. |
338 | | -
|
339 | | -# Examples |
340 | | -```jldoctest |
341 | | -julia> using SuiteSparseGraphBLAS |
342 | | -
|
343 | | -julia> GrB_init(GrB_NONBLOCKING) |
344 | | -GrB_SUCCESS::GrB_Info = 0 |
345 | | -
|
346 | | -julia> A = GrB_Matrix([1, 2, 3], [1, 2, 3], [1, 1, 1]) |
347 | | -GrB_Matrix{Int64} |
348 | | -
|
349 | | -julia> B = copy(A) |
350 | | -GrB_Matrix{Int64} |
351 | | -
|
352 | | -julia> findnz(B) |
353 | | -([1, 2, 3], [1, 2, 3], [1, 1, 1]) |
354 | | -``` |
355 | 198 | """ |
356 | 199 | function copy(A::GrB_Matrix{T}) where T |
357 | 200 | C = GrB_Matrix{T}() |
|
366 | 209 | adjoint(A) |
367 | 210 |
|
368 | 211 | Compute transpose of a GraphBLAS matrix. |
369 | | -
|
370 | | -# Examples |
371 | | -```jldoctest |
372 | | -julia> using SuiteSparseGraphBLAS |
373 | | -
|
374 | | -julia> GrB_init(GrB_NONBLOCKING) |
375 | | -GrB_SUCCESS::GrB_Info = 0 |
376 | | -
|
377 | | -julia> M = GrB_Matrix([1, 1], [2, 3], [1, 1]) |
378 | | -GrB_Matrix{Int64} |
379 | | -
|
380 | | -julia> findnz(M') |
381 | | -([2, 3], [1, 1], [1, 1]) |
382 | | -``` |
383 | 212 | """ |
384 | 213 | function adjoint(A::GrB_Matrix{T}) where T |
385 | 214 | C = GrB_Matrix(T, size(A, 2), size(A, 1)) |
|
0 commit comments