Skip to content

Broadcasting rules distinguish between host scalar and device scalars #49

Description

@kaushikcfd

Consider this script:

actx=_acf()
@with_container_arithmetic(bcast_obj_array=True,bcast_numpy_array=True,rel_comparison=True,_cls_has_array_context_attr=True)@dataclass_array_container@dataclass(frozen=True)classFoo:
u: DOFArrayfoo=Foo(DOFArray(actx, (actx.zeros(3, dtype=np.float64) +41, )))
print(foo) # prints: Foo(u=DOFArray((cl.Array([41., 41., 41.]),)))print(foo+1) # prints: Foo(u=DOFArray((cl.Array([42., 42., 42.]),)))print(foo+actx.from_numpy(np.ones(()))) # ERROR! 😲

I don't see a good reason why we don't support this.

I think we should also go a step ahead and make sure that we broadcast every cl.Array to be added (if legal) with all the leaf arrays of the array container. One way I could see this working is if every ArrayContext comes with a ARRAY_TYPE static, frozen attribute which gives us a hint to broadcast to all successive arrays.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions