convert
: for arrays, copy or view?
#20826
Labels
needs decision
A decision on this change is needed
Milestone
The docstring for
convert
is wonderfully explicit about providing details about the underlying assumptions in many cases, but I've found one that isn't yet covered.convert(T, x)
has the behavior that ifx
already has typeT
, we just returnx
. But for AbstractArrays, things get more complicated:In the first case we didn't copy, in the second we did. Often there is no choice but to copy, for example if we had defined
S = view(A, 1:2, 1:3)
; however, in cases likeview(A, :, :)
it would be possible to return the original without making a copy (and it wouldn't violate type-stability).An even more intermediate case comes from array types like
For this type,
convert(Array, A::MyArray)
could always returnA.data
directly. But is this advisable? Or should it be a copy any timetypeof(A) != T
?The text was updated successfully, but these errors were encountered: