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

Give suggestions for vector->row vector confusion #7688

Merged
merged 1 commit into from
Jul 23, 2014

Conversation

ivarne
Copy link
Member

@ivarne ivarne commented Jul 21, 2014

Some new users might get confused when they create a vector without
commas, and end up with a matrix that does not match the methods he
tries to use. After this patch the error will contain a suggestion.

julia> a = [1 2 3]
1x3 Array{Int64,2}:
 1  2  3

julia> sort(a)
ERROR: `sort` has no method matching sort(::Array{Int64,2})

You might have used a 2d row vector where a 1d column vector was required.
Note the difference between 1d column vector [1,2,3] and 2d row vector [1 2 3]
You can convert a row vector to a column vector with the vec() function

See: https://groups.google.com/forum/#!topic/julia-users/XBjl1sPfTkU and #7512

Suggestions for better wording/formatting is most welcome.

@jiahao
Copy link
Member

jiahao commented Jul 22, 2014

+1

@porterjamesj
Copy link
Contributor

I was very confused by this when I was learning, + a lot

@ViralBShah
Copy link
Member

I like the idea of giving a clear message.

@ivarne
Copy link
Member Author

ivarne commented Jul 22, 2014

The build failure seems unrelated (even though it seems scary that it is the repl.jl tests that is failing).

@Keno
Copy link
Member

Keno commented Jul 22, 2014

Maybe point to the vec function?

@ivarne
Copy link
Member Author

ivarne commented Jul 23, 2014

Does anyone have any objections against this, or should I just squash and merge?

@timholy
Copy link
Member

timholy commented Jul 23, 2014

Nice implementation. One small nit: it might be better to say you can convert Arrays to a vector using vec (the current statement seems to suggest vec is more limited than that).

@ViralBShah
Copy link
Member

I think it should be ok to squash and merge.

@ivarne
Copy link
Member Author

ivarne commented Jul 23, 2014

I don't think it suggests vec is limited to row vectors.

I think it is more important to stress the type difference between row and column vectors in Julia, than to provide a complete description of what vec can be used for. The help text will only be displayed when you get a MethodError for using a row vector where a column vector would have worked.

@timholy
Copy link
Member

timholy commented Jul 23, 2014

I agree that the clarification of row vs column (and space vs comma) much needed---this comes up over and over, and it will be great to have this fixed in such a good, general way.

I was just suggesting converting You can convert a row vector to a column vector with the vec() function to something like You can convert to a column vector with the vec function. But this is a tiny point, and the benefits awaiting users from the merger of this PR should not be delayed any longer! 😄

@ivarne
Copy link
Member Author

ivarne commented Jul 23, 2014

Yes, that seems better. I did not like the reference to Array in the first suggestion.

@ivarne ivarne closed this Jul 23, 2014
@ivarne ivarne reopened this Jul 23, 2014
@ivarne
Copy link
Member Author

ivarne commented Jul 23, 2014

Wrong button 😠

Some new users might get confused when they create a vector without
commas, and end up with a matrix that does not match the methods he
tries to use. After this patch the error will contain a suggestion.

```julia
julia> a = [1 2 3]
1x3 Array{Int64,2}:
 1  2  3

julia> sort(a)
ERROR: `sort` has no method matching sort(::Array{Int64,2})

You might have used a 2d row vector where a 1d column vector was required.
Note the difference between 1d column vector [1,2,3] and 2d row vector [1 2 3]
You can convert to a column vector with the vec() function
```
ivarne added a commit that referenced this pull request Jul 23, 2014
Give suggestions for vector->row vector confusion
@ivarne ivarne merged commit 7e7489d into JuliaLang:master Jul 23, 2014
@ivarne ivarne deleted the row_vec_suggestion branch July 23, 2014 11:18
@timholy
Copy link
Member

timholy commented Jul 23, 2014

Looks like this version omitted the mention of vec.

@timholy
Copy link
Member

timholy commented Jul 23, 2014

Never mind, this was a wait-for-GitHub-to-update issue.

@ivarne
Copy link
Member Author

ivarne commented Jul 23, 2014

Sorry, somehow git happily does a git commit --amend without requiring me to to add anything first (supposedly to change the commit message, which I did). I pushed a new correct commit a few minutes later.

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

Successfully merging this pull request may close these issues.

6 participants