def new_method(self, other, prefix=prefix): if not check_special_methods(): raise NotImplementedError, 'Special method %s called on %s, but special methods have been disabled. Set pymc.special_methods_available to True to enable them.'%(op_name, str(self)) # This code will create one of two Deterministic objects. if prefix == 'r': # Right version: raises error on failure. parents = {'self':self, 'other':other, 'op':'__r' + op_name + '__'} def eval_fun(self,other,op): out = getattr(self, op)(other) if out is NotImplemented: # the rt version has failed, meainng the lft version has failed as well. raise TypeError, "unsupported operand type(s) for %s: '%s' and '%s'"%(op.replace('_',''), self.__class__.__name__, other.__class__.__name__) return out else: # Left version: tries right version on failure. parents = {'self':self, 'other':other, 'op':'__' + op_name + '__', 'rt_op': '__r'+op_name+'__'} def eval_fun(self, other, op, rt_op): out = getattr(self, op)(other) if out is NotImplemented: # if try the rt version. out = getattr(other, rt_op)(self) return out return pm.Deterministic(eval_fun, 'A Deterministic returning the value of %s(%s,%s)'%(prefix+op_name,self.__name__, str(other)), '('+'_'.join([self.__name__,prefix+op_name,str(other)])+')', parents, trace=False, plot=False)
def __call__(self, *args, **kwargs): if not check_special_methods(): raise NotImplementedError, 'Special method __call__ called on %s, but special methods have been disabled. Set pymc.special_methods_available to True to enable them.'%str(self) def eval_fun(self, args=args, kwargs=kwargs): return self(*args, **kwargs) return pm.Deterministic(eval_fun, 'A Deterministic returning the value of %s(*%s, **%s)'%(self.__name__, str(args), str(kwargs)), self.__name__+'(*%s, **%s)'%(str(args), str(kwargs)), {'self':self, 'args': args, 'kwargs': kwargs}, trace=False, plot=False)
def new_method(self, other): if not check_special_methods(): raise NotImplementedError, 'Special method %s called on %s, but special methods have been disabled. Set pymc.special_methods_available to True to enable them.'%(op_name, str(self)) # This code creates a Deterministic object. def eval_fun(self, other, op): return getattr(self, op)(other) return pm.Deterministic(eval_fun, 'A Deterministic returning the value of %s(%s,%s)'%(op_name,self.__name__, str(other)), '('+'_'.join([self.__name__,op_name,str(other)])+')', {'self':self, 'other':other, 'op':'__'+op_name+'__'}, trace=False, plot=False)
def new_method(self): # This code creates a Deterministic object. if not check_special_methods(): raise NotImplementedError, 'Special method %s called on %s, but special methods have been disabled. Set pymc.special_methods_available to True to enable them.'%(op_name, str(self)) jacobian_formats = {'self' : 'transformation_operation'} return pm.Deterministic(op_function, 'A Deterministic returning the value of %s(%s)'%(op_name, self.__name__), '('+op_name+'_'+self.__name__+')', parents = {'self':self}, trace=False, plot=False, jacobians=jacobians, jacobian_formats = jacobian_formats)
def __getitem__(self, index): if not check_special_methods(): raise NotImplementedError, 'Special method __index__ called on %s, but special methods have been disabled. Set pymc.special_methods_available to True to enable them.'%str(self) # If index is number or number-valued variable, make an Index object name = '%s[%s]'%(self.__name__, str(index)) if np.isscalar(value(index)): if np.isreal(value(index)): return Index(name, self, index, trace=False, plot=False) # Otherwise make a standard Deterministic. def eval_fun(self, index): return self[index] return pm.Deterministic(eval_fun, 'A Deterministic returning the value of %s[%s]'%(self.__name__, str(index)), name, {'self':self, 'index':index}, trace=False, plot=False)
def new_method(self, other, prefix=prefix): if not check_special_methods(): raise NotImplementedError, 'Special method %s called on %s, but special methods have been disabled. Set pymc.special_methods_available to True to enable them.'%(op_name, str(self)) # This code will create one of two Deterministic objects. if prefix == 'r': parents = {'a':other, 'b':self} else: parents = {'a':self, 'b':other} jacobian_formats = {'a' : 'broadcast_operation', 'b' : 'broadcast_operation'} return pm.Deterministic(op_function, 'A Deterministic returning the value of %s(%s,%s)'%(prefix+op_name,self.__name__, str(other)), '('+'_'.join([self.__name__,prefix+op_name,str(other)])+')', parents, trace=False, plot=False, jacobians = jacobians, jacobian_formats = jacobian_formats)
def new_method(self, other, x_roles=x_roles, y_roles=y_roles): if not check_special_methods(): raise NotImplementedError, 'Special method %s called on %s, but special methods have been disabled. Set pymc.special_methods_available to True to enable them.'%(op_name, str(self)) x = [] y = [] for xr in x_roles: if xr=='self': x.append(self) elif xr=='other': x.append(other) else: x.append(xr) for yr in y_roles: if yr=='self': y.append(self) elif yr=='other': y.append(other) else: y.append(yr) # This code will create one of two Deterministic objects. return LinearCombination('('+'_'.join([self.__name__,op_name,str(other)])+')', x, y, trace=False, plot=False)
def new_method(self, op=op): if not check_special_methods(): raise NotImplementedError, 'Special method %s called on %s, but special methods have been disabled. Set pymc.special_methods_available to True to enable them.'%(op_name, str(self)) return op(self.value)