-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Real part of complex dot product #22261
Comments
I feel that this falls under our usual "modulizing Julia" discussion. I think it would be ok to export this from the Update: The comment above was a bit too brief. I don't think it makes much sense in the current situation to add exports to LinAlg that are not exported from Base. In a possible future world where we don't export a lot of linear algebra symbols from Base by default, I think it would make sense to be more liberal about adding exports to |
This should work for dotr{T}(a::Vector{Complex{T}}, b::Vector{Complex{T}}) = dot(reinterpret(T, a), reinterpret(T, b)) |
If anybody is interested I did some benchmarking on this. On a single thread, the However, OpenBLAS does not multithread the complex dot product, and so even the reinterpret version is better for large arrays. I guess this should rather be fixed in OpenBLAS (opened an issue here: OpenMathLib/OpenBLAS#2221). I'm closing this issue. |
A common enough operation when dealing with complex vectors is taking the real part of the inner product, ie dotr(a,b) = re(dot(a,b)) = sum_i re(ai) re(bi) + im(ai) im(bi). This turns up when evaluating Taylor series of complex-to-real maps, when evaluating quadratic forms (z* A z where A is Hermitian), etc. It is not trivial enough that one can easily define a one-liner that computes this in an optimal way (ie not real(dot(a,b))). Would it be a good idea to add a "dotr" function to base Julia or is this considered namespace pollution?
The text was updated successfully, but these errors were encountered: