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

Comment to explain _inner #5

Open
goretkin opened this issue Jul 26, 2020 · 1 comment
Open

Comment to explain _inner #5

goretkin opened this issue Jul 26, 2020 · 1 comment

Comments

@goretkin
Copy link

goretkin commented Jul 26, 2020

_inner(x, v1, v2) = v1 === v2 ? LinearAlgebra.norm(v1)^2 : LinearAlgebra.dot(v1, v2)

This is really just for my curiosity. If appropriate, can you include a comment about why not just _inner(x, v1, v2) = LinearAlgebra.dot(v1, v2)? I can't tell if it's about accuracy, or performance, or ....

I know that LinearAlgebra.generic_norm2 does some rescaling for better numerical accuracy, and maybe dot does not.

@Jutho
Copy link
Owner

Jutho commented Jul 27, 2020

I kind of forgot why I did this. It is probably not necessary.

However, I do use sqrt(inner(x, v, v)) to compute the norm of a vector at various places throughout the code. While it is somewhat inefficient to square a number and then take its square root, I assume this has a negligible effect compared to other steps in these optimization algorithms. So with the current implementation, it is guaranteed that the norm is indeed the one computed by norm, if at least the default inner is used. (Hereby assuming that taking the square root of the square of a floating point number is identical to the input, which seems to be true).

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

2 participants