From 255227789a55e73b7d150228f7c66d72038c3b0d Mon Sep 17 00:00:00 2001 From: youdongguo <1010705897@qq.com> Date: Tue, 15 Aug 2023 14:01:35 -0500 Subject: [PATCH] equal comparison between NMF.Results and hash of NMF.Results --- src/common.jl | 5 +++++ test/utils.jl | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/common.jl b/src/common.jl index 819fc1c..bbabbf6 100644 --- a/src/common.jl +++ b/src/common.jl @@ -33,6 +33,11 @@ struct Result{T} end end + +Base.:(==)(A::Result, B::Result) = A.W == B.W && A.H == B.H && A.niters == B.niters && A.converged == B.converged && A.objvalue == B.objvalue +Base.hash(s::Result, h::UInt) = hash(s.objvalue, hash(s.converged, hash(s.niters, hash(s.H, hash(s.W, h + (0x09c9f08cfcba6de3 % UInt)))))) + + # common algorithmic skeleton for iterative updating methods abstract type NMFUpdater{T} end diff --git a/test/utils.jl b/test/utils.jl index f69aabb..632b839 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -61,4 +61,10 @@ Xr = zeros(4, 5) NMF.pdrsolve!(Y, B, Xr) @test Xr ≈ X + + X, Wg, Hg = laurberg6x3(0.3) + Xnmf = NMF.solve!(NMF.CoordinateDescent{Float64}(α=0.0, maxiter=1000, tol=1e-9), X, Wg, Hg) + Xnmf1 = deepcopy(Xnmf) + @test Xnmf == Xnmf1 + @test hash(Xnmf) == hash(Xnmf1) end