Skip to content

Commit 3a3c4cf

Browse files
committed
defragile umfpack, passes tests, diagonal ctors, few bugfixes
1 parent ebbf923 commit 3a3c4cf

File tree

11 files changed

+522
-460
lines changed

11 files changed

+522
-460
lines changed

src/abstractgbarray.jl

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -678,20 +678,33 @@ function LinearAlgebra.diag(A::AbstractGBMatrix{T}, k::Integer = 0; desc = nothi
678678
if A isa Transpose
679679
k = -k
680680
end
681-
@wraperror LibGraphBLAS.GxB_Vector_diag(LibGraphBLAS.GrB_Vector(v), parent(A), k, desc)
682-
return v
681+
@wraperror LibGraphBLAS.GxB_Vector_diag(v, parent(A), k, desc)
682+
return Vector(v)
683683
end
684684

685-
# This does not conform to the normal definition with a lazy wrapper.
686-
function LinearAlgebra.Diagonal(v::AbstractGBVector, k::Integer=0; desc = nothing)
687-
s = size(v, 1)
688-
C = GBMatrix{storedeltype(v)}(s, s; fill = v.fill)
685+
function GBDiagonal!(C::AbstractGBMatrix, v::AbstractGBVector, k::Integer=0; desc = nothing)
689686
desc = _handledescriptor(desc)
690-
# Switch ptr to a Vector to trick GraphBLAS.
691-
# This is allowed since GrB_Vector is a GrB_Matrix internally.
692-
@wraperror LibGraphBLAS.GxB_Matrix_diag(C, LibGraphBLAS.GrB_Vector(v.p[]), k, desc)
687+
@wraperror LibGraphBLAS.GxB_Matrix_diag(C, v, k, desc)
693688
return C
694689
end
690+
function GBDiagonal!(C::AbstractGBMatrix{T}, v::AbstractVector, k::Integer=0; desc = nothing) where T
691+
v2 = GBShallowVector(convert(DenseVector{T}, v))
692+
GBDiagonal!(C, v2, k; desc)
693+
end
694+
function GBDiagonal!(C::AbstractGBMatrix, D::Diagonal; desc = nothing)
695+
GBDiagonal!(C, D.diag; desc)
696+
end
697+
function GBDiagonal(v, k::Integer=0; desc = nothing)
698+
s = size(v, 1)
699+
C = GBMatrix{storedeltype(v)}(s, s; fill = defaultfill(storedeltype(v)))
700+
GBDiagonal!(C, v, k; desc)
701+
end
702+
function GBDiagonal(v::AbstractGBVector, k::Integer=0; desc = nothing)
703+
s = size(v, 1)
704+
C = GBMatrix{storedeltype(v)}(s, s; fill = getfill(v))
705+
GBDiagonal!(C, v, k; desc)
706+
end
707+
695708

696709
# Type dependent functions build, setindex, getindex, and findnz:
697710
for T valid_vec

src/operations/mul.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,15 @@ function Base.:*(rig::TypedSemiring)
188188
*(A, B, rig; mask, accum, desc)
189189
end
190190
end
191+
192+
# Diagonal
193+
function Base.:*(D::Diagonal, A::G) where
194+
{G <: Union{Transpose{T, <:SuiteSparseGraphBLAS.AbstractGBArray{T1, F, O}} where {T, T1, F, O},
195+
SuiteSparseGraphBLAS.AbstractGBArray{T, F, O, 2} where {T, F, O}}}
196+
return *(G(D), A)
197+
end
198+
function Base.:*(A::G, D::Diagonal) where
199+
{G <: Union{Transpose{T, <:SuiteSparseGraphBLAS.AbstractGBArray{T1, F, O}} where {T, T1, F, O},
200+
SuiteSparseGraphBLAS.AbstractGBArray{T, F, O, 2} where {T, F, O}}}
201+
return *(G(D), A)
202+
end

src/options.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Return the current sparsity of `A`, which is one of `Dense`,
103103
`Bitmap`, `Sparse`, or `Hypersparse`.
104104
"""
105105
function sparsitystatus(A::AbstractGBArray)
106+
wait(A) # We need to do this to ensure we're actually unpacking correctly.
106107
t = GBSparsity(gbget(A, SPARSITY_STATUS))
107108
return consttoshape(t)
108109
end

src/pack.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function _packcsrmatrix!(
120120
) where {T, Ti}
121121
if decrementindices && rowptr[begin] == 1
122122
decrement!(rowptr)
123-
decrement(colidx)
123+
decrement!(colidx)
124124
end
125125

126126
rowpointer = pointer(rowptr)
@@ -147,8 +147,8 @@ end
147147

148148
function _packhypermatrix!(
149149
A::AbstractGBArray{T}, ptr::Vector{Ti}, idx1::Vector{Ti}, idx2::Vector{Ti}, values::Vector{T};
150-
desc = nothing, order = ColMajor()
151-
) where {T}
150+
desc = nothing, order = ColMajor(), decrementindices = true
151+
) where {T, Ti}
152152
desc = _handledescriptor(desc)
153153
valsize = length(A) * sizeof(T)
154154
ptrsize = length(ptr) * sizeof(Ti)
@@ -160,7 +160,11 @@ function _packhypermatrix!(
160160
idx1pointer = Ref{Ptr{LibGraphBLAS.GrB_Index}}(pointer(idx1))
161161
idx2pointer = Ref{Ptr{LibGraphBLAS.GrB_Index}}(pointer(idx2))
162162
valpointer = Ref{Ptr{Cvoid}}(pointer(values))
163-
163+
if decrementindices
164+
decrement!(ptr)
165+
decrement!(idx1)
166+
decrement!(idx2)
167+
end
164168
if order === ColMajor()
165169
@wraperror LibGraphBLAS.GxB_Matrix_pack_HyperCSC(
166170
A,
@@ -241,7 +245,7 @@ function unsafepack!(
241245
A::AbstractGBArray, ptr, idx1, idx2, values, shallow::Bool = true;
242246
order = ColMajor(), decrementindices = true
243247
)
244-
_packhypermatrix!(A, ptr, idx1, idx2, values; decrementindices)
248+
_packhypermatrix!(A, ptr, idx1, idx2, values; order, decrementindices)
245249
shallow && makeshallow!(A)
246250
LibGraphBLAS.GxB_Matrix_Option_set(A, LibGraphBLAS.GxB_FORMAT, option_toconst(storageorder(A)))
247251
return A

src/shallowtypes.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# fall back to nzval, this may need to change eventually, as it's currently not possible to know the storage order.
22
# Either a new parameter or something else.
3-
function GBShallowVector(v::DenseVector{T}; fill::F = nothing) where {T, F}
3+
function GBShallowVector(v::DenseVector{T}; fill::F = defaultfill(T)) where {T, F}
44
m = _newGrBRef()
55
@wraperror LibGraphBLAS.GrB_Matrix_new(m, gbtype(T), size(v, 1), size(v, 2))
66
gbvec = GBShallowVector{T}(m, fill, Int64[], Int64[], Int64[], Bool[], v)
77
unsafepack!(gbvec, v, true)
88
end
99

10-
function GBShallowMatrix(M::StridedMatrix{T}; fill::F = nothing) where {T, F}
10+
function GBShallowMatrix(M::StridedMatrix{T}; fill::F = defaultfill(T)) where {T, F}
1111
m = _newGrBRef()
1212
@wraperror LibGraphBLAS.GrB_Matrix_new(m, gbtype(T), size(M)...)
1313
gbmat = GBShallowMatrix{T}(m, fill, Int64[], Int64[], Int64[], Bool[], M)
1414
unsafepack!(gbmat, M, true)
1515
end
1616

17-
function GBShallowVector(idx::DenseVector{I}, nzvals::DenseVector{T}, size; fill::F = nothing, decrementindices = true) where {I<:Integer, T, F}
17+
function GBShallowVector(idx::DenseVector{I}, nzvals::DenseVector{T}, size; fill::F = defaultfill(T), decrementindices = true) where {I<:Integer, T, F}
1818
I isa Integer && sizeo(I) == 8 || throw(ArgumentError("$I is not a 64 bit signed or unsigned Integer."))
1919
m = _newGrBRef()
2020
@wraperror LibGraphBLAS.GrB_Matrix_new(m, gbtype(T), size, 1)
@@ -27,15 +27,15 @@ GBShallowVector(v::SparseVector; fill = nothing, decrementindices = true) = retu
2727
fill, decrementindices
2828
)
2929

30-
function GBShallowMatrix(ptr::DenseVector{I}, idx::DenseVector{I}, nzvals::DenseVector{T}, nrows, ncols; fill::F = nothing, decrementindices = true) where {I<:Integer, T, F}
30+
function GBShallowMatrix(ptr::DenseVector{I}, idx::DenseVector{I}, nzvals::DenseVector{T}, nrows, ncols; fill::F = defaultfill(T), decrementindices = true) where {I<:Integer, T, F}
3131
I isa Integer && sizeo(I) == 8 || throw(ArgumentError("$I is not a 64 bit signed or unsigned Integer."))
3232
m = _newGrBRef()
3333
@wraperror LibGraphBLAS.GrB_Matrix_new(m, gbtype(T), nrows, ncols)
3434
gbmat = GBShallowMatrix{T}(m, fill, ptr, idx, Int64[], Bool[], nzvals)
3535
unsafepack!(gbmat, gbmat.ptr, gbmat.idx, gbmat.nzval, true; decrementindices)
3636
end
3737

38-
GBShallowMatrix(S::SparseMatrixCSC; fill = nothing, decrementindices = true) = GBShallowMatrix(
38+
GBShallowMatrix(S::SparseMatrixCSC{T}; fill = defaultfill(T), decrementindices = true) where T = GBShallowMatrix(
3939
S.colptr, S.rowval, s.nzval, size(S, 1), size(S, 2);
4040
fill, decrementindices
4141
)

0 commit comments

Comments
 (0)