Skip to content
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

row-vector/column-vector products should act like dot products #8

Closed
stevengj opened this issue Apr 25, 2013 · 5 comments
Closed

row-vector/column-vector products should act like dot products #8

stevengj opened this issue Apr 25, 2013 · 5 comments

Comments

@stevengj
Copy link
Member

If x and y are vectors of the same length, then (x*x')*y works but x*(x'*y) does not (it gives ERROR: no method *(Array{Float64,1},Array{Float64,1})). The latter can only be accomplished with x*dot(x,y).

This is surprising and, I think, undesirable: * should be associative (neglecting floating-point roundoff errors, of course).

Another way of putting it is that x'*y, or any product of a row vector and a column vector, should return a scalar, not a vector of length 1. (And it should probably just call the BLAS dot.)

@andreasnoack
Copy link
Member

This has been discussed a few times, I think. At least in JuliaLang/julia#2472. Actually x'*y for vectors x and y already calls dot but wraps it in a vector afterwards.

@stevengj
Copy link
Member Author

At the very least, a column-vector of length 1 should act like a 1×1 matrix for multiplication purposes. e.g. x * [2] should work and be equivalent to 2x.

@toivoh
Copy link

toivoh commented Apr 26, 2013

I think that it might make sense to demote a length one vector to a scalar
in cases where a vector does not make sense. We know that dimensions can be
added spuriosly (typically by transposition).

@pabloferz
Copy link
Contributor

This works now, right?

@StefanKarpinski
Copy link
Member

Yes:

julia> x = rand(3)
3-element Array{Float64,1}:
 0.61878
 0.178213
 0.0933086

julia> y = rand(3)
3-element Array{Float64,1}:
 0.954149
 0.0926293
 0.336523

julia> (x*x')*y
3-element Array{Float64,1}:
 0.394978
 0.113756
 0.0595605

julia> x*(x'*y)
3-element Array{Float64,1}:
 0.394978
 0.113756
 0.0595605

@KristofferC KristofferC transferred this issue from JuliaLang/julia Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants