Skip to content

Commit 7b342e7

Browse files
committed
initial serialization support
1 parent 15bf9c4 commit 7b342e7

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

Project.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
1212
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
1313
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1414
SSGraphBLAS_jll = "7ed9a814-9cab-54e9-8e9e-d9e95b4d61b1"
15+
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
1516
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1617
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
1718
StorageOrders = "e9177fbf-8fde-426c-9425-4eed0f22262a"
1819
SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
1920

2021
[compat]
2122
ChainRulesCore = "1"
23+
HyperSparseMatrices = "0.2"
2224
MacroTools = "0.5"
2325
Preferences = "1"
2426
SSGraphBLAS_jll = "6.2.1"
2527
SpecialFunctions = "2"
26-
julia = "1.6"
27-
HyperSparseMatrices = "0.2"
2828
StorageOrders = "0.2"
29+
julia = "1.6"

src/SuiteSparseGraphBLAS.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ using LinearAlgebra
2121
using Random: randsubseq, default_rng, AbstractRNG, GLOBAL_RNG
2222
using SpecialFunctions: lgamma, gamma, erf, erfc
2323
using Base.Broadcast
24+
using Serialization
2425
include("abstracts.jl")
2526
include("libutils.jl")
2627

@@ -91,6 +92,7 @@ include("asjulia.jl")
9192
# include("spmgb/sparsemat.jl")
9293
include("mmread.jl")
9394
include("iterator.jl")
95+
include("serialization.jl")
9496

9597
export SparseArrayCompat
9698
export LibGraphBLAS

src/serialization.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function Serialization.serialize(s::AbstractSerializer, A::GBVecOrMat)
2+
Serialization.writetag(s.io, Serialization.OBJECT_TAG)
3+
Serialization.serialize(s, typeof(A))
4+
Serialization.serialize(s, A.fill)
5+
v = Vector{UInt8}(undef, serialize_sizehint(A))
6+
sz = Ref{LibGraphBLAS.GrB_Index}()
7+
@wraperror LibGraphBLAS.GrB_Matrix_serialize(v, sz, gbpointer(A))
8+
resize!(v, sz[])
9+
serialize(s, v)
10+
return nothing
11+
end
12+
13+
function Serialization.deserialize(s::AbstractSerializer, ::Type{GBMatrix{T, Tf}}) where {T, Tf}
14+
fill = deserialize(s)
15+
refA = Ref{LibGraphBLAS.GrB_Matrix}() # GrB will take care of size and such.
16+
v = deserialize(s)
17+
@wraperror LibGraphBLAS.GrB_Matrix_deserialize(refA, gbtype(T), v, LibGraphBLAS.GrB_Index(length(v)))
18+
A = GBMatrix{T, Tf}(refA[], fill)
19+
return A
20+
end
21+
22+
function serialize_sizehint(A::GBVecOrMat)
23+
sz = Ref{LibGraphBLAS.GrB_Index}()
24+
@wraperror LibGraphBLAS.GrB_Matrix_serializeSize(sz, gbpointer(A))
25+
return sz[]
26+
end
27+

0 commit comments

Comments
 (0)