Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lay groundwork for Vector transition, etc #75

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ChainRulesCore = "1"
HyperSparseMatrices = "0.2"
MacroTools = "0.5"
Preferences = "1"
SSGraphBLAS_jll = "6.2.1"
SSGraphBLAS_jll = "7.1.0"
SpecialFunctions = "2"
StorageOrders = "0.2"
julia = "1.6"
5 changes: 2 additions & 3 deletions src/SuiteSparseGraphBLAS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ else
end

using SparseArrays
using SparseArrays: nonzeroinds
using SparseArrays: nonzeroinds, getcolptr, getrowval, getnzval, rowvals
using MacroTools
using LinearAlgebra
using Random: randsubseq, default_rng, AbstractRNG, GLOBAL_RNG
Expand All @@ -33,6 +33,7 @@ include("libutils.jl")
include("lib/LibGraphBLAS_gen.jl")
using .LibGraphBLAS

include("mem.jl")
include("operators/libgbops.jl")

include("gbtypes.jl")
Expand Down Expand Up @@ -77,7 +78,6 @@ include("operations/resize.jl")
include("operations/sort.jl")
#
include("print.jl")
include("import.jl")
include("pack.jl")
include("unpack.jl")
include("options.jl")
Expand All @@ -95,7 +95,6 @@ include("serialization.jl")

