-
Notifications
You must be signed in to change notification settings - Fork 6
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
Dot product for QuArray's. #36
Conversation
+1 for |
The Travis error for 0.4 seems unrelated, but we should have a closer look. |
# dot product of QuArray's | ||
dot{B<:OrthonormalBasis}(vec1::AbstractQuVector{B}, vec2::AbstractQuVector{B}) = dot(coeffs(vec1), coeffs(vec2)) | ||
# Reference : http://en.wikipedia.org/wiki/Dot_product#Dyadics_and_matrices | ||
dot{B<:OrthonormalBasis}(qm1::AbstractQuMatrix{B}, qm2::AbstractQuMatrix{B}) = trace(coeffs(qm1')*coeffs(qm2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to use trace(coeffs(qm1'*qm2))
here. If you want you can also steal trace
for QuMatrix
from #32. We have to check the issue I linked to if there is a more efficient way to do this dot product.
@@ -37,3 +37,8 @@ v1 = [0.5+0*im, 0.+0.*im] | |||
qv1 = normalize!(QuArray(v1)) | |||
@assert coeffs(\(sigmax,qv1)) == [0.+0.*im, 1.+0.*im] | |||
@assert coeffs(\(sigmaz, sigmax)) == [0. 1.;-1. 0.] | |||
|
|||
# tests for trace, dot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer the tests being easier to understand on a first glance, which implies more comments. If one doesn't know about Pauli matrices it is unclear what the tests are doing. I think it is better to say for instance
# Pauli matrices sigmax, sigmay, sigmaz are traceless (see ... )
@assert trace(sigmax) == zero(eltype(sigmax))
@assert trace(sigmaz) == zero(eltype(sigmaz))
and so on.
Apart from the comment on the tests, I think this looks good. |
@acroy edits done. If this is fine, I will squash the commits ? |
# Being defined both for vectors and dual vectors | ||
# Related Ref : https://github.com/JuliaLang/julia/issues/11064 | ||
@assert dot(qv,qv) == dot(qv',qv') | ||
@assert dot(sigmax, sigmay) == trace(sigmaz) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line also needs an explanation ...
@acroy done! |
Good. Please squash the commits and then we can merge I would say. |
Sorry. I just noticed that you squashed already :-) |
@acroy can we merge this ? |
Basically yes. I was just thinking if we should generalize dot to allow for two |
@acroy I have tried creating a common |
I see, but what I meant was the following
and maybe similar for |
@acroy the latest commit covers the cases, please do let me know if I am missing something here. |
You are checking if the element types of the two vectors are the same, while I simply want to prevent a |
Sorry my bad I understand what I did here. So what would be the best way out, the initial version or the latest version ? |
Either you revert it to your original version and we sort it out later or you just take the code I posted above and replace the |
Would be good if we compare the types of vectors i.e., |
You don't need to compare the types. |
@acroy a review would be helpful. |
@amitjamadagni : Could you please squash and rebase? |
@acroy done ! |
@amitjamadagni : Thanks! |
Dot product for AbstractQuVectors and AbstractQuMatrix.
I was going through the material on Krylov propagator, as it requires the dot of QuArray's I have added this, I am not really sure if we require this , any comments on this would be helpful.