<s> import numpy as np <EOL> from numpy import asarray <EOL> import types <EOL> from . . syntax import UntypedFn , TypedFn <EOL> from . . ndtypes import ( scalar_types , <EOL> make_array_type , ArrayT , <EOL> make_tuple_type , TupleT , <EOL> make_closure_type , ClosureT , <EOL> NoneT , NoneType , TypeValueT ) <EOL> from . . ndtypes . type_conv import typeof , register <EOL> register ( type ( None ) , NoneT , lambda _ : NoneType ) <EOL> def typeof_dtype ( dt ) : <EOL> return TypeValueT ( scalar_types . from_dtype ( dt ) ) <EOL> register ( [ np . dtype ] , TypeValueT , typeof_dtype ) <EOL> def typeof_type ( t ) : <EOL> assert hasattr ( t , '<STR_LIT>' ) , "<STR_LIT>" <EOL> dt = t ( <NUM_LIT:0> ) . dtype <EOL> pt = scalar_types . from_dtype ( dt ) <EOL> return TypeValueT ( pt ) <EOL> register ( types . TypeType , TypeValueT , typeof_type ) <EOL> def typeof_tuple ( python_tuple ) : <EOL> return make_tuple_type ( [ typeof ( elt_t ) for elt_t in python_tuple ] ) <EOL> register ( types . TupleType , TupleT , typeof_tuple ) <EOL> def typeof_array ( x ) : <EOL> x = asarray ( x ) <EOL> elt_t = scalar_types . from_dtype ( x . dtype ) <EOL> return make_array_type ( elt_t , x . ndim ) <EOL> register ( np . ndarray , ArrayT , typeof_array ) <EOL> from . . import prims <EOL> register ( ( list , xrange ) , ArrayT , typeof_array ) <EOL> from decorators import jit , macro <EOL> register ( ( list , xrange ) , ArrayT , typeof_array ) <EOL> def typeof_prim ( p ) : <EOL> from . . syntax . wrappers import build_untyped_prim_fn <EOL> untyped_fn = build_untyped_prim_fn ( p ) <EOL> return make_closure_type ( untyped_fn , ( ) ) <EOL> register ( prims . class_list , ClosureT , typeof_prim ) <EOL> def typeof_fn ( f ) : <EOL> import ast_conversion <EOL> untyped_fn = ast_conversion . translate_function_value ( f ) <EOL> closure_args = untyped_fn . python_nonlocals ( ) <EOL> closure_arg_types = map ( typeof , closure_args ) <EOL> return make_closure_type ( untyped_fn , closure_arg_types ) <EOL> register ( types . FunctionType , ClosureT , typeof_fn ) <EOL> register ( jit , ClosureT , typeof_fn ) <EOL> register ( macro , ClosureT , typeof_fn ) <EOL> register ( types . BuiltinFunctionType , ClosureT , typeof_fn ) <EOL> register ( np . ufunc , ClosureT , typeof_fn ) <EOL> register ( UntypedFn , ClosureT , typeof_fn ) <EOL> register ( TypedFn , ClosureT , typeof_fn ) </s>
