Skip to content

Commit

Permalink
The dot product should conjugate the second vector.
Browse files Browse the repository at this point in the history
Matrix multiplication, on the other hand, should not
take a complex conjugate, so shouldn't use the dot
product for its definition -- just use sum(_.*_)
instead. I'm really not sure that dot product makes
any sense for anything that's not a vector so get
rid of the definition for non-vectors. It doesn't
seem to be used anywhere, so this is safe.

Closes #51.
  • Loading branch information
StefanKarpinski committed Jun 30, 2011
1 parent 9b628fd commit 5807981
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions j/linalg.j
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
## linalg.j: Basic Linear Algebra functions ##

dot(x::Vector, y::Vector) = sum(x.*y)
# Take care of dot product of vectors that are actually matrices or N-d
dot(x::Matrix, y::Matrix) = dot(reshape(x, prod(size(x))), reshape(y, prod(size(y))) )
dot(x::Vector, y::Vector) = sum(x.*conj(y))

# blas.j defines these for floats; this handles other cases
(*)(A::Matrix, B::Vector) = [ dot(A[i,:],B) | i=1:size(A,1) ]
(*)(A::Matrix, B::Matrix) = [ dot(A[i,:],B[:,j]) | i=1:size(A,1), j=1:size(B,2) ]
(*)(A::Matrix, B::Vector) = [ A[i,:].*B | i=1:size(A,1) ]

This comment has been minimized.

Copy link
@JeffBezanson

JeffBezanson Jun 30, 2011

Member

needs sum()

This comment has been minimized.

Copy link
@StefanKarpinski

StefanKarpinski Jun 30, 2011

Author Member

Yikes. I'd actually realized that already, but failed to add the change to the commit before pushing.

(*)(A::Matrix, B::Matrix) = [ A[i,:].*B[:,j] | i=1:size(A,1), j=1:size(B,2) ]

triu(M) = triu(M,0)
tril(M) = tril(M,0)
Expand Down

1 comment on commit 5807981

@StefanKarpinski
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. This closes issue #92. I'm not sure what crack I was smoking.

Please sign in to comment.