33
44Create a GraphBLAS matrix of dimensions nrows x ncols such that A[I[k], J[k]] = X[k].
55dup 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) and maximum(J) respectively.
7- nvals is set to length(I) is not specified.
8-
9- # Examples
10- ```jldoctest
11- julia> using SuiteSparseGraphBLAS
12-
13- julia> A = GrB_Matrix([1, 1, 2, 3], [1, 1, 2, 3], UInt32[1, 10, 1, 1], dup = GrB_PLUS_UINT32)
14- GrB_Matrix{UInt32}
15-
16- julia> A[1, 1]
17- 0x0000000b
18- ```
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.
198"""
209function GrB_Matrix (
2110 I:: Vector{U} ,
2211 J:: Vector{U} ,
2312 X:: Vector{T} ;
24- nrows:: U = maximum (I),
25- ncols:: U = maximum (J),
13+ nrows:: U = maximum (I)+ 1 ,
14+ ncols:: U = maximum (J)+ 1 ,
2615 nvals:: U = length (I),
27- dup:: GrB_BinaryOp = default_dup (T)) where {T <: valid_types , U <: GrB_Index }
16+ dup:: GrB_BinaryOp = default_dup (T)) where {T, U <: GrB_Index }
2817
2918 A = GrB_Matrix {T} ()
3019 GrB_T = get_GrB_Type (T)
3120 res = GrB_Matrix_new (A, GrB_T, nrows, ncols)
3221 if res != GrB_SUCCESS
3322 error (res)
3423 end
35- res = GrB_Matrix_build (A, I.- 1 , J.- 1 , X, nvals, dup)
24+ res = GrB_Matrix_build (A, I, J, X, nvals, dup)
3625 if res != GrB_SUCCESS
3726 error (res)
3827 end
@@ -58,7 +47,7 @@ julia> nnz(A)
58470
5948```
6049"""
61- function GrB_Matrix (T:: DataType , nrows:: GrB_Index , ncols:: GrB_Index )
50+ function GrB_Matrix (T, nrows:: GrB_Index , ncols:: GrB_Index )
6251 A = GrB_Matrix {T} ()
6352 GrB_T = get_GrB_Type (T)
6453 res = GrB_Matrix_new (A, GrB_T, nrows, ncols)
@@ -163,7 +152,7 @@ function findnz(A::GrB_Matrix)
163152 error (res)
164153 end
165154 I, J, X = res
166- return I.+ 1 , J.+ 1 , X
155+ return I, J, X
167156end
168157
169158"""
@@ -205,7 +194,7 @@ julia> using SuiteSparseGraphBLAS
205194julia> GrB_init(GrB_NONBLOCKING)
206195GrB_SUCCESS::GrB_Info = 0
207196
208- julia> A = GrB_Matrix([1, 2, 3 ], [1, 2, 3 ], [1, 1, 1])
197+ julia> A = GrB_Matrix([0, 1, 2 ], [0, 1, 2 ], [1, 1, 1])
209198GrB_Matrix{Int64}
210199
211200julia> size(A)
@@ -272,7 +261,7 @@ julia> A[1, 1]
272261```
273262"""
274263function getindex (A:: GrB_Matrix , row_index:: GrB_Index , col_index:: GrB_Index )
275- res = GrB_Matrix_extractElement (A, row_index- 1 , col_index- 1 )
264+ res = GrB_Matrix_extractElement (A, row_index, col_index)
276265 if typeof (res) == GrB_Info
277266 error (res)
278267 end
@@ -304,8 +293,8 @@ julia> A[1, 1]
3042935
305294```
306295"""
307- function setindex! (A:: GrB_Matrix{T} , X:: T , I:: GrB_Index , J:: GrB_Index ) where {T <: valid_types }
308- res = GrB_Matrix_setElement (A, X, I- 1 , J- 1 )
296+ function setindex! (A:: GrB_Matrix{T} , X:: T , I:: GrB_Index , J:: GrB_Index ) where T
297+ res = GrB_Matrix_setElement (A, X, I, J)
309298 if res != GrB_SUCCESS
310299 error (res)
311300 end
@@ -364,7 +353,7 @@ julia> findnz(B)
364353([1, 2, 3], [1, 2, 3], [1, 1, 1])
365354```
366355"""
367- function copy (A:: GrB_Matrix{T} ) where T <: valid_types
356+ function copy (A:: GrB_Matrix{T} ) where T
368357 C = GrB_Matrix {T} ()
369358 res = GrB_Matrix_dup (C, A)
370359 if res != GrB_SUCCESS
@@ -392,7 +381,7 @@ julia> findnz(M')
392381([2, 3], [1, 1], [1, 1])
393382```
394383"""
395- function adjoint (A:: GrB_Matrix{T} ) where T <: valid_types
384+ function adjoint (A:: GrB_Matrix{T} ) where T
396385 C = GrB_Matrix (T, size (A, 2 ), size (A, 1 ))
397386 res = GrB_transpose (C, GrB_NULL, GrB_NULL, A, GrB_NULL)
398387 if res != GrB_SUCCESS
406395
407396Return lower triangle of a GraphBLAS matrix.
408397"""
409- function LowerTriangular (A:: GrB_Matrix{T} ) where T <: valid_types
398+ function LowerTriangular (A:: GrB_Matrix{T} ) where T
410399 nrows, ncols = size (A)
411400 if nrows != ncols
412401 error (" Matrix is not square" )
424413
425414Return upper triangle of a GraphBLAS matrix.
426415"""
427- function UpperTriangular (A:: GrB_Matrix{T} ) where T <: valid_types
416+ function UpperTriangular (A:: GrB_Matrix{T} ) where T
428417 nrows, ncols = size (A)
429418 if nrows != ncols
430419 error (" Matrix is not square" )
442431
443432Return diagonal of a GraphBLAS matrix.
444433"""
445- function Diagonal (A:: GrB_Matrix{T} ) where T <: valid_types
434+ function Diagonal (A:: GrB_Matrix{T} ) where T
446435 nrows, ncols = size (A)
447436 D = GrB_Matrix (T, nrows, ncols)
448437 res = GxB_select (D, GrB_NULL, GrB_NULL, GxB_DIAG, A, 0 , GrB_NULL)
0 commit comments