-
-
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
Merge collect() into Vector()? #16029
Comments
duplicate of JuliaLang/LinearAlgebra.jl#231? |
Indeed. Let's keep this issue to discuss the case of |
It would be a lot cleaner, as that is actually what people want when using "our" collect method. I only know the method name |
|
|
By the way |
I really like this suggestion, lets get rid of |
I like the idea too, but it is ambiguous with constructors that take dimensions, e.g. |
Yes, but how? Can we deprecate |
It's not about the performance penalty so much as many people prefer to use the dimension tuple form, and in some sense it's a better, more consistent way to specify this. |
It might be too late for this, but I'd almost say arguments like |
So if we don't want to get rid of Anyway, we can still use @JeffBezanson I'm not sure I get your point. That indeed sounds interesting, but it doesn't replace |
Just to add a data point, the recently introduced constructors from iterables of BitArrays (#19018) also inevitably ended up having the slightly annoying feature that tuples of
It's probably less severe than the Array case. But perhaps if a general solution is not found and |
I thought we were rather trying to get rid of the |
In principle yes, except that good generic constructs to specify the output container type have not yet emerged to my knowledge (other than the constructors, of course). |
Ref. #16740, work in that direction. Best! |
Now that For One option is to deprecate e.g. |
Since Edit: I realized the problem with this as soon as I posted it – |
ref #15120 |
Arrays are at this point one of the only collections that doesn't have constructors that take arbitrary iterators of contents to construct with, making them quite the odd one out. Perhaps we should consider deprecating |
A |
That's essentially what #16740 implements, for |
(If the following doesn't make sense, please check out #24595.) Deprecation process conundrum: We can deprecate |
Working plan from triage: Deprecate |
What the status of this issue? Triage just decided to use |
Right, that's a good point. I'm not sure we need to fully deprecate |
Everything necessary to give e.g. |
Yes, I agree we seem to need |
The very unpopular #22630 proposal would solve that. But obviously not (2) and I also realize that at this stage in the release process it is probably not even worth considering that option anymore :) So treat this comment as noise. |
IMHO Factory pattern was too entangled in OOP land to succeed. Anyway having a simple wrapper - a function, let's call it collect - to handle creation with correct type info is a good - if not essential - step in the good direction.
And move forward to 1.0 :) |
Looks like we are set for 1.0 here. |
Given last week's triage's decision to extend Operating under that assumption, I prepared #25450 as a head start on the potential deprecation between 0.7 and 1.0. Best! |
Yes (note that the title is a bit misleading, since the goal is to merge it into Array, not Vector; possibly by using copyto) |
Discussing this with @mschauer I just wanted to check in on the thinking here. I understand completely the motivation to take more control over things with teh constructors in generic library code. But For example, start with the simplest example:
Next, Imagine the following function which uses the current
The issue, of course, is that So I think the only way to do it correctly (without worrying about promotion... another big issue we didn't need to worry about in the
This is all very confusing for a new user, when all they want to do is get an array from a call to Right now the following works great
and I would hate to see this require a bunch of generic programming just to teach something similar. |
No, the proposal here is to use the un-parameterized |
OK, then I think I agree with the change. As long as I don't have to teach my students about generic programming before they can do the basics! |
Is the proposal here to define
The downside of (1) is that it wouldn't work for arbitrary iterators, while (2) seems prone to accidental misuse and bugs. Perhaps it would be better to introduce a new function (perhaps called |
I wonder whether
collect()
isn't always equivalent toVector()
, and could therefore be merged into it:The method for
Range
returns a vector, so it could be replaced withArray()
, as both callvcat()
in the end.convert(Vector, ...)
currently fails and should be fixed.The methods for general iterables are more complex, but they essentially always create an
Array
too. Even when they callsimilar()
, it's on a1:1
range, so they actually create aVector
. So thecollect()
machinery could be moved toArray()
/Vector()
to make them support conversion from any iterable.This issue is related to discussions regarding
similar()
(JuliaLang/LinearAlgebra.jl#271). Indeed, Julia provides a few functions which appear to behave differently, but in practice behave likeArray
, and callers end up depending on this assumption. This makes the API more complex and less explicit.See also JuliaLang/LinearAlgebra.jl#231 about merging
full
intoArray
.The text was updated successfully, but these errors were encountered: