def __init__(self, clauses, *args, **kwargs): # error check mapping if not isinstance(clauses, (list,tuple)): raise TypeError("'clauses' object passed in must be of python type 'list' or 'tuple'") self._clauses = [] funcSet = set() for clause in clauses: if not isinstance(clause, (list,tuple)): raise TypeError("Clauses within the clause list must be of python type 'list' or 'tuple'") if len(clause) != 2: raise ValueError("Clauses tuples must be of length 2.") conditionFn = _Function._CheckIsFnOrConvertOrThrow(clause[0]) funcSet.add(conditionFn) actionFn = _Function._CheckIsFnOrConvertOrThrow(clause[1]) funcSet.add(actionFn) self._clauses.append( (conditionFn,actionFn) ) # build parent self._fncself = _cfn.Conditional() super(conditional,self).__init__(argument_fns=funcSet,**kwargs) # insert clause into c object now for clause in self._clauses: self._fncself.insert( clause[0]._fncself, clause[1]._fncself )
def __init__(self, clauses, *args, **kwargs): # error check mapping if not isinstance(clauses, (list, tuple)): raise TypeError( "'clauses' object passed in must be of python type 'list' or 'tuple'" ) self._clauses = [] funcSet = set() for clause in clauses: if not isinstance(clause, (list, tuple)): raise TypeError( "Clauses within the clause list must be of python type 'list' or 'tuple'" ) if len(clause) != 2: raise ValueError("Clauses tuples must be of length 2.") conditionFn = _Function._CheckIsFnOrConvertOrThrow(clause[0]) funcSet.add(conditionFn) actionFn = _Function._CheckIsFnOrConvertOrThrow(clause[1]) funcSet.add(actionFn) self._clauses.append((conditionFn, actionFn)) # build parent self._fncself = _cfn.Conditional() super(conditional, self).__init__(argument_fns=funcSet, **kwargs) # insert clause into c object now for clause in self._clauses: self._fncself.insert(clause[0]._fncself, clause[1]._fncself)
def __init__(self, fn1, fn2, **kwargs): fn1fn = _Function._CheckIsFnOrConvertOrThrow( fn1 ) if not isinstance( fn1fn, _Function ): raise TypeError("Functions must be of type (or convertible to) 'Function'.") fn2fn = _Function._CheckIsFnOrConvertOrThrow( fn2 ) if not isinstance( fn2fn, _Function ): raise TypeError("Functions must be of type (or convertible to) 'Function'.") self._fn1 = fn1fn self._fn2 = fn2fn # ok finally lets create the fn self._fncself = _cfn.MathBinary(self._fn1._fncself, self._fn2._fncself, _cfn.MathBinary.fmin ) # build parent super(min,self).__init__(argument_fns=[fn1fn,fn2fn],**kwargs)
def __init__(self, fn1, fn2, **kwargs): fn1fn = _Function._CheckIsFnOrConvertOrThrow(fn1) if not isinstance(fn1fn, _Function): raise TypeError( "Functions must be of type (or convertible to) 'Function'.") fn2fn = _Function._CheckIsFnOrConvertOrThrow(fn2) if not isinstance(fn2fn, _Function): raise TypeError( "Functions must be of type (or convertible to) 'Function'.") self._fn1 = fn1fn self._fn2 = fn2fn # ok finally lets create the fn self._fncself = _cfn.Dot(self._fn1._fncself, self._fn2._fncself) # build parent super(dot, self).__init__(argument_fns=[fn1fn, fn2fn], **kwargs)
def __init__(self, vertices, fn=None, *args, **kwargs): if fn: self._fn = _Function._CheckIsFnOrConvertOrThrow(fn) else: self._fn = input() if not isinstance(vertices, np.ndarray): raise TypeError( "Provided 'vertices' must be a numpy array." ) if len(vertices.shape) != 2: raise TypeError( "Provided 'vertices' array must be 2 dimensional." ) if vertices.shape[0] < 3: raise TypeError( "Provided 'vertices' array must contain at least 3 vertices." ) if vertices.shape[1] != 2: raise TypeError( "Provided 'vertices' array must contain 2d vectors." ) # ok, need to create a 3d array from the 2d array.. create array of required size threedeearray = np.zeros( (vertices.shape[0],3) ) # now copy threedeearray[:,0:2] = vertices[:,0:2] # create instance import random import string self._id = "".join(random.choice(string.ascii_uppercase + string.digits) for _ in range(8)) self._fncself = _cfn.Polygon( self._fn._fncself, threedeearray, self._id ) # build parent super(Polygon,self).__init__(argument_fns=[fn,], *args, **kwargs)
def __init__(self, fn_key=None, mapping=None, fn_default=None, keyFunc=None, mappingDict=None, defaultFunc=None, *args, **kwargs): #DEPRECATE if keyFunc: raise RuntimeError("Note that the 'keyFunc' parameter has been renamed to 'fn_key'.") if mappingDict: raise RuntimeError("Note that the 'mappingDict' parameter has been renamed to 'mapping'.") if defaultFunc: raise RuntimeError("Note that the 'defaultFunc' parameter has been renamed to 'fn_default'.") if not mapping: raise ValueError("You must specify a mapping via the 'mapping' parameter.") if not isinstance(mapping, dict): raise TypeError("'mapping' object passed in must be of python type 'dict'") if not fn_key: raise ValueError("You must specify a key function via the 'fn_key' parameter.") fn_key = _Function._CheckIsFnOrConvertOrThrow(fn_key) self.fn_default = _Function._CheckIsFnOrConvertOrThrow(fn_default) if self.fn_default == None: fn_defaultCself = None else: fn_defaultCself = self.fn_default._fncself # create instance self._fncself = _cfn.Map( fn_key._fncself, fn_defaultCself ) self._fn_key = fn_key self._mapping = mapping # build parent super(map,self).__init__(argument_fns=[fn_key,self.fn_default],**kwargs) self._map = {} for key, value in mapping.iteritems(): if not isinstance(key, int) or key < 0: raise ValueError("Key '{}' not valid. Mapping keys must be unsigned integers.".format(key)) funcVal = _Function._CheckIsFnOrConvertOrThrow(value) if funcVal == None: raise ValueError("'None' is not valid for mapped functions.") self._underlyingDataItems.update(funcVal._underlyingDataItems) # update dictionary # insert mapping and keep handles in py dict self._map[key] = funcVal self._fncself.insert( key, funcVal._fncself )
def __init__(self, fn1, fn2, **kwargs): # lets convert integer powers to floats if isinstance(fn2, int): fn2 = float(fn2) fn1fn = _Function._CheckIsFnOrConvertOrThrow(fn1) if not isinstance(fn1fn, _Function): raise TypeError( "Functions must be of type (or convertible to) 'Function'.") fn2fn = _Function._CheckIsFnOrConvertOrThrow(fn2) if not isinstance(fn2fn, _Function): raise TypeError( "Functions must be of type (or convertible to) 'Function'.") self._fn1 = fn1fn self._fn2 = fn2fn # ok finally lets create the fn self._fncself = _cfn.MathBinary(self._fn1._fncself, self._fn2._fncself, _cfn.MathBinary.pow) # build parent super(pow, self).__init__(argument_fns=[fn1fn, fn2fn], **kwargs)
def __init__(self, fn, *args, **kwargs): _fn = _Function._CheckIsFnOrConvertOrThrow(fn) if _fn == None: raise ValueError( "provided 'fn' must a 'Function' or convertible.") self._fn = _fn # create instance self._fncself = _cfn.TensorFunc( self._fn._fncself, _cfn.TensorFunc.second_invariant ) # build parent super(second_invariant,self).__init__(argument_fns=[fn,],**kwargs)
def __init__(self, fn, *args, **kwargs): _fn = _Function._CheckIsFnOrConvertOrThrow(fn) if _fn == None: raise ValueError( "provided 'fn' must a 'Function' or convertible.") self._fn = _fn # create instance self._fncself = _cfn.SafeMaths( self._fn._fncself ) # build parent super(SafeMaths,self).__init__(argument_fns=[_fn,],**kwargs)
def __init__(self, fn=None, *args, **kwargs): self._fn = _Function._CheckIsFnOrConvertOrThrow(fn) fncself = None if self._fn: fncself = self._fn._fncself # create instance self._fncself = _cfn.MathUnary_sin( fncself ) # build parent super(sin,self).__init__(argument_fns=[fn,],**kwargs)
def __init__(self, fn, *args, **kwargs): _fn = _Function._CheckIsFnOrConvertOrThrow(fn) if _fn == None: raise ValueError("provided 'fn' must a 'Function' or convertible.") self._fn = _fn # create instance self._fncself = _cfn.SafeMaths(self._fn._fncself) # build parent super(SafeMaths, self).__init__(argument_fns=[ _fn, ], **kwargs)
def __init__(self, fn_stress, fn_stresslimit, fn_inputviscosity, stressFn=None, stressLimitFn=None, inputViscosityFn=None, *args, **kwargs): # DEPRECATE 1/16 if stressFn: raise RuntimeError("Note that the 'stressFn' parameter has been renamed to 'fn_stress'.") if stressLimitFn: raise RuntimeError("Note that the 'stressLimitFn' parameter has been renamed to 'fn_stresslimit'.") if inputViscosityFn: raise RuntimeError("Note that the 'inputViscosityFn' parameter has been renamed to 'fn_inputviscosity'.") _fn_stress = _Function._CheckIsFnOrConvertOrThrow(fn_stress) if _fn_stress == None: raise ValueError( "Provided 'fn_stress' must a 'Function' or convertible type.") self._fn_stress = _fn_stress _fn_stresslimit = _Function._CheckIsFnOrConvertOrThrow(fn_stresslimit) if _fn_stresslimit == None: raise ValueError( "Provided 'fn_stresslimit' must a 'Function' or convertible type.") self._fn_stresslimit = _fn_stresslimit _fn_inputviscosity = _Function._CheckIsFnOrConvertOrThrow(fn_inputviscosity) if _fn_inputviscosity == None: raise ValueError( "Provided 'fn_inputviscosity' must a 'Function' or convertible type.") self._fn_inputviscosity = _fn_inputviscosity # grab second inv of stress secondInvFn = _tensor.second_invariant(self._fn_stress) # create conditional self._conditional = _branching.conditional( [ ( secondInvFn > _fn_stresslimit , fn_inputviscosity*_fn_stresslimit/secondInvFn ), # if over limit, reduce viscosity ( True , fn_inputviscosity ) ] ) # else return viscosity # this function is not based on a c function itself, so instead point the c pointer to the conditionals. self._fncself = self._conditional._fncself # build parent super(stress_limiting_viscosity,self).__init__(argument_fns=[_fn_stress,_fn_stresslimit,_fn_inputviscosity],**kwargs)
def __init__(self, fn, *args, **kwargs): _fn = _Function._CheckIsFnOrConvertOrThrow(fn) if _fn == None: raise ValueError("provided 'fn' must a 'Function' or convertible.") self._fn = _fn # create instance self._fncself = _cfn.TensorFunc(self._fn._fncself, _cfn.TensorFunc.second_invariant) # build parent super(second_invariant, self).__init__(argument_fns=[ fn, ], **kwargs)
def __init__(self, fn=None, *args, **kwargs): self._fn = _Function._CheckIsFnOrConvertOrThrow(fn) fncself = None if self._fn: fncself = self._fn._fncself # create instance self._fncself = _cfn.MathUnary_sin(fncself) # build parent super(sin, self).__init__(argument_fns=[ fn, ], **kwargs)
def __init__(self, vertices, fn=None, *args, **kwargs): if fn: self._fn = _Function._CheckIsFnOrConvertOrThrow(fn) else: self._fn = input() if not isinstance(vertices, np.ndarray): raise TypeError("Provided 'vertices' must be a numpy array.") if len(vertices.shape) != 2: raise TypeError("Provided 'vertices' array must be 2 dimensional.") if vertices.shape[0] < 3: raise TypeError( "Provided 'vertices' array must contain at least 3 vertices.") if vertices.shape[1] != 2: raise TypeError( "Provided 'vertices' array must contain 2d vectors.") # ok, need to create a 3d array from the 2d array.. create array of required size threedeearray = np.zeros((vertices.shape[0], 3)) # now copy threedeearray[:, 0:2] = vertices[:, 0:2] # create instance import random import string self._id = "".join( random.choice(string.ascii_uppercase + string.digits) for _ in range(8)) self._fncself = _cfn.Polygon(self._fn._fncself, threedeearray, self._id) # build parent super(Polygon, self).__init__(argument_fns=[ fn, ], *args, **kwargs)
def __init__(self, fn_key=None, mapping=None, fn_default=None, keyFunc=None, mappingDict=None, defaultFunc=None, *args, **kwargs): #DEPRECATE if keyFunc: raise RuntimeError( "Note that the 'keyFunc' parameter has been renamed to 'fn_key'." ) if mappingDict: raise RuntimeError( "Note that the 'mappingDict' parameter has been renamed to 'mapping'." ) if defaultFunc: raise RuntimeError( "Note that the 'defaultFunc' parameter has been renamed to 'fn_default'." ) if not mapping: raise ValueError( "You must specify a mapping via the 'mapping' parameter.") if not isinstance(mapping, dict): raise TypeError( "'mapping' object passed in must be of python type 'dict'") if not fn_key: raise ValueError( "You must specify a key function via the 'fn_key' parameter.") fn_key = _Function._CheckIsFnOrConvertOrThrow(fn_key) self.fn_default = _Function._CheckIsFnOrConvertOrThrow(fn_default) if self.fn_default == None: fn_defaultCself = None else: fn_defaultCself = self.fn_default._fncself # create instance self._fncself = _cfn.Map(fn_key._fncself, fn_defaultCself) self._fn_key = fn_key self._mapping = mapping # build parent super(map, self).__init__(argument_fns=[fn_key, self.fn_default], **kwargs) self._map = {} for key, value in mapping.iteritems(): if not isinstance(key, int) or key < 0: raise ValueError( "Key '{}' not valid. Mapping keys must be unsigned integers." .format(key)) funcVal = _Function._CheckIsFnOrConvertOrThrow(value) if funcVal == None: raise ValueError("'None' is not valid for mapped functions.") self._underlyingDataItems.update( funcVal._underlyingDataItems) # update dictionary # insert mapping and keep handles in py dict self._map[key] = funcVal self._fncself.insert(key, funcVal._fncself)
def __init__(self, fn_stress, fn_stresslimit, fn_inputviscosity, stressFn=None, stressLimitFn=None, inputViscosityFn=None, *args, **kwargs): # DEPRECATE 1/16 if stressFn: raise RuntimeError( "Note that the 'stressFn' parameter has been renamed to 'fn_stress'." ) if stressLimitFn: raise RuntimeError( "Note that the 'stressLimitFn' parameter has been renamed to 'fn_stresslimit'." ) if inputViscosityFn: raise RuntimeError( "Note that the 'inputViscosityFn' parameter has been renamed to 'fn_inputviscosity'." ) _fn_stress = _Function._CheckIsFnOrConvertOrThrow(fn_stress) if _fn_stress == None: raise ValueError( "Provided 'fn_stress' must a 'Function' or convertible type.") self._fn_stress = _fn_stress _fn_stresslimit = _Function._CheckIsFnOrConvertOrThrow(fn_stresslimit) if _fn_stresslimit == None: raise ValueError( "Provided 'fn_stresslimit' must a 'Function' or convertible type." ) self._fn_stresslimit = _fn_stresslimit _fn_inputviscosity = _Function._CheckIsFnOrConvertOrThrow( fn_inputviscosity) if _fn_inputviscosity == None: raise ValueError( "Provided 'fn_inputviscosity' must a 'Function' or convertible type." ) self._fn_inputviscosity = _fn_inputviscosity # grab second inv of stress secondInvFn = _tensor.second_invariant(self._fn_stress) # create conditional self._conditional = _branching.conditional([ (secondInvFn > _fn_stresslimit, fn_inputviscosity * _fn_stresslimit / secondInvFn), # if over limit, reduce viscosity (True, fn_inputviscosity) ]) # else return viscosity # this function is not based on a c function itself, so instead point the c pointer to the conditionals. self._fncself = self._conditional._fncself # build parent super(stress_limiting_viscosity, self).__init__( argument_fns=[_fn_stress, _fn_stresslimit, _fn_inputviscosity], **kwargs)