Skip to content

Commit 9cb9e55

Browse files
committed
init GBMatrixR, GBMatrixC
1 parent 40af13b commit 9cb9e55

File tree

1 file changed

+37
-14
lines changed

1 file changed

+37
-14
lines changed

src/oriented.jl

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,50 @@ StorageOrders.storageorder(::OrientedGBMatrix{T, F, O}) where {T, F, O} = O
1414
1515
Create a GBMatrix of the specified size, defaulting to the maximum on each dimension, 2^60.
1616
"""
17-
function OrientedGBMatrix{T, O}(nrows::Integer, ncols::Integer; fill::F = nothing) where {T, F, O}
17+
function OrientedGBMatrix{T, F, O}(nrows::Integer, ncols::Integer; fill::F = nothing) where {T, F, O}
1818
m = Ref{LibGraphBLAS.GrB_Matrix}()
1919
@wraperror LibGraphBLAS.GrB_Matrix_new(m, gbtype(T), nrows, ncols)
2020
A = GBMatrix{T, F}(finalizer(m) do ref
2121
@wraperror LibGraphBLAS.GrB_Matrix_free(ref)
2222
end, fill)
2323
gbset(A, :format, O === StorageOrders.ColMajor() ? :bycol : :byrow)
24+
return A
2425
end
26+
OrientedGBMatrix{T, O}(nrows::Integer, ncols::Integer; fill::F = nothing) where {T, F, O} = OrientedGBMatrix{T, F, O}(nrows, ncols; fill)
27+
GBMatrixC{T}(nrows::Integer, ncols::Integer; fill::F = nothing) where {T, F} = GBMatrixC{T, F}(nrows, ncols; fill)
28+
GBMatrixR{T}(nrows::Integer, ncols::Integer; fill::F = nothing) where {T, F} = GBMatrixR{T, F}(nrows, ncols; fill)
2529

26-
OrientedGBMatrix{T, O}(dims::Dims{2}; fill = nothing) where {T, O} = OrientedGBMatrix{T, O}(dims...; fill)
27-
OrientedGBMatrix{T, O}(dims::Tuple{<:Integer}; fill = nothing) where {T, O} = OrientedGBMatrix{T, O}(dims...; fill)
28-
OrientedGBMatrix{T, O}(size::Tuple{Base.OneTo, Base.OneTo}; fill = nothing) where {T, O} =
30+
OrientedGBMatrix{T, F, O}(dims::Dims{2}; fill::F = nothing) where {T, F, O} = OrientedGBMatrix{T, O}(dims...; fill)
31+
OrientedGBMatrix{T, F, O}(dims::Tuple{<:Integer}; fill::F = nothing) where {T, F, O} = OrientedGBMatrix{T, O}(dims...; fill)
32+
OrientedGBMatrix{T, F, O}(size::Tuple{Base.OneTo, Base.OneTo}; fill::F = nothing) where {T, F, O} =
2933
OrientedGBMatrix{T, O}(size[1].stop, size[2].stop; fill)
3034

35+
OrientedGBMatrix{T, O}(dims::Tuple; fill::F = nothing) where {T, F, O} = OrientedGBMatrix{T, F, O}(dims; fill)
36+
GBMatrixC{T}(dims::Tuple; fill::F = nothing) where {T, F} = GBMatrixC{T, F}(dims; fill)
37+
GBMatrixR{T}(dims::Tuple; fill::F = nothing) where {T, F} = GBMatrixR{T, F}(dims; fill)
3138
"""
3239
GBMatrix(I, J, X; combine = +, nrows = maximum(I), ncols = maximum(J))
3340
3441
Create an nrows x ncols GBMatrix M such that M[I[k], J[k]] = X[k]. The combine function defaults
3542
to `|` for booleans and `+` for nonbooleans.
3643
"""
37-
function OrientedGBMatrix{O}(
44+
function OrientedGBMatrix{T, F, O}(
3845
I::AbstractVector, J::AbstractVector, X::AbstractVector{T};
39-
combine = +, nrows = maximum(I), ncols = maximum(J), fill = nothing
40-
) where {T, O}
46+
combine = +, nrows = maximum(I), ncols = maximum(J), fill::F = nothing
47+
) where {T, F, O}
4148
I isa Vector || (I = collect(I))
4249
J isa Vector || (J = collect(J))
4350
X isa Vector || (X = collect(X))
4451
A = OrientedGBMatrix{T, O}(nrows, ncols; fill)
4552
build(A, I, J, X; combine)
4653
return A
4754
end
55+
function OrientedGBMatrix{O}(
56+
I::AbstractVecOrMat, J::AbstractVector, X::AbstractVector{T};
57+
combine = +, nrows = maximum(I), ncols = maximum(J), fill::F = nothing
58+
) where {T, F, O}
59+
return OrientedGBMatrix{T, F, O}(I, J, X,; combine, nrows, ncols, fill)
60+
end
4861

4962
#iso constructors
5063
"""
@@ -54,26 +67,36 @@ Create an nrows x ncols GBMatrix M such that M[I[k], J[k]] = x.
5467
The resulting matrix is "iso-valued" such that it only stores `x` once rather than once for
5568
each index.
5669
"""
57-
function OrientedGBMatrix{O}(I::AbstractVector, J::AbstractVector, x::T;
58-
nrows = maximum(I), ncols = maximum(J), fill = nothing) where {T, O}
59-
A = OrientedGBMatrix{T, O}(nrows, ncols; fill)
70+
function OrientedGBMatrix{T, F, O}(I::AbstractVector, J::AbstractVector, x::T;
71+
nrows = maximum(I), ncols = maximum(J), fill::F = nothing) where {T, F, O}
72+
A = OrientedGBMatrix{T, F, O}(nrows, ncols; fill)
6073
build(A, I, J, x)
6174
return A
6275
end
76+
OrientedGBMatrix{O}(I::AbstractVector, J::AbstractVector, x::T; nrows = maximum(I), ncols = maximum(J), fill::F = nothing) where {T, F, O} =
77+
OrientedGBMatrix{T, F, O}(I, J, x; nrows, ncols, fill)
6378

6479

65-
function OrientedGBMatrix{O}(dims::Dims{2}, x::T; fill = nothing) where {T, O}
66-
A = OrientedGBMatrix{T, O}(dims; fill)
80+
function OrientedGBMatrix{T, F, O}(dims::Dims{2}, x::T; fill::F = nothing) where {T, F, O}
81+
A = OrientedGBMatrix{T, F, O}(dims; fill)
6782
A[:, :] = x
6883
return A
6984
end
85+
OrientedGBMatrix{O}(dims::Dims{2}, x::T; fill::F = nothing) where {T, F, O} = OrientedGBMatrix{T, F, O}(dims, x; fill)
7086

71-
OrientedGBMatrix{O}(nrows, ncols, x::T; fill::F = nothing) where {T, F, O} = OrientedGBMatrix{O}((nrows, ncols), x; fill)
87+
OrientedGBMatrix{T, F, O}(nrows, ncols, x::T; fill::F = nothing) where {T, F, O} = OrientedGBMatrix{O}((nrows, ncols), x; fill)
88+
OrientedGBMatrix{O}(nrows, ncols, x::T; fill::F = nothing) where {T, F, O} = OrientedGBMatrix{T, F, O}(nrows, ncols, x; fill)
89+
90+
function OrientedGBMatrix{T, F, O}(v::GBVector) where {T, F, O}
91+
# this copies, I think that's ideal, and I can implement @view or something at a later date.
92+
return copy(OrientedGBMatrix{T, F, O}(v.p, v.fill))
93+
end
7294
function OrientedGBMatrix{O}(v::GBVector) where {O}
7395
# this copies, I think that's ideal, and I can implement @view or something at a later date.
74-
return copy(OrientedGBMatrix{eltype(v), typeof(v.fill), O}(v.p, v.fill))
96+
return OrientedGBMatrix{eltype(v), typeof(v.fill), O}(v)
7597
end
7698

99+
77100
Base.unsafe_convert(::Type{LibGraphBLAS.GrB_Matrix}, A::OrientedGBMatrix) = A.p[]
78101

79102
function Base.copy(A::OrientedGBMatrix{T, F, O}) where {T, F, O}

0 commit comments

Comments
 (0)