Stream: helpdesk (published)

Topic: Arrays and custom arrays


view this post on Zulip Simon Christ (May 20 2021 at 13:38):

is there an easy way to make arithmetic operations of a subtype of AbstractArray and an Array return the other type and not Array?

view this post on Zulip Júlio Hoffimann (May 20 2021 at 13:42):

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

view this post on Zulip Simon Christ (May 20 2021 at 13:59):

This indee makes copy work, but e.g. + returns still an array

view this post on Zulip Simon Christ (May 20 2021 at 14:00):

I guess I'd need promotion rules for that

view this post on Zulip Michael Abbott (May 20 2021 at 23:41):

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.

view this post on Zulip Jonnie Diegelman (May 25 2021 at 14:34):

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: Oct 02 2023 at 04:34 UTC