@@ -21,7 +21,7 @@ function OrientedGBMatrix{T, F, O}(nrows::Integer, ncols::Integer; fill::F = not
2121 @wraperror LibGraphBLAS. GrB_Matrix_free (ref)
2222 end , fill)
2323 gbset (A, :format , O === StorageOrders. ColMajor () ? :bycol : :byrow )
24- return A
24+ return OrientedGBMatrix {T, F, O} (A)
2525end
2626OrientedGBMatrix {T, O} (nrows:: Integer , ncols:: Integer ; fill:: F = nothing ) where {T, F, O} = OrientedGBMatrix {T, F, O} (nrows, ncols; fill)
2727GBMatrixC {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}(
5353 return A
5454end
5555function OrientedGBMatrix {O} (
56- I:: AbstractVecOrMat , J:: AbstractVector , X:: AbstractVector{T} ;
56+ I:: AbstractVector , J:: AbstractVector , X:: AbstractVector{T} ;
5757 combine = + , nrows = maximum (I), ncols = maximum (J), fill:: F = nothing
5858) where {T, F, O}
5959 return OrientedGBMatrix {T, F, O} (I, J, X,; combine, nrows, ncols, fill)
6060end
6161
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+
6273# iso constructors
6374"""
6475 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}
8899OrientedGBMatrix {O} (nrows, ncols, x:: T ; fill:: F = nothing ) where {T, F, O} = OrientedGBMatrix {T, F, O} (nrows, ncols, x; fill)
89100
90101function OrientedGBMatrix {T, F, O} (v:: GBVector ) where {T, F, O}
102+ O === ByRow () && throw (ArgumentError (" Cannot wrap a GBVector in a ByRow matrix." ))
91103 # this copies, I think that's ideal, and I can implement @view or something at a later date.
92104 return copy (OrientedGBMatrix {T, F, O} (v. p, v. fill))
93105end
@@ -96,6 +108,27 @@ function OrientedGBMatrix{O}(v::GBVector) where {O}
96108 return OrientedGBMatrix {eltype(v), typeof(v.fill), O} (v)
97109end
98110
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)
99132
100133Base. unsafe_convert (:: Type{LibGraphBLAS.GrB_Matrix} , A:: OrientedGBMatrix ) = A. p[]
101134
@@ -147,4 +180,14 @@ function Base.similar(
147180 dim1:: Integer , dim2:: Integer ; fill = parent (A). fill
148181) where {T}
149182 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
150193end
0 commit comments