-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
Hi!
I have a class Quaternion in ReferenceFrameRotations.jl that was <:AbstractVector (4 elements). Hence, the following code used to work perfectly:
julia> v[4:7] = qHowever, I had many problems in Zygote because my class was an array and the multiplication of two quaternions (2 4x1 vectors) provides another quaternion (4x1 vector). This behavior was breaking a lot of things.
Thus, I remove the super type <:AbstractVector and defined all the things necessary to make Quaternion and iterable object. In this case, things like:
julia> v[4:7] .= qworks. But
julia> v[4:7] = qdoes not.
I am wondering if this is a bug or not. Notice that if RHS is iterable, maybe Julia has all the information to see if it can be assigned to LHS. My current workaround is to define:
@inline function setindex!(v::Vector{T}, q::Quaternion, I::UnitRange) where T
# We can use all the funcion in static arrays.
return setindex!(v, q[:], I)
end(q[:] converts a Quaternion into a Vector).
However, I am not sure if I am doing type piracy here.