Skip to content

Commit 312d5fa

Browse files
committed
add countstored
1 parent 7bef423 commit 312d5fa

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

src/operations/reduce.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,34 @@ Base.minimum(A::GBArrayOrTranspose) = reduce(min, A)
9090
Base.minimum(f::Function, A::GBArrayOrTranspose) = reduce(min, map(f, A))
9191

9292
Base.sum(A::GBArrayOrTranspose; dims=:) = reduce(+, A; dims)
93+
94+
function countstored!(
95+
C::GBVector, A::GBArrayOrTranspose;
96+
dims=1, mask = nothing, accum = nothing, desc = nothing
97+
)
98+
v=GBVector(size(A, dims), true)
99+
A = dims == 1 ? A' : dims == 2 ? A : throw(ArgumentError("dims ∉ {1, 2}"))
100+
return mul!(C, A, v, (+, pair); mask, accum, desc)
101+
end
102+
function countstored(
103+
A::GBArrayOrTranspose;
104+
dims=1, mask = nothing, accum = nothing, desc = nothing
105+
)
106+
v=GBVector(size(A, dims), true)
107+
countstored!(
108+
similar(A, Int64, size(A, dims == 1 ? 2 : 1)), A;
109+
dims, mask, accum, desc
110+
)
111+
end
112+
113+
function countstoredcol(A::GBArrayOrTranspose, i::Integer)
114+
mask = GBVector{Bool}(size(A, 2))
115+
mask[i] = true
116+
countstored(A; mask)[i]
117+
end
118+
119+
function countstoredrow(A::GBArrayOrTranspose, i::Integer)
120+
mask = GBVector{Bool}(size(A, 2))
121+
mask[i] = true
122+
countstored(A'; mask)[i]
123+
end

src/operators/binaryops.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ second(x, y) = y
144144
@binop any GxB_ANY T=>T # this doesn't match the semantics of Julia's any, but that may be ok...
145145

146146
pair(x::T, y::T) where T = one(T)
147+
pair(x::T, y::U) where {T, U} = promote_type(T, U)(true)
147148
@binop pair GrB_ONEB T=>T # I prefer pair, but to keep up with the spec I'll match...
148149
@binop (+) GrB_PLUS T=>T
149150
@binop (-) GrB_MINUS T=>T

src/types.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ macro gbmatrixtype(typename)
472472
$typename(dims::Dims{2}, x::T; fill = defaultfill(T)) where T =
473473
$typename{T}(dims, x, fill)
474474

475+
$typename{T}(nrows, ncols, x; fill::F = defaultfill(T)) where {T, F} =
476+
$typename{T, F}((nrows, ncols), x; fill)
475477
$typename(nrows, ncols, x::T; fill = defaultfill(T)) where T =
476478
$typename{T}((nrows, ncols), x; fill)
477479
$typename(dims::Tuple{<:Integer}, x::T; fill = defaultfill(T)) where T =
@@ -726,12 +728,14 @@ macro gbvectortype(typename)
726728
$typename(dims::Dims{1}, x::T; fill = defaultfill(T)) where T =
727729
$typename{T}(dims, x, fill)
728730

729-
$typename(nrows, ncols, x::T; fill = defaultfill(T)) where T =
730-
$typename{T}((nrows, ncols), x; fill)
731+
$typename{T}(nrows, x; fill = defaultfill(T)) where T =
732+
$typename{T}((nrows,), x; fill)
733+
$typename(nrows, x::T; fill = defaultfill(T)) where T =
734+
$typename{T}(nrows, x; fill)
731735
$typename(dims::Tuple{<:Integer}, x::T; fill = defaultfill(T)) where T =
732736
$typename{T}(dims..., x; fill)
733-
$typename(size::Tuple{Base.OneTo, Base.OneTo}, x::T; fill = defaultfill(T)) where T =
734-
$typename{T}(size[1].stop, size[2].stop, x; fill)
737+
$typename(size::Tuple{Base.OneTo}, x::T; fill = defaultfill(T)) where T =
738+
$typename{T}(size[1].stop, x; fill)
735739

736740
function $typename{T, F}(v::AbstractGBVector; fill = getfill(v)) where {T, F}
737741
return convert($typename{T, F}, v; fill)

0 commit comments

Comments
 (0)