Skip to content

Commit 4085bb9

Browse files
author
Will Kimmerer
committed
dup => combine
1 parent e43098e commit 4085bb9

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

src/matrix.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ GBMatrix{T}(size::Tuple{Base.OneTo, Base.OneTo}) where {T} =
1717
GBMatrix{T}(size[1].stop, size[2].stop)
1818

1919
"""
20-
GBMatrix(I, J, X; dup = +, nrows = maximum(I), ncols = maximum(J))
20+
GBMatrix(I, J, X; combine = +, nrows = maximum(I), ncols = maximum(J))
2121
22-
Create an nrows x ncols GBMatrix M such that M[I[k], J[k]] = X[k]. The dup function defaults
22+
Create an nrows x ncols GBMatrix M such that M[I[k], J[k]] = X[k]. The combine function defaults
2323
to `|` for booleans and `+` for nonbooleans.
2424
"""
2525
function GBMatrix(
2626
I::AbstractVector, J::AbstractVector, X::AbstractVector{T};
27-
dup = +, nrows = maximum(I), ncols = maximum(J)
27+
combine = +, nrows = maximum(I), ncols = maximum(J)
2828
) where {T}
2929
A = GBMatrix{T}(nrows, ncols)
30-
build(A, I, J, X; dup)
30+
build(A, I, J, X; combine)
3131
return A
3232
end
3333

@@ -161,9 +161,9 @@ for T ∈ valid_vec
161161
func = Symbol(prefix, :_Matrix_build_, suffix(T))
162162
@eval begin
163163
function build(A::GBMatrix{$T}, I::AbstractVector, J::AbstractVector, X::Vector{$T};
164-
dup = +
164+
combine = +
165165
)
166-
dup = BinaryOp(dup)($T)
166+
combine = BinaryOp(combine)($T)
167167
if !(I isa Vector)
168168
I = Vector(I)
169169
end
@@ -181,7 +181,7 @@ for T ∈ valid_vec
181181
Vector{LibGraphBLAS.GrB_Index}(J),
182182
X,
183183
length(X),
184-
dup
184+
combine
185185
)
186186
increment!(I)
187187
increment!(J)
@@ -274,6 +274,7 @@ function Base.getindex(
274274
return extract(A, i, j; mask, accum, desc)
275275
end
276276

277+
# Linear indexing
277278
function Base.getindex(A::GBMatOrTranspose, v::AbstractVector)
278279
throw("Not implemented")
279280
end

src/unpack.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ function _unpackcscmatrix!(A::GBVecOrMat{T}; desc = nothing) where {T}
3535
isjumbled,
3636
desc
3737
)
38-
colptr = unsafe_wrap(Array{LibGraphBLAS.GrB_Index}, colptr[], colptrsize[] ÷ sizeof(LibGraphBLAS.GrB_Index))
38+
#TODO IMPROVE
39+
# colptrsize isn't always exact. Or rather it can be bigger if GrB has allocated a bigger block.
40+
# For now I'll unsafe_wrap based on size(A, 2) + 1
41+
colptr = unsafe_wrap(Array{LibGraphBLAS.GrB_Index}, colptr[], size(A, 2) + 1)
3942
rowidx = unsafe_wrap(Array{LibGraphBLAS.GrB_Index}, rowidx[], rowidxsize[] ÷ sizeof(LibGraphBLAS.GrB_Index))
4043
colptr .+= 1
4144
rowidx .+= 1
@@ -66,7 +69,10 @@ function _unpackcsrmatrix!(A::GBVecOrMat{T}; desc = nothing) where {T}
6669
isjumbled,
6770
desc
6871
)
69-
rowptr = unsafe_wrap(Array{LibGraphBLAS.GrB_Index}, rowptr[], rowptrsize[] ÷ sizeof(LibGraphBLAS.GrB_Index))
72+
#TODO IMPROVE
73+
# rowptrsize isn't always exact. Or rather it can be bigger if GrB has allocated a bigger block.
74+
# For now I'll unsafe_wrap based on size(A, 1) + 1
75+
rowptr = unsafe_wrap(Array{LibGraphBLAS.GrB_Index}, rowptr[],size(A, 1) + 1)
7076
colidx = unsafe_wrap(Array{LibGraphBLAS.GrB_Index}, colidx[], colidxsize[] ÷ sizeof(LibGraphBLAS.GrB_Index))
7177
rowptr .+= 1
7278
colidx .+= 1

src/vector.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ GBVector{T}(nrows::Tuple{Base.OneTo,}) where {T} = GBVector{T}(first(nrows))
2121
2222
Create a GBVector from a vector of indices `I` and a vector of values `X`.
2323
"""
24-
function GBVector(I::AbstractVector{U}, X::AbstractVector{T}; dup = +, nrows = maximum(I)) where {U<:Integer, T}
24+
function GBVector(I::AbstractVector{U}, X::AbstractVector{T}; combine = +, nrows = maximum(I)) where {U<:Integer, T}
2525
x = GBVector{T}(nrows)
26-
build(x, I, X, dup = dup)
26+
build(x, I, X, combine = combine)
2727
return x
2828
end
2929

@@ -139,18 +139,18 @@ for T ∈ valid_vec
139139
# Build functions
140140
func = Symbol(prefix, :_Matrix_build_, suffix(T))
141141
@eval begin
142-
function build(v::GBVector{$T}, I::Vector, X::Vector{$T}; dup = +)
142+
function build(v::GBVector{$T}, I::Vector, X::Vector{$T}; combine = +)
143143
nnz(v) == 0 || throw(OutputNotEmptyError("Cannot build vector with existing elements"))
144144
length(X) == length(I) || DimensionMismatch("I and X must have the same length")
145-
dup = BinaryOp(dup)($T)
145+
combine = BinaryOp(combine)($T)
146146
decrement!(I)
147147
@wraperror LibGraphBLAS.$func(
148148
Ptr{LibGraphBLAS.GrB_Vector}(v.p),
149149
Vector{LibGraphBLAS.GrB_Index}(I),
150150
zeros(LibGraphBLAS.GrB_Index, length(I)),
151151
X,
152152
length(X),
153-
dup
153+
combine
154154
)
155155
increment!(I)
156156
end

0 commit comments

Comments
 (0)