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

Any[1 [1,2]] ERROR: DimensionMismatch #14646

Closed
egoecho opened this issue Jan 11, 2016 · 7 comments
Closed

Any[1 [1,2]] ERROR: DimensionMismatch #14646

egoecho opened this issue Jan 11, 2016 · 7 comments
Labels
needs decision A decision on this change is needed
Milestone

Comments

@egoecho
Copy link

egoecho commented Jan 11, 2016

In Julia 0.4.2,

julia> Any[1 [1,2]]
ERROR: DimensionMismatch("mismatch in dimension 1 (expected 1 got 2)")
 in cat_t at abstractarray.jl:850
 in typed_hcat at abstractarray.jl:878

The old style is fine:

julia> {1 [1,2]}
WARNING: deprecated syntax "{a b ...}".
Use "Any[a b ...]" instead.
1x2 Array{Any,2}:
 1  [1,2]

I also found that Any[1 [1]] = {1 1} rather than {1 [1]}

julia> Any[1 [1]]
1x2 Array{Any,2}:
 1  1

julia> {1 [1]}

WARNING: deprecated syntax "{a b ...}".
Use "Any[a b ...]" instead.
1x2 Array{Any,2}:
 1  [1]
@anthonyclays
Copy link
Contributor

Any[1 [1, 2]] will call typed_hcat which makes julia attempt to make one large array composed of the smaller ones. The same thing will happen when you do simply [1 [1, 2]], or [1; [1 2]].

There's not really an exact equivalent of {...}. I believe your best bet would be to use reshape(Any[1, [1, 2]], 1, 2).

@KristofferC
Copy link
Member

Imo, if you specify "Any" then there shouldn't be any concatenation.

@anthonyclays
Copy link
Contributor

@KristofferC You could specialize the typed concatenation functions when typeC = Type{Any}, but then again what should the behaviour of AbstractArray[[1] [1, 2]] be?
You can't simply special-case Any (like {...} used to do). It's not really obvious what the best behaviour would be here.

@anthonyclays
Copy link
Contributor

There will be ambiguity when using any subtype of AbstractArray in the construction of an Any-typed array, I believe (for example Any[1:3 10] fails too)

@jdlangs
Copy link
Contributor

jdlangs commented Jan 12, 2016

This looks like more evidence there should be parallel syntaxes for array construction and concatenation. (#7128)

@tkelman
Copy link
Contributor

tkelman commented Jan 12, 2016

Or concatenation should be a function call rather than syntax. We should also flip the switch on the concatenation deprecation behavior from #8599

@JeffBezanson JeffBezanson added the needs decision A decision on this change is needed label Feb 6, 2016
@JeffBezanson JeffBezanson added this to the 0.5.0 milestone Feb 6, 2016
@JeffBezanson
Copy link
Member

This will stay as-is for now. As long as [a b] means concatenation, T[a b] should mean concatenation with an element type.

closing as dup of #7128

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs decision A decision on this change is needed
Projects
None yet
Development

No branches or pull requests

6 participants