-
-
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
return type of size(::AbstractArray) and size(::AbstractArray,::Int) #9777
Comments
When given an abstract type like However, many other range types also give broad inference results for |
I don't see why length should be unitful if Also, it's a bit arbitrary to add a typeassert to |
I was forgetting the step must be defined---I was thinking of it as a span, but of course that's not right. |
Well, I was also somewhat to quick / tired yesterday. It doesn't indeed really make sense to consider abstract types. For the concrete ranges, the length seems to be (on my 64bit system) But this triggered the related question: why a typeassert for |
I suspect we should add the typeassert for |
I added that typeassert to the permutedims code in cdb6f7c. It actually fixes a performance problem when B is not a SubArray. Even if |
FWIW, the current state of affairs (Julia 1.8.2):
|
Note that e.g. ulia> Core.Compiler.return_type(size, Tuple{Base.OneTo{Int},Int})
Int64 For the non-concrete julia> Core.Compiler.return_type(length, Tuple{Base.OneTo})
Any And the best we can do there is probably |
I was surprised to find out that the return type of
size(::AbstractArray,::Int)
isAny
, which I traced back to the return type ofsize(::AbstractArray)
being(Any,...)
, which originates from what I can see from the return type oflength(::Range)
beingAny
. This seems somewhat unfortunate, wouldn't the fact thatsize
always returns anNTuple{N,Int}
be part of the implicit interface specification ofAbstractArray{T,N}
, just likelength
should always return anInt
?I stumbled upon this when revisiting my old interest of
permutedims
, where I now noted the::SubArray
typeassert here , which actually doesn't work as the return type offirst_index
of aSubArray
is not inferred correctly, exactly because of the issue in the title.The text was updated successfully, but these errors were encountered: