Ejemplo n.º 1
0
 def f(*args):
     from diffpy.srfit.fitbase.profile import Profile
     from diffpy.srfit.fitbase.profilegenerator import ProfileGenerator
     if isinstance(args[0], Profile):
         self.setProfile(*args)
     elif isinstance(args[0], ProfileGenerator):
         self.addProfileGenerator(*args)
     elif isinstance(args[0], basestring):
         self.setEquation(*args)
     else:
         raise TypeError("Invalid argument")
     return
Ejemplo n.º 2
0
    def __lshift__(self, v):
        """setValue with <<

        Think of '<<' as injecting a value

        v   --  value or Argument derivative
        """
        if isinstance(v, ArgumentABC):
            self.value = v.value
        else:
            self.value = v
        return self
Ejemplo n.º 3
0
    def onArgument(self, arg):
        """Process an Argument node.

        The Argument must be an instance of ArgumentABC from
        diffpy.srfit.equation.literals.abcs

        """
        if not isinstance(arg, ArgumentABC):
            m = msg%(arg, ArgumentABC.__name__)
            self.errors.append(m)
        self._nin = 1
        return self.errors
Ejemplo n.º 4
0
    def onArgument(self, arg):
        """Process an Argument node.

        The Argument must be an instance of ArgumentABC from
        diffpy.srfit.equation.literals.abcs

        """
        if not isinstance(arg, ArgumentABC):
            m = msg % (arg, ArgumentABC.__name__)
            self.errors.append(m)
        self._nin = 1
        return self.errors
Ejemplo n.º 5
0
    def onOperator(self, op):
        """Process an Operator node.

        The Operator must be an instance of OperatorABC from
        diffpy.srfit.equation.literals.abcs

        """

        if not isinstance(op, OperatorABC):
            m = msg % (op, OperatorABC.__name__)
            self.errors.append(m)

        # Can only process single-valued functions
        if op.nout != 1:
            m = "'%s' is not single-valued (nout != 1)" % op
            self.errors.append(m)
        # Check name
        if op.name is None:
            m = "'%s' does not have a name" % op
            self.errors.append(m)
        # Check symbol
        if op.symbol is None:
            m = "'%s' does not have a symbol" % op
            self.errors.append(m)
        # Check operation without evaluating it
        if op.operation is None:
            m = "'%s' does not define and operation" % op
            self.errors.append(m)

        localnin = 0
        for literal in op.args:
            literal.identify(self)
            # Count the nout of the arguments.
            localnin += self._nin

        # Check the input/output balance
        if op.nin >= 0 and localnin != op.nin:
            m = "'%s' requires %i inputs but receives %i" % (op, op.nin,
                                                             localnin)
            self.errors.append(m)

        self._nin = op.nout
        return self.errors
Ejemplo n.º 6
0
    def onOperator(self, op):
        """Process an Operator node.

        The Operator must be an instance of OperatorABC from
        diffpy.srfit.equation.literals.abcs
        
        """

        if not isinstance(op, OperatorABC):
            m = msg%(op, OperatorABC.__name__)
            self.errors.append(m)

        # Can only process single-valued functions
        if op.nout != 1:
            m = "'%s' is not single-valued (nout != 1)"%op
            self.errors.append(m)
        # Check name
        if op.name is None:
            m = "'%s' does not have a name"%op
            self.errors.append(m)
        # Check symbol
        if op.symbol is None:
            m = "'%s' does not have a symbol"%op
            self.errors.append(m)
        # Check operation without evaluating it
        if op.operation is None:
            m = "'%s' does not define and operation"%op
            self.errors.append(m)

        localnin = 0
        for literal in op.args:
            literal.identify(self)
            # Count the nout of the arguments.
            localnin += self._nin

        # Check the input/output balance
        if op.nin >= 0 and localnin != op.nin:
            m = "'%s' requires %i inputs but receives %i"%(op, op.nin, localnin)
            self.errors.append(m)

        self._nin = op.nout
        return self.errors
Ejemplo n.º 7
0
 def f(*args):
     if isinstance(args[0], basestring):
         self._newParameter(*args)
     else:
         self._addParameter(*args)
     return
Ejemplo n.º 8
0
 def f(*args):
     if isinstance(args[0], basestring):
         self.newVar(*args)
     else:
         self.addVar(*args)
     return
Ejemplo n.º 9
0
 def testIdentity(self):
     """Make sure an Argument is an Argument."""
     op = literals.Operator(symbol = "+", operation = numpy.add, nin = 2)
     self.assertTrue(abcs.issubclass(literals.Operator, abcs.OperatorABC))
     self.assertTrue(abcs.isinstance(op, abcs.OperatorABC))
     return
Ejemplo n.º 10
0
 def testIdentity(self):
     """Make sure an Argument is an Argument."""
     a = literals.Argument()
     self.assertTrue(abcs.issubclass(literals.Argument, abcs.ArgumentABC))
     self.assertTrue(abcs.isinstance(a, abcs.ArgumentABC))
     return
Ejemplo n.º 11
0
 def testIdentity(self):
     """Make sure an Argument is an Argument."""
     op = literals.Operator(symbol="+", operation=numpy.add, nin=2)
     self.assertTrue(abcs.issubclass(literals.Operator, abcs.OperatorABC))
     self.assertTrue(abcs.isinstance(op, abcs.OperatorABC))
     return
Ejemplo n.º 12
0
 def testIdentity(self):
     """Make sure an Argument is an Argument."""
     a = literals.Argument()
     self.assertTrue(abcs.issubclass(literals.Argument, abcs.ArgumentABC))
     self.assertTrue(abcs.isinstance(a, abcs.ArgumentABC))
     return