@@ -21,7 +21,7 @@ function OrientedGBMatrix{T, F, O}(nrows::Integer, ncols::Integer; fill::F = not
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
+ return OrientedGBMatrix {T, F, O} (A)
25
25
end
26
26
OrientedGBMatrix {T, O} (nrows:: Integer , ncols:: Integer ; fill:: F = nothing ) where {T, F, O} = OrientedGBMatrix {T, F, O} (nrows, ncols; fill)
27
27
GBMatrixC {T} (nrows:: Integer , ncols:: Integer ; fill:: F = nothing ) where {T, F} = GBMatrixC {T, F} (nrows, ncols; fill)
@@ -53,12 +53,23 @@ function OrientedGBMatrix{T, F, O}(
53
53
return A
54
54
end
55
55
function OrientedGBMatrix {O} (
56
- I:: AbstractVecOrMat , J:: AbstractVector , X:: AbstractVector{T} ;
56
+ I:: AbstractVector , J:: AbstractVector , X:: AbstractVector{T} ;
57
57
combine = + , nrows = maximum (I), ncols = maximum (J), fill:: F = nothing
58
58
) where {T, F, O}
59
59
return OrientedGBMatrix {T, F, O} (I, J, X,; combine, nrows, ncols, fill)
60
60
end
61
61
62
+
63
+ GBMatrixC (
64
+ I:: AbstractVector , J:: AbstractVector , X:: AbstractVector ;
65
+ combine = + , nrows = maximum (I), ncols = maximum (J), fill = nothing
66
+ ) = OrientedGBMatrix {ColMajor()} (I, J, X; combine, nrows, ncols, fill)
67
+ GBMatrixR (
68
+ I:: AbstractVector , J:: AbstractVector , X:: AbstractVector ;
69
+ combine = + , nrows = maximum (I), ncols = maximum (J), fill = nothing
70
+ ) = OrientedGBMatrix {RowMajor()} (I, J, X; combine, nrows, ncols, fill)
71
+
72
+
62
73
# iso constructors
63
74
"""
64
75
GBMatrix(I, J, x; nrows = maximum(I), ncols = maximum(J))
@@ -88,6 +99,7 @@ OrientedGBMatrix{T, F, O}(nrows, ncols, x::T; fill::F = nothing) where {T, F, O}
88
99
OrientedGBMatrix {O} (nrows, ncols, x:: T ; fill:: F = nothing ) where {T, F, O} = OrientedGBMatrix {T, F, O} (nrows, ncols, x; fill)
89
100
90
101
function OrientedGBMatrix {T, F, O} (v:: GBVector ) where {T, F, O}
102
+ O === ByRow () && throw (ArgumentError (" Cannot wrap a GBVector in a ByRow matrix." ))
91
103
# this copies, I think that's ideal, and I can implement @view or something at a later date.
92
104
return copy (OrientedGBMatrix {T, F, O} (v. p, v. fill))
93
105
end
@@ -96,6 +108,27 @@ function OrientedGBMatrix{O}(v::GBVector) where {O}
96
108
return OrientedGBMatrix {eltype(v), typeof(v.fill), O} (v)
97
109
end
98
110
111
+ function OrientedGBMatrix {T, F, O} (A:: AbstractGBMatrix ) where {T, F, O}
112
+ storageorder (A) != O && throw (ArgumentError (" Cannot wrap a GBMatrix in an OrientedGBMatrix with a different orientation." ))
113
+ # this copies, I think that's ideal, and I can implement @view or something at a later date.
114
+ return copy (OrientedGBMatrix {T, F, O} (A. p, A. fill))
115
+ end
116
+ function OrientedGBMatrix {O} (A:: AbstractGBMatrix ) where {O}
117
+ # this copies, I think that's ideal, and I can implement @view or something at a later date.
118
+ return OrientedGBMatrix {eltype(A), typeof(A.fill), O} (A)
119
+ end
120
+
121
+ GBMatrixR (A:: AbstractGBMatrix ) = OrientedGBMatrix {RowMajor()} (A)
122
+ GBMatrixC (A:: AbstractGBMatrix ) = OrientedGBMatrix {ColMajor()} (A)
123
+
124
+ GBMatrixC (
125
+ I:: AbstractVector , J:: AbstractVector , X:: T ;
126
+ nrows = maximum (I), ncols = maximum (J), fill = nothing
127
+ ) where {T} = OrientedGBMatrix {ColMajor()} (I, J, X; nrows, ncols, fill)
128
+ GBMatrixR (
129
+ I:: AbstractVector , J:: AbstractVector , X:: T ;
130
+ nrows = maximum (I), ncols = maximum (J), fill = nothing
131
+ ) where {T} = OrientedGBMatrix {RowMajor()} (I, J, X; nrows, ncols, fill)
99
132
100
133
Base. unsafe_convert (:: Type{LibGraphBLAS.GrB_Matrix} , A:: OrientedGBMatrix ) = A. p[]
101
134
@@ -147,4 +180,14 @@ function Base.similar(
147
180
dim1:: Integer , dim2:: Integer ; fill = parent (A). fill
148
181
) where {T}
149
182
return similar (A, (dim1, dim2); fill)
183
+ end
184
+
185
+ function gbset (A:: OrientedGBMatrix , option, value)
186
+ if option === :format
187
+ throw (ArgumentError (" Cannot change orientation of an OrientedGBMatrix" ))
188
+ end
189
+ option = option_toconst (option)
190
+ value = option_toconst (value)
191
+ GxB_Matrix_Option_set (A, option, value)
192
+ return nothing
150
193
end
0 commit comments