is there an easy way to make arithmetic operations of a subtype of AbstractArray
and an Array
return the other type and not Array
?
I was looking into it the other day but got busy with other tasks. I think you need to define a method for Base.similar
for your array type. See the SparseArray example here: https://docs.julialang.org/en/v1/manual/interfaces/#man-interface-array
This indee makes copy
work, but e.g. +
returns still an array
I guess I'd need promotion rules for that
One way is to overload broadcasting, that's where A+B
goes. I don't think promotion rules get used for arrays, although broadcasting has some similar mechanisms to try to decide who wins.
Yeah, it’s best to do it via the broadcasting machinery. I found that trying to handle it directly by dispatch methods is a losing battle due to all the method ambiguities.
Last updated: Nov 22 2024 at 04:41 UTC