-
Notifications
You must be signed in to change notification settings - Fork 4
Support abstract vectors/arrays even if different types or complex #3
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
base: main
Are you sure you want to change the base?
Conversation
helpful -- reviewing |
imo, it should be the responsibility of the caller to provide two vectors of the same type (promoting them if needed) because there is potential for incorrect results otherwise. How do you interpret the angle between two Complex vectors mathematically? |
Thanks for the very quick reply! And thanks for the package too - I was not familiar with the Kahan method prior to seeing it used here. Related functions like One defines the angle the same way for any inner product space even if over the complex field; it stems from the Cauchy Schwarz inequality that is quite general. However, your question made me realize that one must take care of the complex conjugate needed for the inner product for complex spaces. There is no inner product in Kahan's formula, so that made me wonder if it is even applicable to complex vectors. I have not seen a proof of his "unfamiliar" formula so I simply tried it in Julia and sadly it fails. So I've marked the current PR as a WIP because this needs to be fixed. using AngleBetweenVectors
using LinearAlgebra: dot, norm
for T in (Float64, ComplexF64)
n = 5
x = rand(T, n)
y = rand(T, n)
a1 = acos(abs(dot(x,y)) / norm(x) / norm(y))
a2 = angle(x, y)
@show T, a1, a2
@assert a1 ≈ a2
end My proposal would be to revert to the usual |
I found these two references, perhaps they are of help to you. K. Scharnhorst, “Angles in complex vector spaces,” Acta Applicandae Math., vol. 69, pp. 95–103, Nov. 2001. and appendix in V. G. Reju, S. N. Koh and I. Y. Soon, “Underdetermined Convolutive Blind Source Separation via Time-Frequency Masking,” IEEE Transactions on Audio, Speech and Language Processing, Vol. 18, NO. 1, Jan. 2010, pp. 101–116. (both refs are from the last response to |
The first sections here may be of interest too |
This PR adds support for the angle between two
AbstractArrays
(of compatible dimensions) even if they have different element types and even if the elements are non-float reals (i.e., integers) or if they are complex.Added tests exercise the additional flexibility.
If this type of generalization is welcome then I can also add comment about it to the docstring and README if you want.
Also fixes the previously inaccurate comment about a zero point, perhaps addressing #2.