From 5db443a65d2790b1b64ac218e05175827801e492 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Thu, 10 Aug 2023 17:20:39 -0400 Subject: [PATCH] test: remove SparseArrays dependency from hashing test (#50751) These tests now belong in SparseArrays, since it is removed from Base. Since SparseArrays does some piracy, that can break or distort later tests. Refs #50550 --- test/hashing.jl | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/test/hashing.jl b/test/hashing.jl index 8146edafea130..7c3024640aa32 100644 --- a/test/hashing.jl +++ b/test/hashing.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license -using Random, LinearAlgebra, SparseArrays +using Random, LinearAlgebra isdefined(Main, :OffsetArrays) || @eval Main include("testhelpers/OffsetArrays.jl") using .Main.OffsetArrays @@ -92,9 +92,8 @@ vals = Any[ Dict(x => x for x in 1:10), Dict(7=>7,9=>9,4=>4,10=>10,2=>2,3=>3,8=>8,5=>5,6=>6,1=>1), [], [1], [2], [1, 1], [1, 2], [1, 3], [2, 2], [1, 2, 2], [1, 3, 3], - zeros(2, 2), spzeros(2, 2), Matrix(1.0I, 2, 2), sparse(1.0I, 2, 2), - sparse(fill(1., 2, 2)), fill(1., 2, 2), sparse([0 0; 1 0]), [0 0; 1 0], - [-0. 0; -0. 0.], SparseMatrixCSC(2, 2, [1, 3, 3], [1, 2], [-0., -0.]), + zeros(2, 2), Matrix(1.0I, 2, 2), fill(1., 2, 2), + [-0. 0; -0. 0.], # issue #16364 1:4, 1:1:4, 1:-1:0, 1.0:4.0, 1.0:1.0:4.0, range(1, stop=4, length=4), # issue #35597, when `LinearIndices` does not begin at 1 @@ -141,13 +140,6 @@ vals = Any[ [5 1; 0 0], [1 1; 0 1], [0 2; 3 0], [0 2; 4 6], [4 0; 0 1], [0 0 0; 0 0 0], [1 0 0; 0 0 1], [0 0 2; 3 0 0], [0 0 7; 6 1 2], [4 0 0; 3 0 1], [0 2 4; 6 0 0], - # various stored zeros patterns - sparse([1], [1], [0]), sparse([1], [1], [-0.0]), - sparse([1, 2], [1, 1], [-0.0, 0.0]), sparse([1, 2], [1, 1], [0.0, -0.0]), - sparse([1, 2], [1, 1], [-0.0, 0.0], 3, 1), sparse([1, 2], [1, 1], [0.0, -0.0], 3, 1), - sparse([1, 3], [1, 1], [-0.0, 0.0], 3, 1), sparse([1, 3], [1, 1], [0.0, -0.0], 3, 1), - sparse([1, 2, 3], [1, 1, 1], [-1, 0, 1], 3, 1), sparse([1, 2, 3], [1, 1, 1], [-1.0, -0.0, 1.0], 3, 1), - sparse([1, 3], [1, 1], [-1, 0], 3, 1), sparse([1, 2], [1, 1], [-1, 0], 3, 1) ] for a in vals @@ -155,7 +147,6 @@ for a in vals @test hash(convert(Array{Any}, a)) == hash(b) @test hash(convert(Array{supertype(eltype(a))}, a)) == hash(b) @test hash(convert(Array{Float64}, a)) == hash(b) - @test hash(sparse(a)) == hash(b) if !any(x -> isequal(x, -0.0), a) @test hash(convert(Array{Int}, a)) == hash(b) if all(x -> typemin(Int8) <= x <= typemax(Int8), a) @@ -169,20 +160,6 @@ end @test hash(Any[Int8(127), Int8(-128), 129, 130]) == hash([127, -128, 129, 130]) != hash([127, 128, 129, 130]) -# Test hashing sparse matrix with type which does not support - -struct CustomHashReal - x::Float64 -end -Base.hash(x::CustomHashReal, h::UInt) = hash(x.x, h) -Base.:(==)(x::CustomHashReal, y::Number) = x.x == y -Base.:(==)(x::Number, y::CustomHashReal) = x == y.x -Base.zero(::Type{CustomHashReal}) = CustomHashReal(0.0) -Base.zero(x::CustomHashReal) = zero(CustomHashReal) - -let a = sparse([CustomHashReal(0), CustomHashReal(3), CustomHashReal(3)]) - @test hash(a) == hash(Array(a)) -end - vals = Any[ 0.0:0.1:0.3, 0.3:-0.1:0.0, 0:-1:1, 0.0:-1.0:1.0, 0.0:1.1:10.0, -4:10,