@@ -14,37 +14,50 @@ StorageOrders.storageorder(::OrientedGBMatrix{T, F, O}) where {T, F, O} = O
14
14
15
15
Create a GBMatrix of the specified size, defaulting to the maximum on each dimension, 2^60.
16
16
"""
17
- function OrientedGBMatrix {T, O} (nrows:: Integer , ncols:: Integer ; fill:: F = nothing ) where {T, F, O}
17
+ function OrientedGBMatrix {T, F, O} (nrows:: Integer , ncols:: Integer ; fill:: F = nothing ) where {T, F, O}
18
18
m = Ref {LibGraphBLAS.GrB_Matrix} ()
19
19
@wraperror LibGraphBLAS. GrB_Matrix_new (m, gbtype (T), nrows, ncols)
20
20
A = GBMatrix {T, F} (finalizer (m) do ref
21
21
@wraperror LibGraphBLAS. GrB_Matrix_free (ref)
22
22
end , fill)
23
23
gbset (A, :format , O === StorageOrders. ColMajor () ? :bycol : :byrow )
24
+ return A
24
25
end
26
+ OrientedGBMatrix {T, O} (nrows:: Integer , ncols:: Integer ; fill:: F = nothing ) where {T, F, O} = OrientedGBMatrix {T, F, O} (nrows, ncols; fill)
27
+ GBMatrixC {T} (nrows:: Integer , ncols:: Integer ; fill:: F = nothing ) where {T, F} = GBMatrixC {T, F} (nrows, ncols; fill)
28
+ GBMatrixR {T} (nrows:: Integer , ncols:: Integer ; fill:: F = nothing ) where {T, F} = GBMatrixR {T, F} (nrows, ncols; fill)
25
29
26
- OrientedGBMatrix {T, O} (dims:: Dims{2} ; fill = nothing ) where {T, O} = OrientedGBMatrix {T, O} (dims... ; fill)
27
- OrientedGBMatrix {T, O} (dims:: Tuple{<:Integer} ; fill = nothing ) where {T, O} = OrientedGBMatrix {T, O} (dims... ; fill)
28
- OrientedGBMatrix {T, O} (size:: Tuple{Base.OneTo, Base.OneTo} ; fill = nothing ) where {T, O} =
30
+ OrientedGBMatrix {T, F, O} (dims:: Dims{2} ; fill:: F = nothing ) where {T, F , O} = OrientedGBMatrix {T, O} (dims... ; fill)
31
+ OrientedGBMatrix {T, F, O} (dims:: Tuple{<:Integer} ; fill:: F = nothing ) where {T, F , O} = OrientedGBMatrix {T, O} (dims... ; fill)
32
+ OrientedGBMatrix {T, F, O} (size:: Tuple{Base.OneTo, Base.OneTo} ; fill:: F = nothing ) where {T, F , O} =
29
33
OrientedGBMatrix {T, O} (size[1 ]. stop, size[2 ]. stop; fill)
30
34
35
+ OrientedGBMatrix {T, O} (dims:: Tuple ; fill:: F = nothing ) where {T, F, O} = OrientedGBMatrix {T, F, O} (dims; fill)
36
+ GBMatrixC {T} (dims:: Tuple ; fill:: F = nothing ) where {T, F} = GBMatrixC {T, F} (dims; fill)
37
+ GBMatrixR {T} (dims:: Tuple ; fill:: F = nothing ) where {T, F} = GBMatrixR {T, F} (dims; fill)
31
38
"""
32
39
GBMatrix(I, J, X; combine = +, nrows = maximum(I), ncols = maximum(J))
33
40
34
41
Create an nrows x ncols GBMatrix M such that M[I[k], J[k]] = X[k]. The combine function defaults
35
42
to `|` for booleans and `+` for nonbooleans.
36
43
"""
37
- function OrientedGBMatrix {O} (
44
+ function OrientedGBMatrix {T, F, O} (
38
45
I:: AbstractVector , J:: AbstractVector , X:: AbstractVector{T} ;
39
- combine = + , nrows = maximum (I), ncols = maximum (J), fill = nothing
40
- ) where {T, O}
46
+ combine = + , nrows = maximum (I), ncols = maximum (J), fill:: F = nothing
47
+ ) where {T, F, O}
41
48
I isa Vector || (I = collect (I))
42
49
J isa Vector || (J = collect (J))
43
50
X isa Vector || (X = collect (X))
44
51
A = OrientedGBMatrix {T, O} (nrows, ncols; fill)
45
52
build (A, I, J, X; combine)
46
53
return A
47
54
end
55
+ function OrientedGBMatrix {O} (
56
+ I:: AbstractVecOrMat , J:: AbstractVector , X:: AbstractVector{T} ;
57
+ combine = + , nrows = maximum (I), ncols = maximum (J), fill:: F = nothing
58
+ ) where {T, F, O}
59
+ return OrientedGBMatrix {T, F, O} (I, J, X,; combine, nrows, ncols, fill)
60
+ end
48
61
49
62
# iso constructors
50
63
"""
@@ -54,26 +67,36 @@ Create an nrows x ncols GBMatrix M such that M[I[k], J[k]] = x.
54
67
The resulting matrix is "iso-valued" such that it only stores `x` once rather than once for
55
68
each index.
56
69
"""
57
- function OrientedGBMatrix {O} (I:: AbstractVector , J:: AbstractVector , x:: T ;
58
- nrows = maximum (I), ncols = maximum (J), fill = nothing ) where {T, O}
59
- A = OrientedGBMatrix {T, O} (nrows, ncols; fill)
70
+ function OrientedGBMatrix {T, F, O} (I:: AbstractVector , J:: AbstractVector , x:: T ;
71
+ nrows = maximum (I), ncols = maximum (J), fill:: F = nothing ) where {T, F , O}
72
+ A = OrientedGBMatrix {T, F, O} (nrows, ncols; fill)
60
73
build (A, I, J, x)
61
74
return A
62
75
end
76
+ OrientedGBMatrix {O} (I:: AbstractVector , J:: AbstractVector , x:: T ; nrows = maximum (I), ncols = maximum (J), fill:: F = nothing ) where {T, F, O} =
77
+ OrientedGBMatrix {T, F, O} (I, J, x; nrows, ncols, fill)
63
78
64
79
65
- function OrientedGBMatrix {O} (dims:: Dims{2} , x:: T ; fill = nothing ) where {T, O}
66
- A = OrientedGBMatrix {T, O} (dims; fill)
80
+ function OrientedGBMatrix {T, F, O} (dims:: Dims{2} , x:: T ; fill:: F = nothing ) where {T, F , O}
81
+ A = OrientedGBMatrix {T, F, O} (dims; fill)
67
82
A[:, :] = x
68
83
return A
69
84
end
85
+ OrientedGBMatrix {O} (dims:: Dims{2} , x:: T ; fill:: F = nothing ) where {T, F, O} = OrientedGBMatrix {T, F, O} (dims, x; fill)
70
86
71
- OrientedGBMatrix {O} (nrows, ncols, x:: T ; fill:: F = nothing ) where {T, F, O} = OrientedGBMatrix {O} ((nrows, ncols), x; fill)
87
+ OrientedGBMatrix {T, F, O} (nrows, ncols, x:: T ; fill:: F = nothing ) where {T, F, O} = OrientedGBMatrix {O} ((nrows, ncols), x; fill)
88
+ OrientedGBMatrix {O} (nrows, ncols, x:: T ; fill:: F = nothing ) where {T, F, O} = OrientedGBMatrix {T, F, O} (nrows, ncols, x; fill)
89
+
90
+ function OrientedGBMatrix {T, F, O} (v:: GBVector ) where {T, F, O}
91
+ # this copies, I think that's ideal, and I can implement @view or something at a later date.
92
+ return copy (OrientedGBMatrix {T, F, O} (v. p, v. fill))
93
+ end
72
94
function OrientedGBMatrix {O} (v:: GBVector ) where {O}
73
95
# this copies, I think that's ideal, and I can implement @view or something at a later date.
74
- return copy ( OrientedGBMatrix {eltype(v), typeof(v.fill), O} (v. p, v . fill) )
96
+ return OrientedGBMatrix {eltype(v), typeof(v.fill), O} (v)
75
97
end
76
98
99
+
77
100
Base. unsafe_convert (:: Type{LibGraphBLAS.GrB_Matrix} , A:: OrientedGBMatrix ) = A. p[]
78
101
79
102
function Base. copy (A:: OrientedGBMatrix{T, F, O} ) where {T, F, O}
0 commit comments