I have a vector of QuatRotation{Float64}, defined initially as:
Q = Vector{QuatRotation{Float64}}(undef, 10)
and a vector of indices ids= [1, 4, 7]. I want to insert at each index β ids, the rotation Rotations.UnitQuaternion(0,0,1,0). I expected to be allowed to assign this QuatRotation, as follows:
julia> Q[ids] .= UnitQuaternion(0, 0, 1, 0)
ERROR: DimensionMismatch: cannot broadcast array to have fewer non-singleton dimensions
but it throws this error.
Obviously I can assign it with a for loop, but Iβd like a more concise way.
QuatRotation is not a scalar with respect to broadcasting. Using
Q[ids] .= Ref(UnitQuaternion(0, 0, 1, 0))
works, because Refs are treated as scalars.
Note however that this is dangerous when the right hand side is mutable / has mutable fields, i.e. a Vector{...}, because that will assign the same object to every index on the left. Not a problem here, but itβs a trap Iβve fallen in more times than I like to admit Same goes for fill([1,2,3], 5) for example.