-
-
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
Functions that return arrays with eltype as input should use container type instead? #11557
Comments
Not sure anybody gives a hoot about my opinion, but I think this is a very good idea, and is exactly the sort of thing that should only happen once in the language, and the coming 0.5 "Arraymeggedon" is exactly the perfect time to do so. 👍 |
Should it be called |
That doesn't work for things like |
Who said anything about eliminating them? That's why I showed how they could be defined using a new general function... I think you are the one who will get the 🍅s for daring to suggest taking away |
That is actually already done in terms of Lines 234 to 240 in d198e90
zeros(A::AbstractArray) , but not zeros{T<:AbstractArray}(::Type{T}, dims...) .
The decision item is which is more general, needing to take an already-constructed instance of the |
Well, I already stated that I liked the idea of passing the array type (actually, couldn't it be any collection type?) |
For matrices of matrices, the type information alone is insufficient to determine the appropriate Thinking about |
Yeah, sparse arrays of sparse arrays, while godawfully cool in concept, would be pretty tough to support generically. A nerd can dream. To give a concrete example where I ran into this as a major problem, I was making a separate sparse matrix type in a package using a different representation than CSC, and immediately found that there was no signature for |
Arrays of arrays are not pleasant to work with in Julia. Recall #8759? There's definitely room for a variant of |
@tkelman, why are sparse arrays of sparse arrays so difficult? Is it just to handle the mathematical functions? (I've been using and implementing structures [multidimensional associative arrays], for the past 29 years, and they could be viewed/used as sparse arrays of sparse arrays)... sorry in advance for the potentially dumb question |
There are assumptions sprinkled around in various places that you can always call edit: Also please please refrain from conflating missing data with sparsity in the linear algebraic sense. They are rather different in implementation aspects and semantics. You're very familiar with data structures that are optimized for missingness, those exist outside of base in the Julia ecosystem, primarily for statistical purposes right now. Most of what I'm discussing is about linear algebra and data structures optimized for that purpose. |
@tkelman Thanks for the explanation! (formalizing interfaces I think is very important, all over julia...) |
I'm generally positive about this proposal, but it is a general problem that parametric types can be cumbersome to write out, e.g. I solution might be to have default behavior when the type parameters are not specified, e.g. something like |
@andreasnoack Yes, I think that makes a lot of sense, like the convenience of still having |
I think the convenience methods should eventually be behind a non-default import though, not exported globally by default. |
Wouldn't unexported convenience methods just be inconvenient convenience methods then? |
Can't you do something to just bring all the convenience functions in, in one fell swoop, if desired? |
Sounds like we need a |
Actually |
Oh, I forgot that. Then just ignore |
If arrays of arrays are excluded from the scope of |
I'm not sure why this has to be breaking. |
@stevengj Are you replying to my comment? If so, I don't think it has to be breaking indeed. My idea was precisely, as you say, to allow both. |
@tkelman I just noticed the edit you'd added after I'd read and responded:
So far, I didn't see anything that makes these different in implementation... the sparse structures in Julia might be optimized for linear algebra, but that doesn't make them not be useful (with a bit more generalization) for dealing with missing data (and much more efficient than simply using dense arrays). |
I think it's much better for functionality like this to be constructors of the container type you want, e.g. |
What about |
It doesn't have to be a Do we know what the general set of affected functions is here? Or is it just zeros, ones, and rand? |
|
|
Has anybody mentioned |
|
Yes I think we should resolve this along with #16029 by deprecating the current |
From triage, alternatives here seem to be:
Note that 1 is not in conflict with more generically constructing arrays by passing them generators, and in fact |
One complication with e.g. Edit: Perhaps e.g. |
Could we do that like: rng = MersenneTwister(seed)
Array(rng, dims)
That could be done similarly then, e.g. a = [1, 2, 3, 4, 5]
Array(a, dims) Although thats pretty bad cause it is not apparent that we create something at random, so we should probably include |
The key is that we need ways to get random numbers without constructing arrays, so you can do e.g. |
Continuing discussion from #24389 (comment) here.
Through working with
The new constructor direction can achieve similar brevity with a bit of generalization/relaxation. Consider Illustrating with With array types that carry information beyond shape and element type, for example More on the second invocation mode later. Best! |
Could Should we consider keyword arguments to disambiguate these cases? |
I believe we've decided not to do this. |
Looks like the conclusion has mostly been to deprecate them and use array constructors directly instead? Are any of the old style functions left? What about the rand family? |
That's OK, we mostly want to keep them for interactive use. If Base commonly uses a different style, that's not an issue. |
ref #11280 (comment) and a few other places I've mentioned this. Functions like
zeros
,ones
,eye
,rand
,mmap
(maybe), etc which currently take aneltype
as inputs and return some subtype ofAbstractArray
, would be much more general if they instead took the container type (with element type as a parameter) as input, so the current case would instead look likezeros(Array{Float64}, dims...)
. This would allow extending these functions to other types ofAbstractArray
in a much nicer way than right now. We could potentially get rid of a bunch of ugly-named functions likebitrand
andspzeros
andspeye
andsprandbool
with this change.I think it would by necessity be breaking, though maybe clever enough subtyping ofzeros{T<:AbstractArray}(::Type{T}, dims...)
would allow putting in deprecations (or defaults? might be fragile) for "scalar" types, if we have enough of a concept of interfaces to determine what makes a type a scalar (that's a different issue).This would have to be a breaking change for arrays-of-arrays (if any of these functions currently work for arrays of arrays, that is?).
The text was updated successfully, but these errors were encountered: