@@ -34,15 +34,24 @@ function to_fusiontensor(
3434 return to_fusiontensor (blockarray, codomain_legs, domain_legs)
3535end
3636
37- get_tol (a:: AbstractArray ) = get_tol (real (eltype (a)))
38- get_tol (T:: Type{<:Integer} ) = get_tol (Float64)
39- get_tol (T:: Type{<:Real} ) = 10 * eps (T)
37+ rtoldefault (a:: AbstractArray ) = rtoldefault (eltype (a))
38+ rtoldefault (arrayt:: Type{<:AbstractArray} ) = rtoldefault (eltype (arrayt))
39+ rtoldefault (elt:: Type{<:Number} ) = 10 * eps (real (float (elt)))
40+
41+ function checknorm (ft:: FusionTensor , a:: AbstractArray , atol:: Real , rtol:: Real )
42+ return isapprox (norm (ft), norm (a); atol= atol, rtol= rtol) || throw (
43+ InexactError (
44+ :FusionTensor , typeof (a), typeof (codomain_axes (ft)), typeof (domain_axes (ft))
45+ ),
46+ )
47+ end
4048
4149function to_fusiontensor (
4250 blockarray:: AbstractBlockArray ,
4351 codomain_legs:: Tuple{Vararg{AbstractGradedUnitRange}} ,
4452 domain_legs:: Tuple{Vararg{AbstractGradedUnitRange}} ;
45- tol:: Real = get_tol (blockarray),
53+ atol:: Real = 0 ,
54+ rtol:: Real = rtoldefault (blockarray),
4655)
4756 # input validation
4857 if length (codomain_legs) + length (domain_legs) != ndims (blockarray) # compile time
@@ -55,19 +64,7 @@ function to_fusiontensor(
5564 ft = to_fusiontensor_no_checknorm (blockarray, codomain_legs, domain_legs)
5665
5766 # if blockarray is not G-invariant, norm(ft) < norm(blockarray)
58- checknorm (ft, blockarray, tol)
59- return ft
60- end
61-
62- function checknorm (ft:: FusionTensor , a:: AbstractArray , tol:: Real )
63- n0 = norm (a)
64- if abs (norm (ft) - n0) > tol * n0
65- throw (
66- InexactError (
67- :FusionTensor , typeof (a), typeof (codomain_axes (ft)), typeof (domain_axes (ft))
68- ),
69- )
70- end
67+ checknorm (ft, blockarray, atol, rtol)
7168 return ft
7269end
7370
0 commit comments