-
-
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
What does T mean in AbstractArray{T}? #9586
Comments
Ah, #987, the undead issue that continues to haunt us despite being closed. Last I heard over there, the consensus was that an
The complexity guarantee inherent in the interface of Note that the |
The part of the
and more complicated versions thereof. In #4744, the possibility of |
Not sure if relevant, but a couple other
|
It seems to me we should maybe have |
I'd also say the T in |
Completely agree. I think of |
The problem for Take @timholy's example above, remove the
The The current WIP implementation in JuliaMath/Interpolations.jl#19 gets around this by enforcing that all indices inherit |
|
That is good news! Interpolation objects (probably) won't support linear indexing, so the default iteration won't work for us, but we can already guarantee that |
Yes, that all sounds fine to me. |
backported the clarification in b22d42a |
This is inspired by our head-scratching over in JuliaMath/Interpolations.jl#17. I couldn't find an open issue on this, but apologies if this is a dupe. It is surely related to #8974, #8027.
The meaning of
eltype
is fairly clear for a stored array, but it's less clear for an array type that involves computation. For example, here's something that sure looks like an AbstractArray, for which it seems to make sense to define agetindex
that involves computation:Note that if you omit the
convert
, you are not guaranteed to return an "element" of typeT
---the return type would depend not only on the concrete type ofA
, but also that ofi
.There are situations, however, when multiple-dispatch type-dependency might be desirable. For example, if one omitted the call to
convert
, one could use DualNumbers.jl to also compute the gradient (e.g.,A[dual(5,1)]
would compute both the value and slope ati=5
). Skipping theconvert
does not automatically make it type-unstable, of course, as long as the return type can be inferred. In that sense, one can make the argument thatgetindex
is just a normal function and our usual preference for duck-typing should apply.So this raises the question: do we have a clear definition of what
AbstractArray{T}
really means? This documentation page says it means "the type of the elements contained in A", which would appear to make it OK to skip theconvert
ingetindex
. However, I'll wager that we have a lot of code that assumes thatA[1]
returns an object of typeeltype(A)
.FYI over in Interpolations we've also thought about not making this kind of thing a subtype of
AbstractArray
; the biggest loss would seem to be the ability to create aSubArray
out of anInterpArray1D
, which is definitely something that comes up in practice.The text was updated successfully, but these errors were encountered: