<s> from __future__ import print_function , division , absolute_import <EOL> import inspect <EOL> from . import _internal , dufunc <EOL> from . ufuncbuilder import GUFuncBuilder <EOL> from . parallel import ParallelUFuncBuilder , ParallelGUFuncBuilder <EOL> from numba . targets . registry import TargetRegistry <EOL> class _BaseVectorize ( object ) : <EOL> @ classmethod <EOL> def get_identity ( cls , kwargs ) : <EOL> return kwargs . pop ( '<STR_LIT>' , None ) <EOL> @ classmethod <EOL> def get_target_implementation ( cls , kwargs ) : <EOL> target = kwargs . pop ( '<STR_LIT:target>' , '<STR_LIT>' ) <EOL> try : <EOL> return cls . target_registry [ target ] <EOL> except KeyError : <EOL> raise ValueError ( "<STR_LIT>" % target ) <EOL> class Vectorize ( _BaseVectorize ) : <EOL> target_registry = TargetRegistry ( { '<STR_LIT>' : dufunc . DUFunc , <EOL> '<STR_LIT>' : ParallelUFuncBuilder , } ) <EOL> def __new__ ( cls , func , ** kws ) : <EOL> identity = cls . get_identity ( kws ) <EOL> imp = cls . get_target_implementation ( kws ) <EOL> return imp ( func , identity , kws ) <EOL> class GUVectorize ( _BaseVectorize ) : <EOL> target_registry = TargetRegistry ( { '<STR_LIT>' : GUFuncBuilder , <EOL> '<STR_LIT>' : ParallelGUFuncBuilder , } ) <EOL> def __new__ ( cls , func , signature , ** kws ) : <EOL> identity = cls . get_identity ( kws ) <EOL> imp = cls . get_target_implementation ( kws ) <EOL> return imp ( func , signature , identity , kws ) <EOL> def vectorize ( ftylist_or_function = ( ) , ** kws ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( ftylist_or_function , str ) : <EOL> ftylist = [ ftylist_or_function ] <EOL> elif inspect . isfunction ( ftylist_or_function ) : <EOL> return dufunc . DUFunc ( ftylist_or_function , ** kws ) <EOL> elif ftylist_or_function is not None : <EOL> ftylist = ftylist_or_function <EOL> def wrap ( func ) : <EOL> vec = Vectorize ( func , ** kws ) <EOL> for sig in ftylist : <EOL> vec . add ( sig ) <EOL> if len ( ftylist ) > <NUM_LIT:0> : <EOL> vec . disable_compile ( ) <EOL> return vec . build_ufunc ( ) <EOL> return wrap <EOL> def guvectorize ( ftylist , signature , ** kws ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( ftylist , str ) : <EOL> ftylist = [ ftylist ] <EOL> def wrap ( func ) : <EOL> guvec = GUVectorize ( func , signature , ** kws ) <EOL> for fty in ftylist : <EOL> guvec . add ( fty ) <EOL> return guvec . build_ufunc ( ) <EOL> return wrap </s>
