-
-
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
size
, reshape
not consistent
#22665
Comments
-1 since julia> reshape(rand(2,2), 3, 1)
ERROR: DimensionMismatch("new dimensions (3,1) must be consistent with array size 4")
julia> resize!([1,2,3,4], 3)
3-element Array{Int64,1}:
1
2
3 |
If we had multidimensional resizable (as in re-length-able) arrays, then a multidimensional If we decide to go with non-length-changing arrays, then we can still support |
I think the core suggestion here is to rename |
Linking to #20402 so this gets more eyes before anyone goes to great effort. |
|
renaming seems to me this would be relatively straightforward. just a cut and paste with a deprecation, no? |
If we think this to the end then yuyichao has a point though Personally I don't think all this is worth it. Naming is something that at some point gets subjective and IMHO reaching 100% consistency is close to impossible. |
If we were to move to |
@StefanKarpinski we already have i'm surprised to see so much resistance to this idea. is it just that change is bad / a lot of work and this syntax is too entrenched? we're not at 1.0 yet. would there be less opposition to change |
There are two key properties here: the number of elements, and how they are factored into dimensions. One issue we're up against here is that |
@JeffBezanson matlab uses length to mean the number of elements in the longest dimension. it doesn't make sense; just wanted to point it out. [edit: perhaps the person he coined this usage was a woodworker, where length, width, and depth refers to the longest, 2nd longest, and shortest dimensions of a board, respectively] to me, in plain layman terms, vectors have lengths, matrices have areas, and 3-D arrays have volumes. i guess i tend to think in physical terms, as if they represented a space in the real world. again, to me, a general term for a scalar quantity that includes length, area, and volume is size (not length), meaning how big it is, that is how many elements it has. in julia |
the STL (C++) also uses size. The suggestion The question if its worth the effort. On the other hand: Now or never... :-) |
I don't think we have enough deprecation cycles to make that change happen in 1.0. |
No. I think renaming |
A more descriptive name for |
@StefanKarpinski not enough deprecation cycles? how is the change proposed here ( |
I really don't want to rename |
@bjarthur: a chain of renames requires a deprecation cycle for each link, and we only have one left. Specifically, we can't deprecated |
re. renaming
|
NO. Don't do that! It's not even useful for performance since LLVM can fold that branch easily. |
|
"resize"? |
there are three things wrong with the following interface to arrays:
the first is that the same root word, "size", is used to query an array and return a tuple of dimensions, as well as to alter an array with a scalar input (the diagonal elements in the 2x2 table above). the second and third are that the same root word is not shared for tuple inputs and outputs, and scalar input and outputs (the columns in each row). a single change, |
What about |
i'd suggest deprecating the 2-input method of |
Just to fill in your table a bit more:
Personally, I don't find this all that dreadful. Note that The only refactoring that I could really see is |
@bjarthur |
Thinking more from the linguistic point of view I would second @JeffBezanson and even say that |
i would've expected |
If |
I support having a From this point of view, I would also point out that some of these things are just vagaries of English, which we're inheriting. To change the length of something, you "resize" it, you don't "relength" it – that's just not a word. Moreover, even though asking for the length of an individual dimension makes sense, asking for the length of an entire array and getting back a tuple of dimension lengths does not make sense, so swapping |
I would actually like to rename |
I bet this suggestion will be unpopular, but one possible way to reduce the unfortunate linguistic similarity between the conceptually distinct functions |
Since this has been added to the 2.0 milestone, could we describe how we plan to address this in the context of modern Julia.
Should we add an alias |
I have an idle thought for Julia 2.0, which would be to do away with implicit array bases altogether. Not sure if it's a good idea or not, but it would basically entail making the built-in arrays OffsetArrays and instead of giving dimension sizes in APIs, you would give dimension ranges, e.g. All that said, I just don't think the slight linguistic mismatch between |
It sounds like this could be prototyped in OffsetArrays before reaching |
Isn't this just julia> A = Array{Int}(undef, 5,2,3); axes(A)
(Base.OneTo(5), Base.OneTo(2), Base.OneTo(3))
julia> using OffsetArrays
julia> O = OffsetArray(A, (-1, -2, -3)); axes(O)
(OffsetArrays.IdOffsetRange(values=0:4, indices=0:4), OffsetArrays.IdOffsetRange(values=-1:0, indices=-1:0), OffsetArrays.IdOffsetRange(values=-2:0, indices=-2:0))
julia> collect.(axes(O))
([0, 1, 2, 3, 4], [-1, 0], [-2, -1, 0]) |
if
size
returns a tuple of an arrays dimensions, then why is the function which changes an array's dimensions not calledresize
?size
andreshape
are borrowed from matlab. numpy usesshape
andreshape
. the latter make a lot more sense to me, despite being a recovering matlab user. shall we consider changing? happy to submit a PR if there is a consensus. some discussion here.The text was updated successfully, but these errors were encountered: