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

StochasticParameter should support __radd__, __rpow__ etc. #76

Open
isarandi opened this Issue Nov 15, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@isarandi

isarandi commented Nov 15, 2017

Currently only __add__, __pow__ etc. are supported, which means expressions where the first operand is a number (such as 3/ia.Normal(0,1)) don't work. This is especially a problem for expressions such as 2**ia.Uniform(-1,1). These can only be written as ia.Deterministic(2)**ia.Uniform(-1,1), which is much less straightforward. This could be solved by implementing __rpow__, __rdiv__ etc. on StochasticParameter.

Basically something like this could be added into StochasticParameter:

    @staticmethod
    def deterministic_if_single_number(x):
        if ia.is_single_number(x):
            return Deterministic(x)
        return x

    def __radd__(self, other):
        return self.deterministic_if_single_number(other) + self

    def __rsub__(self, other):
        return self.deterministic_if_single_number(other) - self

    def __rmul__(self, other):
        return self.deterministic_if_single_number(other) * self

    def __rpow__(self, other):
        return self.deterministic_if_single_number(other) ** self

    def __rdiv__(self, other):
        return self.deterministic_if_single_number(other) / self

    def __rtruediv__(self, other):
        return self.deterministic_if_single_number(other) / self
@aleju

This comment has been minimized.

Show comment
Hide comment
@aleju

aleju Nov 19, 2017

Owner

Thanks for pointing this out. This should now work with the latest version.

Owner

aleju commented Nov 19, 2017

Thanks for pointing this out. This should now work with the latest version.

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