-
Notifications
You must be signed in to change notification settings - Fork 152
Conversion to AbstractArray not defined #746
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
Comments
This seems fairly clear cut — A little use of |
Thanks! Judging by the definitions in base here, the conversions to Would adding the following lines to AbstractArray{T}(sa::StaticArray{S,T}) where {S,T} = sa
AbstractArray{T,N}(sa::StaticArray{S,T,N}) where {S,T,N} = sa
AbstractArray{T}(sa::StaticArray{S,U}) where {S,T,U} = similar_type(typeof(sa),T,Size(sa))(Tuple(sa))
AbstractArray{T,N}(sa::StaticArray{S,U,N}) where {S,T,U,N} = similar_type(typeof(sa),T,Size(sa))(Tuple(sa)) It does work for the cases I've tried (SVector and SMatrix), but the StaticArrays codebase is larger than I was expecting and there are a lot of other cases. It would be very convenient indeed if |
Fixed in #747 (thanks!) |
Conversion of static vectors and matrices to an AbstractVector or AbstractArray with a wider element type seems to fail with an error:
Yet, a type-stable conversion is possible because:
Conversion to an abstract vector or abstract array with the same element type succeeds (via a fallback in Base).
I use conversions like this elsewhere in generic code that updates the element type of a vector. Currently, I have to add special cases for static vectors.
Would this just be a matter of adding conversion routines that invoke the right static array constructor? E.g., though it should be more general than this:
This is not as problematic as going in the other direction (converting from abstract vectors to static vectors).
The text was updated successfully, but these errors were encountered: