Skip to content

Commit 8383afd

Browse files
authored
Merge pull request #41 from tensor4all/40-estimatetrueerror-does-not-stop-if-the-error-is-close-to-machine-precision
Fixed possible infinite loop in estimatetrueerror
2 parents 99c552a + 361dc1a commit 8383afd

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/globalsearch.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ function _floatingzone(
8080
)
8181
err = vec(abs.(exactdata .- prediction))
8282
pivot[ipos] = argmax(err)
83-
maxerror = maximum(err)
83+
# In RHS, we compare the maximum of the error vector with the current maxerror
84+
# to make sure that the error does not decrease even if maxerror is close to machine precision.
85+
maxerror = max(maximum(err), maxerror)
8486
end
8587

8688
if maxerror == prev_maxerror || maxerror > earlystoptol # early stop

test/test_globalsearch.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ import QuanticsGrids as QD
3232
pivoterrors = TCI.estimatetrueerror(TCI.TensorTrain(tci), f)
3333

3434
errors = [e for (_, e) in pivoterrors]
35-
@test all([abs(f(p) - tci(p)) for (p, _) in pivoterrors] .== errors)
35+
@test [abs(f(p) - tci(p)) for (p, _) in pivoterrors] errors
3636
@test all(errors[1:end-1] .>= errors[2:end]) # check if errors are sorted in descending order
3737
end

0 commit comments

Comments
 (0)