Truncation error in ITensors SVD

I am trying to understand the truncation error when performing an SVD using ITensors. According to ITensor Examples · ITensors.jl, the truncation error is defined as sum_{discarded n} lambda_n^2 / sum_{n} lambda_n^2, where lambda_n are the singular values. However, running the following code, I get inconsistent results:

using ITensors
i = Index(10,"i”);

j = Index(40,"j”);

k = Index(20,"k”);

T = random_itensor(i,j,k)

# Approximate calculation, get truncated spectrum

maxdim = 10

U,S,V,spec = svd(T, (i,k), maxdim = maxdim)
 # The following lines give the same result
@show (norm(U * S * V - T)/norm(T))^2

@show truncerror(spec)

# Exact calculation to get the entire spectrum

U,S,V,spec = svd(T,(i,k))

spec_vals = eigs(spec)
# This line gives a result that does not agree with the truncation errors from above
@show (sum(spec_vals[maxdim+1:end].^2)/sum(spec_vals.^2))

What am I missing?

I found my mistake: eigs(spec) actually contains the singular values squared, so a working example is:

using ITensors
using LinearAlgebra
using Test
i = Index(10,"i")
j = Index(40,"j")
k = Index(30,"k")

A = random_itensor(i,j,k)

U,S,V,spec = svd(A, (i,j))

S_diag = diag(Array(S, inds(S)))

@test norm(A)^2 ≈ sum(S_diag.^2)

@test eigs(spec) ≈ S_diag.^2
@test truncerror(spec) == 0.0

maxdim = 7
U,S,V,spec_trunc = svd(A,(i,j); maxdim=maxdim)
@test truncerror(spec_trunc) ≈ sum(S_diag[maxdim+1:end].^2) / sum(S_diag.^2)
eigs_spec = eigs(spec)
@test truncerror(spec_trunc) ≈ sum(eigs_spec[maxdim+1:end]) / sum(eigs_spec)
@test truncerror(spec_trunc) ≈ (norm(U*S*V - A)/norm(A))^2