当前位置: 首页>>代码示例>>Python>>正文


Python _function.Function类代码示例

本文整理汇总了Python中_function.Function的典型用法代码示例。如果您正苦于以下问题:Python Function类的具体用法?Python Function怎么用?Python Function使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Function类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, fn_stress, fn_stresslimit, fn_inputviscosity, *args, **kwargs):

        _fn_stress = _Function.convert(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.convert(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.convert(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)
开发者ID:underworldcode,项目名称:underworld2,代码行数:29,代码来源:rheology.py

示例2: __init__

    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.convert(clause[0])
            funcSet.add(conditionFn)
            resultantFn    = _Function.convert(clause[1])
            funcSet.add(resultantFn)
            self._clauses.append( (conditionFn,resultantFn) )
        
        # 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 )
开发者ID:dansand,项目名称:underworld2,代码行数:26,代码来源:branching.py

示例3: __init__

    def __init__(self, fn_input, fn_condition, fn_print=None, *args, **kwargs):

        _fn_input = _Function.convert(fn_input)
        if _fn_input == None:
            raise ValueError( "provided 'fn_input' must a 'Function' or convertible.")
        self._fn_input = _fn_input

        _fn_condition = _Function.convert(fn_condition)
        if _fn_condition == None:
            raise ValueError( "provided 'fn_condition' must a 'Function' or convertible.")
        self._fn_condition = _fn_condition

        if fn_print != None:
            _fn_print = _Function.convert(fn_print)
            if _fn_print == None:
                raise ValueError( "provided 'fn_print' must a 'Function' or convertible.")
            self._fn_print = _fn_print

        # create instance
        if not fn_print:
            self._fncself = _cfn.CustomException( self._fn_input._fncself, self._fn_condition._fncself )
        else:
            self._fncself = _cfn.CustomException( self._fn_input._fncself, self._fn_condition._fncself, self._fn_print._fncself )

        # build parent
        # note that we only pass in _fn_input as the argument_fns, as _fn_condition & _fn_print are
        # not dynamically relevant... it is only used for performing the exception check.
        super(CustomException,self).__init__(argument_fns=[_fn_input,],**kwargs)
开发者ID:dansand,项目名称:underworld2,代码行数:28,代码来源:exception.py

示例4: __init__

    def __init__(self, fn1, fn2, **kwargs):
        fn1fn = _Function.convert( fn1 )
        if not isinstance( fn1fn, _Function ):
            raise TypeError("Functions must be of type (or convertible to) 'Function'.")
        fn2fn = _Function.convert( 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.Min(self._fn1._fncself, self._fn2._fncself )
        # build parent
        super(min,self).__init__(argument_fns=[fn1fn,fn2fn],**kwargs)
开发者ID:dansand,项目名称:underworld2,代码行数:14,代码来源:misc.py

示例5: __init__

 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.fmax )
     # build parent
     super(max,self).__init__(argument_fns=[fn1fn,fn2fn],**kwargs)
开发者ID:AngelValverdePerez,项目名称:underworld2,代码行数:14,代码来源:misc.py

示例6: __init__

    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)
开发者ID:AngelValverdePerez,项目名称:underworld2,代码行数:29,代码来源:shape.py

示例7: __init__

    def __init__(self, vertices, fn=None, *args, **kwargs):

        if fn:
            self._fn = _Function.convert(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
        self._fncself = _cfn.Polygon( self._fn._fncself, threedeearray)

        # build parent
        super(Polygon,self).__init__(argument_fns=[fn,], *args, **kwargs)
开发者ID:dansand,项目名称:underworld2,代码行数:26,代码来源:shape.py

示例8: __init__

    def __init__(self, fn1, fn2, **kwargs):
        # lets convert integer powers to floats
        if isinstance(fn2, int):
            fn2 = float(fn2)
        fn1fn = _Function.convert( fn1 )
        if not isinstance( fn1fn, _Function ):
            raise TypeError("Functions must be of type (or convertible to) 'Function'.")
        fn2fn = _Function.convert( 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)
开发者ID:underworldcode,项目名称:underworld2,代码行数:17,代码来源:_math.py

示例9: __init__

    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 )
开发者ID:AngelValverdePerez,项目名称:underworld2,代码行数:46,代码来源:branching.py

示例10: __init__

    def __init__(self, fn, *args, **kwargs):

        _fn = _Function.convert(fn)
        if _fn == None:
            raise ValueError( "provided 'fn' must a 'Function' or convertible.")
        self._fn = _fn

        # create instance
        self._fncself = _cfn.MinMax( self._fn._fncself )

        # build parent
        super(min_max,self).__init__(argument_fns=[fn,],**kwargs)
开发者ID:underworldcode,项目名称:underworld2,代码行数:12,代码来源:view.py

示例11: __init__

    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)
开发者ID:AngelValverdePerez,项目名称:underworld2,代码行数:12,代码来源:exception.py

示例12: __init__

    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)
开发者ID:AngelValverdePerez,项目名称:underworld2,代码行数:12,代码来源:tensor.py

示例13: __init__

    def __init__(self, fn, *args, **kwargs):

        _fn = _Function.convert(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.get_antisymmetric )

        # build parent
        super(antisymmetric,self).__init__(argument_fns=[fn,],**kwargs)
开发者ID:dansand,项目名称:underworld2,代码行数:12,代码来源:tensor.py

示例14: __init__

    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_abs( fncself )

        # build parent
        super(abs,self).__init__(argument_fns=[fn,],**kwargs)
开发者ID:AngelValverdePerez,项目名称:underworld2,代码行数:13,代码来源:_math.py

示例15: __init__

    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)
开发者ID:AngelValverdePerez,项目名称:underworld2,代码行数:37,代码来源:rheology.py


注:本文中的_function.Function类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。