-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Change vcat and cat behaviour for vectors #19622
Comments
It might be worth considering also row vectors here (there might be action on JuliaLang/LinearAlgebra.jl#42 soon) |
I'm not in favor of this change. There are two issues here: syntax (how commas and spaces semicolons should be interpreted) and what the functions Regarding syntax: Although I was a little confused by the commas/space/semicolons syntax when I first encountered Julia, that was mostly due to my preconceived notions. I soon came to appreciate that it is (like most design features of Julia) actually quite logical and also convenient. Regarding the behavior of |
Although I mostly agree with @benninkrs on not changing too much the behavior of these functions, I think there is some scope to refine how the literal syntax is parsed (or lowered).
This should be possible:
Row vectors will change this as
To be honest, this makes sense to me - I thought |
Then with |
@benninkrs @andyferris @martinholters |
Right. I see the commas here indicate a kind of list (currently,
should give results entirely consistent with
or, if you prefer to change the semantics to this,
that would be OK too. But having We could (and I would argue we should) change the lowering to (With regards to the first sentence, Julia will have resizeable lists and non-resizeable vectors sometime soon, so we may even need to disambiguate those, e.g. commas for lists via
Agreed, completely. I wasn't thinking quite straight! I feel that having |
That makes sense if the arguments are scalars, but if they are (column) vectors, then you would get a row vector whose elements are column vectors, whereas I think the expectation (and preferred behavior) would be to get a matrix. In the context of concatenation, I think the mindset that function X should always return type Y is too simplistic. The "symmetry" people desire really is there in the current behavior, it is just at the underlying level of how concatenation works (see my response to @felixrehren below). |
See my response to @andyferris above.
Sorry, I was a bit imprecise. What I meant was that only
I only stumbled because I hadn't taken the few minutes to actually read the parts of the manual that describe concatenation. The current behavior is actually quite logical and straightforward, but I agree it is not presented very clearly in the manual. The rules can be stated quite succinctly:
From these rules it is easy to determine what the output type of any array construct is. Of course, this hinges on truly understanding two things: (1) the difference between enumeration and concatenation; and (2) what
Does that help? |
Ignoring the OP here, I think this audience might be interested in checking out master of https://github.com/andyferris/TransposedVectors.jl - it now has the |
(The goal there being to refine what is currently in v0.5 not to implement the proposal in the OP). |
@andyferris That looks interesting. I saw JuliaLang/LinearAlgebra.jl#42 a while ago, but it seemed to me like much ado about a couple of fairly minor issues. However, if you have indeed found a way to remove those "minor" issues and recover all the conventions of standard linear algebra without introducing weirdness anywhere else, then kudos to you! |
This comment from @benninkrs describes the situation well: #19622 (comment) |
Following this discourse, I suggest
;
operator in array construction to always return a 2D matrixvcat
to always return a 2D or higher matrixcat
to concatenate vectors (taking over the vector methods currently onvcat
)for the following reasons
hcat
) and semicolons (vcat
) concatenate and return 2D arrayshcat
andvcat
, having built-in directions, only make sense in 2D or higher. In particular, it doesn't make sense thathcat(xx::Vector{T}...)
returns an1xn Array{T,2}
andvcat(xx::Vector{T}...)
returns ann Array{T,1}
. By analogy,vcat
should return annx1 Array{T,2}
.cat
with the benefits that
nx1 Array
as well as1xn Array
and vectorsThe text was updated successfully, but these errors were encountered: