From 11e7aeb7680968e064e2c100b19fe4e86f459b6a Mon Sep 17 00:00:00 2001 From: jofrevalles Date: Fri, 18 Oct 2024 13:34:08 +0200 Subject: [PATCH 1/5] Modify truncate threshold with the epsilon value of the chain eltype --- src/Ansatz/Chain.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ansatz/Chain.jl b/src/Ansatz/Chain.jl index bc7332728..89ed56bc6 100644 --- a/src/Ansatz/Chain.jl +++ b/src/Ansatz/Chain.jl @@ -393,7 +393,7 @@ function truncate!(qtn::Chain, bond; threshold::Union{Nothing,Real}=nothing, max # remove 0s from spectrum if isnothing(threshold) - threshold = 1e-16 + threshold = eps(eltype(qtn)) end filter!(extent) do i From bc75395fc865f36e0dd7620bc250891a5e4eb850 Mon Sep 17 00:00:00 2001 From: jofrevalles Date: Fri, 18 Oct 2024 15:13:21 +0200 Subject: [PATCH 2/5] Add wrap_eps function --- src/Ansatz/Chain.jl | 2 +- src/Helpers.jl | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Ansatz/Chain.jl b/src/Ansatz/Chain.jl index 89ed56bc6..72d80b237 100644 --- a/src/Ansatz/Chain.jl +++ b/src/Ansatz/Chain.jl @@ -393,7 +393,7 @@ function truncate!(qtn::Chain, bond; threshold::Union{Nothing,Real}=nothing, max # remove 0s from spectrum if isnothing(threshold) - threshold = eps(eltype(qtn)) + threshold = wrap_eps(eltype(qtn)) end filter!(extent) do i diff --git a/src/Helpers.jl b/src/Helpers.jl index e819032b0..ff19416cb 100644 --- a/src/Helpers.jl +++ b/src/Helpers.jl @@ -44,3 +44,7 @@ function nextindex!(gen::IndexCounter) return letter(Threads.atomic_add!(gen.counter, 1)) end resetindex!(gen::IndexCounter) = letter(Threads.atomic_xchg!(gen.counter, 1)) + +# eps wrapper so it handles Complex numbers +# if is Complex, extract the parametric type and get the eps of that +wrap_eps(eltype) = eltype <: Real ? eps(eltype) : eps(first(eltype.parameters)) From a204a95616cea9f26264ae1fd61b9094105b6adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jofre=20Vall=C3=A8s=20Muns?= <61060572+jofrevalles@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:30:31 +0200 Subject: [PATCH 3/5] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sergio Sánchez Ramírez <15837247+mofeing@users.noreply.github.com> --- src/Helpers.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Helpers.jl b/src/Helpers.jl index ff19416cb..9f3cce5b6 100644 --- a/src/Helpers.jl +++ b/src/Helpers.jl @@ -47,4 +47,5 @@ resetindex!(gen::IndexCounter) = letter(Threads.atomic_xchg!(gen.counter, 1)) # eps wrapper so it handles Complex numbers # if is Complex, extract the parametric type and get the eps of that -wrap_eps(eltype) = eltype <: Real ? eps(eltype) : eps(first(eltype.parameters)) +wrap_eps(x) = eps(x) +wrap_eps(::Type{Complex{T}}) = eps(T) From f598ed6bd77dda583eda65fcc911da7c2760fcd1 Mon Sep 17 00:00:00 2001 From: jofrevalles Date: Fri, 18 Oct 2024 15:49:18 +0200 Subject: [PATCH 4/5] Fix code from commit suggestion --- src/Helpers.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Helpers.jl b/src/Helpers.jl index 9f3cce5b6..5f6e660ef 100644 --- a/src/Helpers.jl +++ b/src/Helpers.jl @@ -48,4 +48,4 @@ resetindex!(gen::IndexCounter) = letter(Threads.atomic_xchg!(gen.counter, 1)) # eps wrapper so it handles Complex numbers # if is Complex, extract the parametric type and get the eps of that wrap_eps(x) = eps(x) -wrap_eps(::Type{Complex{T}}) = eps(T) +wrap_eps(::Type{Complex{T}}) where T = eps(T) From d137cf7a874f9a7b0b8f409edbb8e5a81a9049ef Mon Sep 17 00:00:00 2001 From: jofrevalles Date: Fri, 18 Oct 2024 15:52:53 +0200 Subject: [PATCH 5/5] Format code --- src/Helpers.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Helpers.jl b/src/Helpers.jl index 5f6e660ef..05be5be6f 100644 --- a/src/Helpers.jl +++ b/src/Helpers.jl @@ -48,4 +48,4 @@ resetindex!(gen::IndexCounter) = letter(Threads.atomic_xchg!(gen.counter, 1)) # eps wrapper so it handles Complex numbers # if is Complex, extract the parametric type and get the eps of that wrap_eps(x) = eps(x) -wrap_eps(::Type{Complex{T}}) where T = eps(T) +wrap_eps(::Type{Complex{T}}) where {T} = eps(T)