Skip to content

Commit d565180

Browse files
committed
fix stackoverflow on 1.10+
1 parent d5da04a commit d565180

File tree

6 files changed

+61
-105
lines changed

6 files changed

+61
-105
lines changed

src/abstractgbarray.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,45 @@ function Base.similar(
113113
return similar(A, (dim1, dim2); fill)
114114
end
115115

116+
function Base.similar(
117+
A::AbstractGBArray,
118+
dims::Tuple{Int64, Vararg{Int64, N}} = size(A); fill::F = getfill(A)
119+
) where {N, F}
120+
return similar(A, eltype(A), dims; fill)
121+
end
122+
123+
function Base.similar(A::AbstractGBArray{T}, dims::Tuple; fill = getfill(A)) where T
124+
return similar(A, T, dims; fill)
125+
end
126+
127+
function Base.similar(
128+
A::AbstractGBArray, ::Type{TNew},
129+
dims::Integer; fill = getfill(A)
130+
) where TNew
131+
return similar(A, TNew, (dims,); fill)
132+
end
133+
134+
function Base.similar(
135+
A::AbstractGBArray, ::Type{TNew},
136+
dim1::Integer, dim2::Integer; fill = getfill(A)
137+
) where TNew
138+
return similar(A, TNew, (dim1, dim2); fill)
139+
end
140+
141+
function Base.similar(
142+
A::AbstractGBArray,
143+
dims::Integer; fill = getfill(A)
144+
)
145+
return similar(A, (dims,); fill)
146+
end
147+
148+
function Base.similar(
149+
A::AbstractGBArray,
150+
dim1::Integer, dim2::Integer; fill = getfill(A)
151+
)
152+
return similar(A, (dim1, dim2); fill)
153+
end
154+
116155
"""
117156
empty!(A::AbstractGBArray)
118157

src/operations/mul.jl

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -129,23 +129,10 @@ end
129129

130130
# clear up some ambiguities:
131131
function Base.:*(
132-
A::AbstractGBVector{T},
133-
B::Transpose{T, <:AbstractGBVector{T}};
134-
mask = nothing,
135-
accum = nothing,
136-
desc = nothing
132+
A::Transpose{<:T, <:GBVector},
133+
B::GBVector{T}
137134
) where {T <: Real}
138-
return *(A, B, (+, *); mask, accum, desc)
139-
end
140-
141-
function Base.:*(
142-
A::Transpose{T, <:AbstractGBVector{T}},
143-
B::AbstractGBVector{T};
144-
mask = nothing,
145-
accum = nothing,
146-
desc = nothing
147-
) where {T <: Real}
148-
return *(A, B, (+, *); mask, accum, desc)
135+
return *(A, B, (+, *))
149136
end
150137

151138
function Base.:*(
@@ -208,4 +195,4 @@ function Base.:*(A::G, D::Diagonal, op = (+, *); mask = nothing, accum = nothing
208195
{G <: Union{Transpose{T, <:SuiteSparseGraphBLAS.AbstractGBArray{T1, F, O}} where {T, T1, F, O},
209196
SuiteSparseGraphBLAS.AbstractGBArray{T, F, O, 2} where {T, F, O}}}
210197
return *(A, G(D), op; mask, accum, desc)
211-
end
198+
end

src/shallowtypes.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@ function Base.similar(
5757
::Type{TNew}, dims::Tuple{Int64, Vararg{Int64, N}} = size(A);
5858
fill = A.fill
5959
) where {T, TNew, N}
60-
return GBMatrix{TNew}(dims...; fill)
60+
if dims isa Dims{1}
61+
# TODO: When new Vector types are added this will be incorrect.
62+
x = GBVector{TNew}(dims...; fill)
63+
else
64+
x = GBMatrix{TNew}(dims...; fill)
65+
end
66+
_hasconstantorder(x) || setstorageorder!(x, storageorder(A))
67+
return x
6168
end
6269

6370
function Base.similar(
@@ -97,4 +104,4 @@ Base.resize!(::GBShallowMatrix, nrows, ncols) = throw(ShallowException())
97104
Base.resize!(::GBShallowVector, nrows) = throw(ShallowException())
98105
build!(::GBShallowMatrix{T}, I::AbstractVector, J::AbstractVector, x::T) where T = throw(ShallowException())
99106

100-
LinearAlgebra.Diagonal(v::GBShallowVector) = Diagonal(copy(v))
107+
LinearAlgebra.Diagonal(v::GBShallowVector) = Diagonal(copy(v))

src/types.jl

Lines changed: 7 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -588,44 +588,14 @@ macro gbmatrixtype(typename)
588588
if dims isa Dims{1}
589589
# TODO: When new Vector types are added this will be incorrect.
590590
x = GBVector{TNew}(dims...; fill)
591+
elseif $typename <: AbstractGBVector
592+
x = GBMatrix{TNew}(dims...; fill)
591593
else
592594
x = $typename{TNew}(dims...; fill)
593-
_hasconstantorder(x) || setstorageorder!(x, storageorder(A))
594595
end
596+
_hasconstantorder(x) || setstorageorder!(x, storageorder(A))
595597
return x
596598
end
597-
598-
function Base.similar(A::$typename{T}, dims::Tuple; fill = getfill(A)) where T
599-
return similar(A, T, dims; fill)
600-
end
601-
602-
function Base.similar(
603-
A::$typename, ::Type{TNew},
604-
dims::Integer; fill = getfill(A)
605-
) where TNew
606-
return similar(A, TNew, (dims,); fill)
607-
end
608-
609-
function Base.similar(
610-
A::$typename, ::Type{TNew},
611-
dim1::Integer, dim2::Integer; fill = getfill(A)
612-
) where TNew
613-
return similar(A, TNew, (dim1, dim2); fill)
614-
end
615-
616-
function Base.similar(
617-
A::$typename,
618-
dims::Integer; fill = getfill(A)
619-
)
620-
return similar(A, (dims,); fill)
621-
end
622-
623-
function Base.similar(
624-
A::$typename,
625-
dim1::Integer, dim2::Integer; fill = getfill(A)
626-
)
627-
return similar(A, (dim1, dim2); fill)
628-
end
629599
strip_parameters(::Type{<:$typename}) = $typename
630600
end)
631601
end
@@ -779,54 +749,20 @@ macro gbvectortype(typename)
779749
A::SparseVector{T};
780750
fill::F = defaultfill(T)
781751
) where {T, F} = $typename{T, F}(A; fill)
782-
783-
# similar
784752
function Base.similar(
785753
v::$typename{T}, ::Type{TNew} = T,
786754
dims::Tuple{Int64, Vararg{Int64, N}} = size(v); fill::F = getfill(v)
787755
) where {T, TNew, N, F}
788756
!(F <: Union{Nothing, Missing}) && (fill = convert(TNew, fill))
789757
if dims isa Dims{1}
790-
# TODO: Check this for correctness!!!
758+
# TODO: When new Vector types are added this will be incorrect.
791759
x = $typename{TNew}(dims...; fill)
792760
else
793-
x = $GBMatrix{TNew}(dims...; fill)
794-
_hasconstantorder(x) || setstorageorder!(x, storageorder(v))
761+
x = GBMatrix{TNew}(dims...; fill)
795762
end
763+
_hasconstantorder(x) || setstorageorder!(x, storageorder(v))
796764
return x
797765
end
798-
799-
function Base.similar(v::$typename{T}, dims::Tuple; fill = getfill(v)) where T
800-
return similar(v, T, dims; fill)
801-
end
802-
803-
function Base.similar(
804-
v::$typename, ::Type{TNew},
805-
dims::Integer; fill = getfill(v)
806-
) where TNew
807-
return similar(v, TNew, (dims,); fill)
808-
end
809-
810-
function Base.similar(
811-
v::$typename, ::Type{TNew},
812-
dim1::Integer, dim2::Integer; fill = getfill(v)
813-
) where TNew
814-
return similar(v, TNew, (dim1, dim2); fill)
815-
end
816-
817-
function Base.similar(
818-
v::$typename,
819-
dims::Integer; fill = getfill(v)
820-
)
821-
return similar(v, (dims,); fill)
822-
end
823-
824-
function Base.similar(
825-
v::$typename,
826-
dim1::Integer, dim2::Integer; fill = getfill(v)
827-
)
828-
return similar(v, (dim1, dim2); fill)
829-
end
830766
# misc utilities:
831767
strip_parameters(::Type{<:$typename}) = $typename
832768
end)
@@ -1050,4 +986,4 @@ defaultfill(::Type{Missing}) = missing
1050986
# I don't think it is onerous for graph algorithm writers to say `GBMatrix{Int64, Nothing}`,
1051987
# and provides better defaults for other users.
1052988
defaultfill(::Type{Union{T, Nothing}}) where T = T
1053-
defaultfill(::Type{Union{T, Missing}}) where T = T
989+
defaultfill(::Type{Union{T, Missing}}) where T = T

test/runtests.jl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,6 @@ function ChainRulesTestUtils.rand_tangent(
3535
end
3636

3737
# Inefficient, but doesn't matter, only doing small matrices
38-
function FiniteDifferences.to_vec(M::SparseMatrixCSC)
39-
x, back = FiniteDifferences.to_vec(Matrix(M))
40-
function backtomat(xvec)
41-
M2 = back(xvec)
42-
M_out = copy(M)
43-
nz = findnz(M_out)
44-
for j nz[1], i nz[2]
45-
M_out[i,j] = M2[i, j]
46-
end
47-
return M_out
48-
end
49-
return x, backtomat
50-
end
5138
function FiniteDifferences.to_vec(M::SparseVector)
5239
x, back = FiniteDifferences.to_vec(Vector(M))
5340
function backtovec(xvec)

test/types.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ for type ∈ [GBMatrix, GBMatrixC, GBMatrixR]
1313
@test getfill(A) === 3
1414
type === GBMatrixC && (@test storageorder(A) === ColMajor())
1515
type === GBMatrixR && (@test storageorder(A) === RowMajor())
16-
@test_throws MethodError type{Int64, Nothing}(3, 3; fill = 3)
16+
@test_throws Exception type{Int64, Nothing}(3, 3; fill = 3) # TODO: better error message?
1717
@test type{Int64, Nothing}(3, 3; fill = nothing) isa type
1818

1919
# <type>{T}(nrows, ncols; fill)
@@ -27,4 +27,4 @@ for type ∈ [GBMatrix, GBMatrixC, GBMatrixR]
2727

2828
# <type>{T, F}()
2929
end
30-
end
30+
end

0 commit comments

Comments
 (0)