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
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
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
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
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
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
def f(*args): if isinstance(args[0], basestring): self._newParameter(*args) else: self._addParameter(*args) return
def f(*args): if isinstance(args[0], basestring): self.newVar(*args) else: self.addVar(*args) return
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
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
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
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