-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
While discussing #10525, it became clear that NullableArray{Int, 1} is an anomaly with regard to some of the assumptions made about AbstractArray{T, N}. Unlike Array{Int, 1}, which has an eltype of Int, NullableArray{Int, 1} has an eltype of Nullable{Int}. It is, to my knowledge, the only AbstractArray type whose first type parameter is not equal to its eltype. (This, of course, could be changed.)
This distinction affects how one interprets something like
x = NullableArray([1, 2, 3], [false, false, false])
similar(x, Float64, 3)
versus something like
x = NullableArray([1, 2, 3], [false, false, false])
similar(x, Nullable{Float64}, 3)
In the first variant, a call to similar(x, T, dims) produces a new object of typeof(x) <: AbstractArray{T, N} whose first type parameter is the passed argument T.
In the second variant, a call to similar(x, T, dims) produces a new object of typeof(x) <: AbstractArray{T, N} whose first type parameter is eltype(T).
More generally, this raises the issue: should the second argument to similar refer to the first type parameter of the resulting AbstractArray or should it refer to the eltype of the resulting AbstractArray? Or should we require all AbstractArray objects to match the type-parameterization assumptions that the first type is always the eltype and the second is always the order of the array?