inducer / arraycontext

Choose your favorite numpy-workalike!
6 stars 11 forks source link

rec_map_array_container: ValueError on trying to traverse a dataclass_array_container with a leaf array #28

Closed kaushikcfd closed 3 years ago

kaushikcfd commented 3 years ago

On running:

@with_container_arithmetic(bcast_obj_array=True, rel_comparison=True)
@dataclass_array_container
@dataclass(frozen=True)
class State:
    u: np.ndarray

mystate = State(np.zeros(10))
rec_map_array_container(lambda x: x, mystate)

I get an error saying: ValueError: only object arrays are supported, given dtype 'float64'. Should dataclass_array_container not contain primitive-dtyped numpy arrays?

I was expecting to get a shallow copy of mystate after the traversal.

inducer commented 3 years ago

I agree with you; I think this is just being mishandled. The key thing is that while object arrays are array containers, plain numpy arrays are not. So IMO the code should just funnel "normal" numpy arrays down the same path of "not a container" instead of complaining. PR welcome.