Commit e05332db authored by Reimar H Leike's avatar Reimar H Leike

added the possibility to multiply a field by a model

parent 7caca9b2
Pipeline #31537 failed with stages
in 4 minutes and 1 second
......@@ -17,7 +17,9 @@
# and financially supported by the Studienstiftung des deutschen Volkes.
from ..operators.selection_operator import SelectionOperator
from ..operators.diagonal_operator import DiagonalOperator
from ..utilities import NiftyMetaBase
from ..field import Field
class Model(NiftyMetaBase()):
......@@ -62,9 +64,15 @@ class Model(NiftyMetaBase()):
if isinstance(other, Model):
from .binary_helpers import Mul
return Mul.make(self, other)
if isinstance(other, Field):
if other.domain == self.value.domain:
from .binary_helpers import Mul
return DiagonalOperator(other)(self)
raise NotImplementedError
def __rmul__(self, other):
if isinstance(other, (float, int)):
return self.__mul__(other)
if isinstance(other, Field):
return self.__mul__(other)
raise NotImplementedError
  • @mtr, @reimar, I do not like that change. I think it can be the cause of many bugs in user-written code. Why not just convert a Field to a Model with ift.Constant?

  • I'm not sure ... this looks very much like the exception we made for multiplying operators with scalars. If I read the code correctly, the explicit conversion of a Field to a Constant would require specifying a position argument, which is somehow redundant (just like the domain of a ScalingOperator).

  • By our definition, models behave like fields. By this paradigma, this should be fine. What kind of bugs do you think it triggers?

  • By our definition, models behave like fields. By this paradigma, this should be fine. What kind of bugs do you think it triggers?

    Somehow, one could mess up which fields are variable and which are not. Or people could acidentally write Model.value*field and noone would notice that one probably wants to have Model*Constant(field).

    But I understand the redundancy argument with the Constant contructor. Perhaps the automatic conversion does not produce problems.

    Edited by Philipp Arras
  • We could discuss it We/Th next week and otherwise just leave it for now in until it makes trouble

  • Fine with me :)

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment