|
2 | 2 | GrB_Matrix_new(A, type, nrows, ncols)
|
3 | 3 |
|
4 | 4 | Create a new matrix with specified domain and dimensions.
|
| 5 | +
|
| 6 | +# Examples |
| 7 | +```jldoctest |
| 8 | +julia> using SuiteSparseGraphBLAS |
| 9 | +
|
| 10 | +julia> GrB_init(GrB_NONBLOCKING) |
| 11 | +GrB_SUCCESS::GrB_Info = 0 |
| 12 | +
|
| 13 | +julia> MAT = GrB_Matrix() |
| 14 | +GrB_Matrix |
| 15 | +
|
| 16 | +julia> GrB_Matrix_new(MAT, GrB_INT8, 4, 4) |
| 17 | +GrB_SUCCESS::GrB_Info = 0 |
| 18 | +``` |
5 | 19 | """
|
6 | 20 | function GrB_Matrix_new(A::GrB_Matrix, type::GrB_Type, nrows::T, ncols::T) where T <: GrB_Index
|
7 | 21 | A_ptr = pointer_from_objref(A)
|
|
20 | 34 | GrB_Matrix_build(C, I, J, X, nvals, dup)
|
21 | 35 |
|
22 | 36 | Store elements from tuples into a vector.
|
| 37 | +
|
| 38 | +# Examples |
| 39 | +```jldoctest |
| 40 | +julia> using SuiteSparseGraphBLAS |
| 41 | +
|
| 42 | +julia> GrB_init(GrB_NONBLOCKING) |
| 43 | +GrB_SUCCESS::GrB_Info = 0 |
| 44 | +
|
| 45 | +julia> MAT = GrB_Matrix() |
| 46 | +GrB_Matrix |
| 47 | +
|
| 48 | +julia> GrB_Matrix_new(MAT, GrB_INT8, 4, 4) |
| 49 | +GrB_SUCCESS::GrB_Info = 0 |
| 50 | +
|
| 51 | +julia> I = [1, 2, 2, 2, 3]; J = [1, 2, 1, 3, 3]; X = Int8[2, 3, 4, 5, 6]; n = 5; |
| 52 | +
|
| 53 | +julia> GrB_Matrix_build(MAT, I, J, X, n, GrB_FIRST_INT8) |
| 54 | +GrB_SUCCESS::GrB_Info = 0 |
| 55 | +
|
| 56 | +julia> @GxB_Matrix_fprint(MAT, GxB_COMPLETE) |
| 57 | +
|
| 58 | +GraphBLAS matrix: MAT |
| 59 | +nrows: 4 ncols: 4 max # entries: 5 |
| 60 | +format: standard CSR vlen: 4 nvec_nonempty: 3 nvec: 4 plen: 4 vdim: 4 |
| 61 | +hyper_ratio 0.0625 |
| 62 | +GraphBLAS type: int8_t size: 1 |
| 63 | +number of entries: 5 |
| 64 | +row: 1 : 1 entries [0:0] |
| 65 | + column 1: int8 2 |
| 66 | +row: 2 : 3 entries [1:3] |
| 67 | + column 1: int8 4 |
| 68 | + column 2: int8 3 |
| 69 | + column 3: int8 5 |
| 70 | +row: 3 : 1 entries [4:4] |
| 71 | + column 3: int8 6 |
| 72 | +
|
| 73 | +
|
| 74 | +``` |
23 | 75 | """
|
24 | 76 | function GrB_Matrix_build(C::GrB_Matrix, I::Vector{U}, J::Vector{U}, X::Vector{T}, nvals::U, dup::GrB_BinaryOp) where{U <: GrB_Index, T <: valid_types}
|
25 | 77 | I_ptr = pointer(I)
|
|
41 | 93 |
|
42 | 94 | Return the number of rows in a matrix if successful.
|
43 | 95 | Else return value of type GrB Info.
|
| 96 | +
|
| 97 | +# Examples |
| 98 | +```jldoctest |
| 99 | +julia> using SuiteSparseGraphBLAS |
| 100 | +
|
| 101 | +julia> GrB_init(GrB_NONBLOCKING) |
| 102 | +GrB_SUCCESS::GrB_Info = 0 |
| 103 | +
|
| 104 | +julia> MAT = GrB_Matrix() |
| 105 | +GrB_Matrix |
| 106 | +
|
| 107 | +julia> GrB_Matrix_new(MAT, GrB_INT8, 4, 4) |
| 108 | +GrB_SUCCESS::GrB_Info = 0 |
| 109 | +
|
| 110 | +julia> GrB_Matrix_nrows(MAT) |
| 111 | +4 |
| 112 | +``` |
44 | 113 | """
|
45 | 114 | function GrB_Matrix_nrows(A::GrB_Matrix)
|
46 | 115 | nrows = Ref(UInt64(0))
|
|
61 | 130 |
|
62 | 131 | Return the number of columns in a matrix if successful.
|
63 | 132 | Else return value of type GrB Info.
|
| 133 | +
|
| 134 | +# Examples |
| 135 | +```jldoctest |
| 136 | +julia> using SuiteSparseGraphBLAS |
| 137 | +
|
| 138 | +julia> GrB_init(GrB_NONBLOCKING) |
| 139 | +GrB_SUCCESS::GrB_Info = 0 |
| 140 | +
|
| 141 | +julia> MAT = GrB_Matrix() |
| 142 | +GrB_Matrix |
| 143 | +
|
| 144 | +julia> GrB_Matrix_new(MAT, GrB_INT8, 4, 4) |
| 145 | +GrB_SUCCESS::GrB_Info = 0 |
| 146 | +
|
| 147 | +julia> GrB_Matrix_ncols(MAT) |
| 148 | +4 |
| 149 | +``` |
64 | 150 | """
|
65 | 151 | function GrB_Matrix_ncols(A::GrB_Matrix)
|
66 | 152 | ncols = Ref(UInt64(0))
|
|
81 | 167 |
|
82 | 168 | Return the number of stored elements in a matrix if successful.
|
83 | 169 | Else return value of type GrB Info.
|
| 170 | +
|
| 171 | +# Examples |
| 172 | +```jldoctest |
| 173 | +julia> using SuiteSparseGraphBLAS |
| 174 | +
|
| 175 | +julia> GrB_init(GrB_NONBLOCKING) |
| 176 | +GrB_SUCCESS::GrB_Info = 0 |
| 177 | +
|
| 178 | +julia> MAT = GrB_Matrix() |
| 179 | +GrB_Matrix |
| 180 | +
|
| 181 | +julia> GrB_Matrix_new(MAT, GrB_INT8, 4, 4) |
| 182 | +GrB_SUCCESS::GrB_Info = 0 |
| 183 | +
|
| 184 | +julia> I = [1, 2, 2, 2, 3]; J = [1, 2, 1, 3, 3]; X = Int8[2, 3, 4, 5, 6]; n = 5; |
| 185 | +
|
| 186 | +julia> GrB_Matrix_build(MAT, I, J, X, n, GrB_FIRST_INT8) |
| 187 | +GrB_SUCCESS::GrB_Info = 0 |
| 188 | +
|
| 189 | +julia> GrB_Matrix_nvals(MAT) |
| 190 | +5 |
| 191 | +``` |
84 | 192 | """
|
85 | 193 | function GrB_Matrix_nvals(A::GrB_Matrix)
|
86 | 194 | nvals = Ref(UInt64(0))
|
|
100 | 208 | GrB_Matrix_dup(C, A)
|
101 | 209 |
|
102 | 210 | Create a new matrix with the same domain, dimensions, and contents as another matrix.
|
| 211 | +
|
| 212 | +# Examples |
| 213 | +```jldoctest |
| 214 | +julia> using SuiteSparseGraphBLAS |
| 215 | +
|
| 216 | +julia> GrB_init(GrB_NONBLOCKING) |
| 217 | +GrB_SUCCESS::GrB_Info = 0 |
| 218 | +
|
| 219 | +julia> MAT = GrB_Matrix() |
| 220 | +GrB_Matrix |
| 221 | +
|
| 222 | +julia> GrB_Matrix_new(MAT, GrB_INT8, 4, 4) |
| 223 | +GrB_SUCCESS::GrB_Info = 0 |
| 224 | +
|
| 225 | +julia> I = [1, 2, 2, 2, 3]; J = [1, 2, 1, 3, 3]; X = Int8[2, 3, 4, 5, 6]; n = 5; |
| 226 | +
|
| 227 | +julia> GrB_Matrix_build(MAT, I, J, X, n, GrB_FIRST_INT8) |
| 228 | +GrB_SUCCESS::GrB_Info = 0 |
| 229 | +
|
| 230 | +julia> B = GrB_Matrix() |
| 231 | +GrB_Matrix |
| 232 | +
|
| 233 | +julia> GrB_Matrix_dup(B, MAT) |
| 234 | +GrB_SUCCESS::GrB_Info = 0 |
| 235 | +
|
| 236 | +julia> @GxB_Matrix_fprint(B, GxB_SHORT) |
| 237 | +
|
| 238 | +GraphBLAS matrix: B |
| 239 | +nrows: 4 ncols: 4 max # entries: 5 |
| 240 | +format: standard CSR vlen: 4 nvec_nonempty: 3 nvec: 4 plen: 4 vdim: 4 |
| 241 | +hyper_ratio 0.0625 |
| 242 | +GraphBLAS type: int8_t size: 1 |
| 243 | +number of entries: 5 |
| 244 | +row: 1 : 1 entries [0:0] |
| 245 | + column 1: int8 2 |
| 246 | +row: 2 : 3 entries [1:3] |
| 247 | + column 1: int8 4 |
| 248 | + column 2: int8 3 |
| 249 | + column 3: int8 5 |
| 250 | +row: 3 : 1 entries [4:4] |
| 251 | + column 3: int8 6 |
| 252 | +
|
| 253 | +``` |
103 | 254 | """
|
104 | 255 | function GrB_Matrix_dup(C::GrB_Matrix, A::GrB_Matrix)
|
105 | 256 | C_ptr = pointer_from_objref(C)
|
|
118 | 269 | GrB_Matrix_clear(A)
|
119 | 270 |
|
120 | 271 | Remove all elements from a matrix.
|
| 272 | +
|
| 273 | +# Examples |
| 274 | +```jldoctest |
| 275 | +julia> using SuiteSparseGraphBLAS |
| 276 | +
|
| 277 | +julia> GrB_init(GrB_NONBLOCKING) |
| 278 | +GrB_SUCCESS::GrB_Info = 0 |
| 279 | +
|
| 280 | +julia> MAT = GrB_Matrix() |
| 281 | +GrB_Matrix |
| 282 | +
|
| 283 | +julia> GrB_Matrix_new(MAT, GrB_INT8, 4, 4) |
| 284 | +GrB_SUCCESS::GrB_Info = 0 |
| 285 | +
|
| 286 | +julia> I = [1, 2, 2, 2, 3]; J = [1, 2, 1, 3, 3]; X = Int8[2, 3, 4, 5, 6]; n = 5; |
| 287 | +
|
| 288 | +julia> GrB_Matrix_build(MAT, I, J, X, n, GrB_FIRST_INT8) |
| 289 | +GrB_SUCCESS::GrB_Info = 0 |
| 290 | +
|
| 291 | +julia> GrB_Matrix_nvals(MAT) |
| 292 | +5 |
| 293 | +
|
| 294 | +julia> GrB_Matrix_clear(MAT) |
| 295 | +GrB_SUCCESS::GrB_Info = 0 |
| 296 | +
|
| 297 | +julia> GrB_Matrix_nvals(MAT) |
| 298 | +0 |
| 299 | +``` |
121 | 300 | """
|
122 | 301 | function GrB_Matrix_clear(A::GrB_Matrix)
|
123 | 302 | return GrB_Info(
|
|
134 | 313 | GrB_Matrix_setElement(C, X, I, J)
|
135 | 314 |
|
136 | 315 | Set one element of a matrix to a given value, C[I][J] = X.
|
| 316 | +
|
| 317 | +# Examples |
| 318 | +```jldoctest |
| 319 | +julia> using SuiteSparseGraphBLAS |
| 320 | +
|
| 321 | +julia> GrB_init(GrB_NONBLOCKING) |
| 322 | +GrB_SUCCESS::GrB_Info = 0 |
| 323 | +
|
| 324 | +julia> MAT = GrB_Matrix() |
| 325 | +GrB_Matrix |
| 326 | +
|
| 327 | +julia> GrB_Matrix_new(MAT, GrB_INT8, 4, 4) |
| 328 | +GrB_SUCCESS::GrB_Info = 0 |
| 329 | +
|
| 330 | +julia> I = [1, 2, 2, 2, 3]; J = [1, 2, 1, 3, 3]; X = Int8[2, 3, 4, 5, 6]; n = 5; |
| 331 | +
|
| 332 | +
|
| 333 | +julia> GrB_Matrix_build(MAT, I, J, X, n, GrB_FIRST_INT8) |
| 334 | +GrB_SUCCESS::GrB_Info = 0 |
| 335 | +
|
| 336 | +julia> GrB_Matrix_extractElement(MAT, 1, 1) |
| 337 | +2 |
| 338 | +
|
| 339 | +julia> GrB_Matrix_setElement(MAT, Int8(7), 1, 1) |
| 340 | +GrB_SUCCESS::GrB_Info = 0 |
| 341 | +
|
| 342 | +julia> GrB_Matrix_extractElement(MAT, 1, 1) |
| 343 | +7 |
| 344 | +``` |
137 | 345 | """
|
138 | 346 | function GrB_Matrix_setElement(C::GrB_Matrix, X::T, I::U, J::U) where {U <: GrB_Index, T <: valid_int_types}
|
139 | 347 | fn_name = "GrB_Matrix_setElement_" * get_suffix(T)
|
|
176 | 384 |
|
177 | 385 | Return element of a vector at a given index (A[row_index][col_index]) if successful.
|
178 | 386 | Else return value of type GrB Info.
|
| 387 | +
|
| 388 | +# Examples |
| 389 | +```jldoctest |
| 390 | +julia> using SuiteSparseGraphBLAS |
| 391 | +
|
| 392 | +julia> GrB_init(GrB_NONBLOCKING) |
| 393 | +GrB_SUCCESS::GrB_Info = 0 |
| 394 | +
|
| 395 | +julia> MAT = GrB_Matrix() |
| 396 | +GrB_Matrix |
| 397 | +
|
| 398 | +julia> GrB_Matrix_new(MAT, GrB_INT8, 4, 4) |
| 399 | +GrB_SUCCESS::GrB_Info = 0 |
| 400 | +
|
| 401 | +julia> I = [1, 2, 2, 2, 3]; J = [1, 2, 1, 3, 3]; X = Int8[2, 3, 4, 5, 6]; n = 5; |
| 402 | +
|
| 403 | +julia> GrB_Matrix_build(MAT, I, J, X, n, GrB_FIRST_INT8) |
| 404 | +GrB_SUCCESS::GrB_Info = 0 |
| 405 | +
|
| 406 | +julia> GrB_Matrix_extractElement(MAT, 1, 1) |
| 407 | +2 |
| 408 | +``` |
179 | 409 | """
|
180 | 410 | function GrB_Matrix_extractElement(A::GrB_Matrix, row_index::U, col_index::U) where U <: GrB_Index
|
181 | 411 | res, A_type = GxB_Matrix_type(A)
|
|
200 | 430 | GrB_Matrix_extractTuples(A)
|
201 | 431 |
|
202 | 432 | Return tuples stored in a matrix.
|
| 433 | +
|
| 434 | +# Examples |
| 435 | +```jldoctest |
| 436 | +julia> using SuiteSparseGraphBLAS |
| 437 | +
|
| 438 | +julia> GrB_init(GrB_NONBLOCKING) |
| 439 | +GrB_SUCCESS::GrB_Info = 0 |
| 440 | +
|
| 441 | +julia> MAT = GrB_Matrix() |
| 442 | +GrB_Matrix |
| 443 | +
|
| 444 | +julia> GrB_Matrix_new(MAT, GrB_INT8, 4, 4) |
| 445 | +GrB_SUCCESS::GrB_Info = 0 |
| 446 | +
|
| 447 | +julia> I = [1, 2, 2, 2, 3]; J = [1, 2, 1, 3, 3]; X = Int8[2, 3, 4, 5, 6]; n = 5; |
| 448 | +
|
| 449 | +julia> GrB_Matrix_build(MAT, I, J, X, n, GrB_FIRST_INT8) |
| 450 | +GrB_SUCCESS::GrB_Info = 0 |
| 451 | +
|
| 452 | +julia> GrB_Matrix_extractTuples(MAT) |
| 453 | +([1, 2, 2, 2, 3], [1, 1, 2, 3, 3], Int8[2, 4, 3, 5, 6]) |
| 454 | +``` |
203 | 455 | """
|
204 | 456 | function GrB_Matrix_extractTuples(A::GrB_Matrix)
|
205 | 457 | res, A_type = GxB_Matrix_type(A)
|
|
0 commit comments