OptimKit.jl icon indicating copy to clipboard operation
OptimKit.jl copied to clipboard

Comment to explain `_inner`

Open goretkin opened this issue 5 years ago • 1 comments

https://github.com/Jutho/OptimKit.jl/blob/6f08a89c94af4c0ec0886fc2d38efc40d238af24/src/OptimKit.jl#L7

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.

goretkin avatar Jul 26 '20 17:07 goretkin

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).

Jutho avatar Jul 27 '20 22:07 Jutho