#EXPERIMENTAL
include("misc.jl")
include("asjulia.jl")
include("mmread.jl")
# include("iterator.jl")
include("oriented.jl")
Expand Down
101 changes: 66 additions & 35 deletions src/abstractgbarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,43 @@ Does not modify the type or dimensions.
"""
Base.empty!(A::AbsGBArrayOrTranspose) = @wraperror LibGraphBLAS.GrB_Matrix_clear(gbpointer(parent(A))); return nothing

# TODO: with cheatmalloc we can move from 2x copies -> 1x copy.
# Currently this function copies A to avoid modifying the sparsity of A and
function Base.Matrix(A::AbstractGBMatrix)
sparsity = sparsitystatus(A)
T = sparsity === Dense() ? A : copy(A) # If A is not dense we need to copy to avoid densifying
x = unpack!(T, Dense())
C = copy(x)
pack!(T, x; copytoraw = false)
return C
end

function Base.Vector(v::AbstractGBVector)
sparsity = sparsitystatus(v)
T = sparsity === Dense() ? v : copy(v) # If A is not dense we need to copy to avoid densifying
x = unpack!(T, Dense())
C = copy(x)
pack!(T, x; copytoraw = false)
return C
end

function SparseArrays.SparseMatrixCSC(A::AbstractGBArray)
sparsity = sparsitystatus(A)
T = sparsity === Sparse() ? A : copy(A)
x = unpack!(T, SparseMatrixCSC)
C = copy(x)
pack!(T, x; copytoraw = false)
return C
end

function SparseArrays.SparseVector(v::AbstractGBVector)
sparsity = sparsitystatus(v)
T = sparsity === Sparse() ? A : copy(A)
x = unpack!(T, SparseVector)
C = copy(x)
pack!(T, x; copytoraw = false)
return C
end
# AbstractGBMatrix functions:
#############################

Expand Down Expand Up @@ -247,21 +284,16 @@ for T ∈ valid_vec
return x
end
end
# TODO: Update when upstream.
# this is less than ideal. But required for isstored.
# a new version of graphBLAS will replace this with Matrix_extractElement_Structural
func = Symbol(prefix, :_Matrix_extractElement_, suffix(T))
@eval begin
function Base.isstored(A::AbstractGBMatrix{$T}, i::Int, j::Int)
result = LibGraphBLAS.$func(Ref{$T}(), gbpointer(A), decrement!(i), decrement!(j))
if result == LibGraphBLAS.GrB_SUCCESS
true
elseif result == LibGraphBLAS.GrB_NO_VALUE
false
else
@wraperror result
end
end
end

function Base.isstored(A::AbstractGBMatrix, i::Int, j::Int)
result = LibGraphBLAS.GxB_Matrix_isStoredElement(gbpointer(A), decrement!(i), decrement!(j))
if result == LibGraphBLAS.GrB_SUCCESS
true
elseif result == LibGraphBLAS.GrB_NO_VALUE
false
else
@wraperror result
end
end

Expand All @@ -276,19 +308,6 @@ function _assign(C::AbstractGBMatrix{T}, x::T, I, ni, J, nj, mask, accum, desc)
@wraperror LibGraphBLAS.GrB_Matrix_assign_UDT(C, mask, accum, in, I, ni, J, nj, desc)
return x
end
# TODO: Update when upstream.
# this is less than ideal. But required for isstored.
# a new version of graphBLAS will replace this with Matrix_extractElement_Structural
function Base.isstored(A::AbstractGBMatrix{T}, i::Int, j::Int) where {T}
result = LibGraphBLAS.GrB_Matrix_extractElement_UDT(Ref{T}(), gbpointer(A), decrement!(i), decrement!(j))
if result == LibGraphBLAS.GrB_SUCCESS
true
elseif result == LibGraphBLAS.GrB_NO_VALUE
false
else
@wraperror result
end
end


# subassign fallback for Matrix <- Matrix, and Matrix <- Vector
Expand Down Expand Up @@ -317,7 +336,7 @@ Assign a submatrix of `A` to `C`. Equivalent to [`assign!`](@ref) except that
- `GrB_DIMENSION_MISMATCH`: If `size(A) != (max(I), max(J))` or `size(A) != size(mask)`.
"""
function subassign!(
C::AbstractGBMatrix, A::GBArray, I, J;
C::AbstractGBMatrix, A::AbstractGBArray, I, J;
mask = nothing, accum = nothing, desc = nothing
)
I, ni = idx(I)
Expand Down Expand Up @@ -346,14 +365,15 @@ function subassign!(C::AbstractGBArray{T}, x, I, J;
_subassign(C, x, I, ni, J, nj, mask, getaccum(accum, eltype(C)), desc)
increment!(I)
increment!(J)
return C
return x
end

function subassign!(C::AbstractGBArray, x::AbstractArray, I, J;
mask = nothing, accum = nothing, desc = nothing)
as(GBMatrix, x) do array
subassign!(C, array, I, J; mask, accum, desc)
end
array = pack!(GBMatrix, x; copytoraw=false)
subassign!(C, array, I, J; mask, accum, desc)
unpack!(array)
return C
end

"""
Expand Down Expand Up @@ -381,7 +401,7 @@ Assign a submatrix of `A` to `C`. Equivalent to [`subassign!`](@ref) except that
- `GrB_DIMENSION_MISMATCH`: If `size(A) != (max(I), max(J))` or `size(C) != size(mask)`.
"""
function assign!(
C::AbstractGBMatrix, A::AbstractGBVector, I, J;
C::AbstractGBMatrix, A::AbstractGBArray, I, J;
mask = nothing, accum = nothing, desc = nothing
)
I, ni = idx(I)
Expand Down Expand Up @@ -409,7 +429,7 @@ function assign!(C::AbstractGBArray, x, I, J;
_assign(gbpointer(C), x, I, ni, J, nj, mask, getaccum(accum, eltype(C)), desc)
increment!(I)
increment!(J)
return C
return x
end

function Base.setindex!(
Expand Down Expand Up @@ -561,6 +581,17 @@ for T ∈ valid_vec
end
end

function Base.isstored(v::AbstractGBVector, i::Int)
result = LibGraphBLAS.GxB_Matrix_isStoredElement(gbpointer(v), decrement!(i), 0)
if result == LibGraphBLAS.GrB_SUCCESS
true
elseif result == LibGraphBLAS.GrB_NO_VALUE
false
else
@wraperror result
end
end

# UDT versions of Vector functions, which just require one def of each.

function build(v::AbstractGBVector{T}, I::Vector{<:Integer}, X::Vector{T}; combine = +) where {T}
Expand Down
132 changes: 0 additions & 132 deletions src/asjulia.jl

This file was deleted.

Loading