-
Notifications
You must be signed in to change notification settings - Fork 5
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
Size of StaticArray type #3
Comments
No.
That's what it does for
If we wanted to support it, |
Aha: julia> import ArrayInterface as Arr
julia> using StaticArrays
julia> Base.IteratorSize(StaticArray{Tuple{2,3}})
Base.HasLength()
julia> Base.IteratorSize(StaticArray{Tuple{2,3}, <:Any, 2})
Base.HasShape{2}()
julia> Arr.known_size(StaticArray{Tuple{2,3}, <:Any, 2})
(2, 3) So a |
It should probably be defined like this: julia> itersize(::Type{<:SArray{S}}) where {N,S<:Tuple{Vararg{Any,N}}} = Base.HasShape{N}()
itersize (generic function with 1 method)
julia> itersize(SArray{Tuple{3}})
Base.HasShape{1}()
julia> itersize(SArray{Tuple{3,4}})
Base.HasShape{2}()
julia> itersize(SArray{Tuple{3,4,5}})
Base.HasShape{3}() So that they only need the first parameter. |
@chriselrod: As a temporary workaround, I type-pirated something like your code above into the (unpublished) package I am working on, and it did does fix the problem. Also:
Could it be useful to have an |
I'd prefer to return
You could make a PR to StaticArrays.jl |
Good point.
Sure - I can try to do this whenever I get the chance in the next few of days. |
I am thinking something like the following would be quite helpful.
To give context, this behavior would be potentially useful for function I am writing that takes an iterator with a statically known size and element type and tries to create an array of the given type, if that type is compatible with the dimensions of materialize(target_type::Type{<:AbstractArray}}, iter::SizedIterator) For example, if one passed |
I'm assuming these issues are arising from manually writing out types like
I believe our goal has been to define traits on types that correspond to actual instances, and so far we've just let traits on a |
Currently, there is still some unexpected behavior still happening for concrete
So, |
size was never intended to be called on the type. We should probably document this |
Using
ArrayInterface v5.05
andStaticArrays v1.42
:Are those the intended results? I expected
(2, 3)
and(static(2), static(3))
, respectively. (Though, things work fine for instances ofStaticArrays
.)I think what is happening is that
IteratorSize(::Type{<:StaticArray})
is defaulting toHasLength()
while it might better off beHasShape{N}()
, so the wrong method gets called at some point. If that's the case, perhaps its also worth opening a bug report onStaticArrays
.Also, should
ArrayInterface.size
produce an error if given aType
as an argument? What should be the behavior if one of the dimensions is unknown?The text was updated successfully, but these errors were encountered: