From eb438c6c93963e45899351c3e5d505472a1233d4 Mon Sep 17 00:00:00 2001 From: GiggleLiu Date: Mon, 26 Feb 2024 02:13:16 +0800 Subject: [PATCH] fix tess --- src/PermMatrix.jl | 1 + src/conversions.jl | 2 +- src/linalg.jl | 2 +- test/PermMatrix.jl | 3 +++ test/PermMatrixCSC.jl | 3 +++ 5 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/PermMatrix.jl b/src/PermMatrix.jl index ab3bc73..3a492a0 100644 --- a/src/PermMatrix.jl +++ b/src/PermMatrix.jl @@ -162,6 +162,7 @@ function Base.show(io::IO, M::AbstractPermMatrix) end end end +Base.hash(pm::AbstractPermMatrix) = hash((pm.perm, pm.vals)) ######### sparse array interfaces ######### nnz(M::AbstractPermMatrix) = length(M.vals) diff --git a/src/conversions.jl b/src/conversions.jl index a4f167c..767d3a5 100644 --- a/src/conversions.jl +++ b/src/conversions.jl @@ -96,7 +96,7 @@ end function PermMatrixCSC{Tv,Ti}(A::AbstractMatrix) where {Tv,Ti} i, j, v = _findnz(A) j == collect(1:size(A, 2)) || throw(ArgumentError("This is not a PermMatrix")) - PermMatrix{Tv,Ti}(Vector{Ti}(i), Vector{Tv}(v)) + PermMatrixCSC{Tv,Ti}(Vector{Ti}(i), Vector{Tv}(v)) end for MT in [:PermMatrix, :PermMatrixCSC] diff --git a/src/linalg.jl b/src/linalg.jl index cf696cb..a8836cd 100644 --- a/src/linalg.jl +++ b/src/linalg.jl @@ -94,7 +94,7 @@ end function Base.:*(A::PermMatrixCSC, B::PermMatrixCSC) @assert basetype(A) == basetype(B) size(A, 1) == size(B, 1) || throw(DimensionMismatch()) - basetype(A)(A.perm[B.perm], B.vals .* view(A.vals, B.perm)) + basetype(A)(A.perm[B.perm], [B.vals[i] * A.vals[B.perm[i]] for i in 1:size(A, 1)]) end # to matrix diff --git a/test/PermMatrix.jl b/test/PermMatrix.jl index f5479a3..2c1d14e 100644 --- a/test/PermMatrix.jl +++ b/test/PermMatrix.jl @@ -14,6 +14,8 @@ v = [0.5, 0.3im, 0.2, 1.0] @testset "basic" begin @test p1 == copy(p1) + @test hash(p1) == hash(copy(p1)) + @test hash(p1) != hash(p2) @test eltype(p1) == ComplexF64 @test eltype(p2) == Float64 @test eltype(p3) == Float64 @@ -29,6 +31,7 @@ v = [0.5, 0.3im, 0.2, 1.0] @test p1[1, 1] === 0.1 + 0.0im copyto!(p0, p1) @test p0 == p1 + @test PermMatrix([0.0 -1.0im; 1.0im 0.0im]) ≈ [0.0 -1.0im; 1.0im 0.0im] end @testset "linalg" begin diff --git a/test/PermMatrixCSC.jl b/test/PermMatrixCSC.jl index 24bc2a0..db794fe 100644 --- a/test/PermMatrixCSC.jl +++ b/test/PermMatrixCSC.jl @@ -14,6 +14,8 @@ v = [0.5, 0.3im, 0.2, 1.0] @testset "basic" begin @test p1 == copy(p1) + @test hash(p1) == hash(copy(p1)) + @test hash(p1) != hash(p2) @test eltype(p1) == ComplexF64 @test eltype(p2) == Float64 @test eltype(p3) == Float64 @@ -29,6 +31,7 @@ v = [0.5, 0.3im, 0.2, 1.0] @test p1[1, 1] === 0.1 + 0.0im copyto!(p0, p1) @test p0 == p1 + @test PermMatrix([0.0 -1.0im; 1.0im 0.0im]) ≈ [0.0 -1.0im; 1.0im 0.0im] end @testset "linalg" begin