Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for multiplying dataclass times scalar #209

Open
ethancaballero opened this issue Jun 5, 2019 · 1 comment
Open

add support for multiplying dataclass times scalar #209

ethancaballero opened this issue Jun 5, 2019 · 1 comment

Comments

@ethancaballero
Copy link
Collaborator

ethancaballero commented Jun 5, 2019

e.g. support for:

model = model - 0.1 * dmodel

(inside of myia decorator):

@myia(backend='pytorch', backend_options={'device': device_type}, return_backend=True)
@ethancaballero ethancaballero changed the title add support for multiplying array times scalar add support for multiplying dataclass times scalar Jun 5, 2019
@breuleux
Copy link
Member

breuleux commented Jun 5, 2019

Using myia.hypermap.HyperMap instead of myia.composite.Elemwise (using the appropriate leaf function) would work as a quick-fix, but it would bypass Python's __add__/__radd__ protocol entirely, which may not be the right thing here.

Alternatively, we could implement Python's protocol, which is essentially this:

def add(x, y):
    if hasattr(x, '__add__'):
        z = x.__add__(y)
    else:
        z = NotImplemented
    if z is NotImplemented:
        z = y.__radd__(x)
    return z

We'd just need to add support for NotImplemented, hasattr and some way to check for NotImplemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants