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

1 / [1,2,3] returns nonsense #25431

Closed
mohamed82008 opened this issue Jan 6, 2018 · 9 comments
Closed

1 / [1,2,3] returns nonsense #25431

mohamed82008 opened this issue Jan 6, 2018 · 9 comments

Comments

@mohamed82008
Copy link
Contributor

julia> 1 / [1, 2, 3]
1×3 Transpose{Float64,Array{Float64,1}}:
 0.0714286  0.142857  0.214286

julia> versioninfo()
Julia Version 0.7.0-DEV.3234
Commit 2cc82d29e1* (2018-01-02 11:44 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, skylake)
@KristofferC
Copy link
Member

#23067

@tkluck
Copy link
Contributor

tkluck commented Jan 6, 2018

You're looking at the Moore-Penrose pseudoinverse:

julia> (1/[1,2,3]) * [1,2,3]
0.9999999999999999

https://docs.julialang.org/en/stable/stdlib/linalg/#Base.LinAlg.pinv

The way to find out out about these things is by calling

julia> @less 1 / [1,2,3]

which will point you to pinv. The documentation for that explains what you are looking at.

Thanks for opening an issue, @mohamed82008 ! @andreasnoack is right in closing this, though.

@mohamed82008
Copy link
Contributor Author

I know about pinv, but I never expected it show up in that context, i.e. dividing a scalar by a vector. I am also not sure how many people who know about pinv would expect it to pop up in such a context. So I wonder if this is the most intuitive/correct behavior, might be a trade-off between the 2.

@stevengj
Copy link
Member

stevengj commented Jan 6, 2018

It's pretty surprising to me too. @martinholters, why was scalar / matrix defined as scalar * pinv(matrix) in #23067? That PR was mostly about rowvector, but don't understand how that affects scalar/matrix operations.

@andreasnoack
Copy link
Member

There is no matrix here. It is ([1,2,3]' \ 1)', i.e. it involves what used to be a rowvector and a scalar. It solves the underdetermined system x1 + 2x2 + 3x3 = 1 and then transposes the result.

@stevengj
Copy link
Member

stevengj commented Jan 6, 2018

@andreasnoack, we didn't used to allow solving systems by rowvector \ scalar. In all previous Julia versions, [1 2 3] \ 1 threw an error. You had to write [1 2 3] \ [1] or [1, 2, 3]' \ [1] if you wanted to solve the underdetermined system.

I realize that we can assign this a meaning, but I'm not sure we should. An expression like this seems more likely to be a user error...

@martinholters
Copy link
Member

Reason for allowing it is that rowvector*vector gives a scalar and it seems natural for the inverse operation - the division - to work, at least in the sense it works for matrices.

@stevengj
Copy link
Member

stevengj commented Jan 6, 2018

I see. To put it another way, you want to have associativity (a' \ b') * c ≈ a' \ (b' * c) for three vectors a,b,c.

@glemieux
Copy link

Tracking down this thread to figure out exactly what 1 / [1,2,3] was doing took a long time for me today. Is this noted anywhere in the official docs? Also the example of using @less that @tkluck gave doesn't work for this particular example any more.

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

7 participants