NamedArrays.jl icon indicating copy to clipboard operation
NamedArrays.jl copied to clipboard

Broadcasting fails to locate namedarray object

Open tomhaber opened this issue 4 years ago • 2 comments

The broadcast implementation tries to find the first NamedArray in the expression tree, but fails when a subtree doesn't have a NamedArray. For example:

bc = Base.broadcasted(+, Base.broadcasted(*, [1., 2., 3.], 2.), NamedArray([1,2,3]))
copy(bc) # throws BoundsError: attempt to access () at index [1]

Quick and dirty fix is to add the terminating case

find_namedarray(x::Tuple{}) = ()

I'm not really familiar with broadcasting, but I think the names could be encoded into the broadcast-style as well.

tomhaber avatar Nov 21 '20 13:11 tomhaber

I've just been dealing with this broadcasting code... I didn't write it so I had to study it a little. What is the actual use case for this error? I assume you don't work with raw Base.broadcasted?

davidavdav avatar May 24 '21 10:05 davidavdav

Oh no, definitely not. The actual use case is

[1., 2., 3.] .* 2 .+ NamedArray([1,2,3])

If I remember correctly, the problem occurs when the NamedArray is on the right side of the expression tree

tomhaber avatar May 25 '21 08:05 tomhaber