@@ -43,6 +43,58 @@ function SparseArrays.SparseVector(v::GBVectorOrTranspose)
4343 return unpack! (T, SparseVector)
4444end
4545
46+ function reshape! (
47+ A:: AbstractGBMatrix , nrows, ncols;
48+ bycol:: Bool = true , desc = nothing
49+ )
50+ desc = _handledescriptor (desc)
51+ lenA = length (A)
52+ nrows isa Colon && ncols isa Colon && throw (
53+ ArgumentError (" nrows and ncols may not both be Colon" ))
54+ nrows isa Colon && (nrows = lenA ÷ ncols)
55+ ncols isa Colon && (ncols = lenA ÷ nrows)
56+ @wraperror LibGraphBLAS. GxB_Matrix_reshape (
57+ gbpointer (A), bycol, nrows, ncols, desc
58+ )
59+ return A
60+ end
61+ reshape! (A:: AbstractGBMatrix , dims... ; bycol = true ) =
62+ reshape! (A, dims... ; bycol)
63+ reshape! (A:: AbstractGBMatrix , n; bycol = true ) =
64+ reshape! (A, n, 1 ; bycol)
65+ function Base. reshape (
66+ A:: AbstractGBMatrix , nrows, ncols;
67+ bycol = true , desc = nothing )
68+ desc = _handledescriptor (desc)
69+ lenA = length (A)
70+ nrows isa Colon && ncols isa Colon && throw (
71+ ArgumentError (" nrows and ncols may not both be Colon" ))
72+ nrows isa Colon && (nrows = lenA ÷ ncols)
73+ ncols isa Colon && (ncols = lenA ÷ nrows)
74+ C = Ref {LibGraphBLAS.GrB_Matrix} ()
75+ @wraperror LibGraphBLAS. GxB_Matrix_reshapeDup (
76+ C, gbpointer (A),
77+ bycol, nrows, ncols, desc
78+ )
79+ # TODO , do better. This is ugly and allocates twice.
80+ out = similar (A)
81+ out. p = finalizer (C) do ref
82+ @wraperror LibGraphBLAS. GrB_Matrix_free (ref)
83+ end
84+ return out
85+ end
86+ Base. reshape (A:: AbstractGBMatrix , dims:: Tuple{Vararg{Int64, N}} ; bycol = true ) where N =
87+ reshape (A, dims... ; bycol)
88+ Base. reshape (A:: AbstractGBMatrix , dims:: Tuple{Vararg{Union{Colon, Int64}}} ; bycol = true ) =
89+ reshape (A, dims... ; bycol)
90+ Base. reshape (
91+ A:: AbstractGBMatrix ,
92+ dims:: Tuple{Union{Integer, Base.OneTo}, Vararg{Union{Integer, Base.OneTo}}} ;
93+ bycol = true
94+ ) = reshape (A, dims... ; bycol)
95+
96+ Base. reshape (A:: AbstractGBMatrix , n; bycol = true ) = reshape (A, n, 1 ; bycol)
97+
4698# AbstractGBMatrix functions:
4799# ############################
48100
0 commit comments