-
-
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 is the official similar
interface?
#11574
Comments
Worth thinking about whether #11557 ties into this too? It's seeming like using |
My stance on this is fairly firm: I think that what you choose to be the parameters of an AbstractArray subtype are implementation details specific to that type. They don't matter. You don't even need to parameterize an What matters is what you report are the parameters to So, for |
I pretty much agree with everything @mbauman says. It's a little strange that similar(NullableArray([1], [false]), Float64) produce an |
Is returning a |
I mostly agree with what @mbauman is saying, but I think that specific behavior is really weird. In particular, I think it's odd that Alternatively, why are we saying that |
I don't see how the thinking here could be any different than for
It looks like we don't have non-square Line 25 in ce90a6d
#8240 would provide an equivalent though. |
I think |
Indeed, it helps to think about |
This is a good point: when |
What does |
"Give me a reasonable value of this type". For example, you could write |
I was just spit-balling, but I'm liking it more and more. It certianly solves @johnmyleswhite's initial question: it'd be more obvious that |
I'm liking it less and less. It's really "give me a reasonable value of a reasonably chosen concrete subtype of this abstract type" which is a bit too ambiguous for my liking. Especially if there start being odd mapping rules from the concrete type of |
+1 about the identity mapping of element types (unless, of course, a different element type is asked for). |
|
Definitely not if its going to wholesale replace Once similar(::SparseMatrix, T, ::Int) -> SparseVector{T}
similar(::SparseMatrix, T, ::Int, ::Int) -> SparseMatrix{T}
similar(::SparseMatrix, T, ::Int, ::Int, ::Int) -> SparseCOO{T} # Maybe someday This is essential for sensible indexing behavior. |
Another thing to consider here: it'd also be nice to allow some sort of promotion to a common AbstractArray type when working with two or more arrays at the same time: #2326. |
I think a few basic assumptions, valid for
In practice, I guess especially the first point means that if |
I like those rules, @tlycken, but I think I'd slightly amend each. I think Here's another idea: break T = promote_type(typeof(A), AbstractArray{Float64, 2})
T(Float64, 10, 10) Then we make the constructor (Both |
Hm, upon looking back at that, it doesn't quite do what we want. |
I'm probably missing your main point, but just because the container is immutable doesn't mean the elements are. Example: immutable MyArray{T,N} <: AbstractArray{T,N}
data::Array{T,N}
end
A = MyArray(rand(2,2));
A.data[1,1] = 0.5 works just fine. Also, I'm skeptical about the promote idea, because you'll always get a non-leaf type unless people write specific |
Yeah, I don't think promotion is quite the operation we want here. And see my edit — I was lazy and wrote immutable when I meant not-supporting-setindex!. I'm still entertaining the idea that |
If a type doesn't support |
Also, for many My point for the first bullet was that My point with the second bullet, was that when the user supplies additional arguments, it is because they want to change some specific aspect of the result. Exactly which aspect that is, and what the parameters for that should be, might vary between different concrete types. While writing this, I've come to realize that I don't think there even is a sane way to define what |
That's precisely why I think this is a naming bug. The way |
Anyone have a nice name for "ask an array (or ideally arrays) for some modifiable AbstractArray that it knows can support a given element type and dimensionality"? |
To me, |
I'm ok with closing this, since I think my remaining concerns would require a very substantial reorganization of our abstractions to resolve. |
defer to #10064 for more general abstraction design? |
👍 |
While discussing #10525, it became clear that
NullableArray{Int, 1}
is an anomaly with regard to some of the assumptions made aboutAbstractArray{T, N}
. UnlikeArray{Int, 1}
, which has aneltype
ofInt
,NullableArray{Int, 1}
has aneltype
ofNullable{Int}
. It is, to my knowledge, the onlyAbstractArray
type whose first type parameter is not equal to itseltype
. (This, of course, could be changed.)This distinction affects how one interprets something like
versus something like
In the first variant, a call to
similar(x, T, dims)
produces a new object oftypeof(x) <: AbstractArray{T, N}
whose first type parameter is the passed argumentT
.In the second variant, a call to
similar(x, T, dims)
produces a new object oftypeof(x) <: AbstractArray{T, N}
whose first type parameter iseltype(T)
.More generally, this raises the issue: should the second argument to
similar
refer to the first type parameter of the resultingAbstractArray
or should it refer to theeltype
of the resultingAbstractArray
? Or should we require allAbstractArray
objects to match the type-parameterization assumptions that the first type is always theeltype
and the second is always the order of the array?The text was updated successfully, but these errors were encountered: