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

Usable results are thrown away if recoverable errors are encountered #8

Open
biotinker opened this issue Dec 4, 2023 · 0 comments
Open

Comments

@biotinker
Copy link
Contributor

See the code here in Optimize:

	var cResult C.nlopt_result = C.nlopt_optimize(n.cOpt, (*C.double)(unsafe.Pointer(&cX[0])), &cOptF)
	status, err := normResult(cResult)
	n.setStatus(status)
	if err != nil {
		return nil, math.NaN(), err
	}
	return toGoArray(cX), float64(cOptF), nil

If there is any sort of error encountered, then nil, NaN is returned rather than what nlopt returned.

However, nlopt will frequently return usable values in addition to an error; for example, if the optimizer runs out of floating-point precision prior to hitting an exit condition, it will error with "ROUNDOFF_LIMITED" and return the last value, which usually is a good, usable value. Unfortunately, this value will be thrown out.

I understand that the "Go way" is to return nil and an error, or a usable value and a nil error.

However the use of that paradigm here destroys useful information. Is there a way to resolve this?

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

No branches or pull requests

1 participant