Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace hard-coded truncate! threshold with the epsilon value of the chain's eltype #220

Merged
merged 5 commits into from
Oct 18, 2024

Conversation

jofrevalles
Copy link
Member

Summary

This PR modifies the previously hard-coded threshold inside the truncate! function, which was fixed to 1e-16, to the proper epsilon value of the chain's eltype, making it more flexible and general.

@jofrevalles
Copy link
Member Author

jofrevalles commented Oct 18, 2024

Now everything seems to work fine:

julia> using Tenet

julia> A = Tensor(rand(Float32, 2, 2), (:i, :j))
2×2 Tensor{Float32, 2, Matrix{Float32}}:
 0.252758  0.719538
 0.417894  0.9425

julia> B = Tensor(rand(Float32, 2, 2), (:k, :j))
2×2 Tensor{Float32, 2, Matrix{Float32}}:
 0.802961  0.219748
 0.143793  0.835135

julia> tn = TensorNetwork([A, B])
TensorNetwork (#tensors=2, #inds=3)

julia> Tenet.wrap_eps(eltype(tn))
1.1920929f-7

julia> A = Tensor(rand(ComplexF64, 2, 2), (:i, :j))
2×2 Tensor{ComplexF64, 2, Matrix{ComplexF64}}:
 0.500145+0.230456im   0.644049+0.482663im
 0.599711+0.0412583im    0.7519+0.889049im

julia> B = Tensor(rand(ComplexF64, 2, 2), (:k, :j))
2×2 Tensor{ComplexF64, 2, Matrix{ComplexF64}}:
 0.0460109+0.810682im   0.55873+0.698605im
   0.58918+0.183138im  0.733106+0.15675im

julia> tn = TensorNetwork([A, B])
TensorNetwork (#tensors=2, #inds=3)

julia> Tenet.wrap_eps(eltype(tn))
2.220446049250313e-16

@jofrevalles jofrevalles requested a review from mofeing October 18, 2024 13:14
src/Helpers.jl Outdated Show resolved Hide resolved
@jofrevalles jofrevalles merged commit ce9c1a2 into master Oct 18, 2024
6 checks passed
@jofrevalles jofrevalles deleted the feature/truncate branch October 18, 2024 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants