def reciprocal(localization, proxy_obj, arguments, func_name='reciprocal'): dvar = call_utilities.parse_varargs_and_kwargs( localization, arguments, ['out', 'where'], { 'out': numpy.ndarray, 'where': numpy.ndarray, }, func_name) if isinstance(dvar, StypyTypeError): return dvar if Number == type(arguments[0]): ret = call_utilities.cast_to_numpy_type(numpy.float64()) else: try: ret = call_utilities.create_numpy_array_n_dimensions( call_utilities.cast_to_numpy_type( call_utilities.get_inner_type(localization, arguments[0])), call_utilities.get_dimensions(localization, arguments[0])) except Exception as ex: return StypyTypeError(localization, str(ex)) if 'out' in dvar.keys(): set_contained_elements_type(localization, dvar['out'], ret) return dvar['out'] return ret
def nansum(localization, proxy_obj, arguments): if Number == type(arguments[0]): return call_utilities.cast_to_numpy_type(arguments[0]) dvar = call_utilities.parse_varargs_and_kwargs( localization, arguments, ['axis', 'dtype', 'out', 'keepdims'], { 'axis': int, 'dtype': type, 'out': numpy.ndarray, 'keepdims': bool }, 'nansum') if isinstance(dvar, StypyTypeError): return dvar if 'out' in dvar.keys(): set_contained_elements_type( localization, dvar['out'], get_contained_elements_type(localization, arguments[0])) return dvar['out'] if 'axis' in dvar.keys(): return call_utilities.create_numpy_array( get_contained_elements_type(localization, arguments[0])) return call_utilities.cast_to_numpy_type( get_contained_elements_type(localization, arguments[0]))
def __getitem__(localization, proxy_obj, arguments): r = TypeWrapper.get_wrapper_of(proxy_obj.__self__) index_selector = arguments[0] if isinstance(index_selector, tuple): index_selector = index_selector[0] dims = call_utilities.get_dimensions(localization, r) if dims > 1: if call_utilities.is_iterable(arguments[0]): if call_utilities.is_iterable(arguments[0].get_contained_type()): return call_utilities.create_numpy_array_n_dimensions( call_utilities.cast_to_numpy_type(call_utilities.get_inner_type(localization, r)), dims - 1) contained = call_utilities.cast_to_numpy_type(call_utilities.get_inner_type(localization, r)) for i in range(dims - 1): contained = UnionType.add(contained, call_utilities.create_numpy_array_n_dimensions(r.get_contained_type(), i + 1)) else: contained = r.get_contained_type() if isinstance(index_selector, TypeWrapper): if isinstance(index_selector.wrapped_type, slice) or ( call_utilities.is_iterable(index_selector) and not isinstance(index_selector.wrapped_type, tuple)): l = call_utilities.create_numpy_array(contained) return l return contained # proxy_obj.__self__.dtype.type()
def __div__(localization, proxy_obj, arguments, func_name='__div__'): # dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments, ['out', 'where'], { # 'out': numpy.ndarray, # 'where': numpy.ndarray, # }, func_name, 2) # # if isinstance(dvar, StypyTypeError): # return dvar try: dims = 0 if call_utilities.is_iterable(arguments[0]): param0 = call_utilities.get_inner_type(localization, arguments[0]) dims = call_utilities.get_dimensions(localization, arguments[0]) else: param0 = arguments[0] if dims > 0: ret = call_utilities.create_numpy_array_n_dimensions( call_utilities.cast_to_numpy_type(param0), dims) else: ret = call_utilities.create_numpy_array(call_utilities.cast_to_numpy_type(param0)) except Exception as ex: return StypyTypeError(localization, str(ex)) # if 'out' in dvar.keys(): # set_contained_elements_type(localization, dvar['out'], # ret) # return dvar['out'] return ret
def prod(localization, proxy_obj, arguments): if Number == type(arguments[0]): return call_utilities.cast_to_numpy_type(arguments[0]) dvar = call_utilities.parse_varargs_and_kwargs( localization, arguments, ['axis', 'dtype', 'out'], { 'axis': [ types.NoneType, Integer, IterableDataStructureWithTypedElements(Integer) ], 'dtype': type, 'out': numpy.ndarray, 'keepdims': bool }, 'prod') if isinstance(dvar, StypyTypeError): return dvar if 'out' in dvar.keys(): set_contained_elements_type( localization, dvar['out'], get_contained_elements_type(localization, arguments[0])) return dvar['out'] if 'axis' in dvar.keys(): return call_utilities.create_numpy_array( get_contained_elements_type(localization, arguments[0])) return call_utilities.cast_to_numpy_type( get_contained_elements_type(localization, arguments[0]))
def det(localization, proxy_obj, arguments): param0 = call_utilities.get_inner_type(localization, arguments[0]) dims = call_utilities.get_dimensions(localization, arguments[0]) if dims == 1: return call_utilities.cast_to_numpy_type(param0) else: return call_utilities.create_numpy_array_n_dimensions( call_utilities.cast_to_numpy_type(param0), dims)
def clip(localization, proxy_obj, arguments): if Number == type(arguments[0]): return call_utilities.cast_to_numpy_type(arguments[0]) dvar = call_utilities.parse_varargs_and_kwargs( localization, arguments, ['a_min', 'a_max', 'out'], { 'a_min': [ Integer, IterableDataStructureWithTypedElements(Integer), types.NoneType ], 'a_max': [ Integer, IterableDataStructureWithTypedElements(Integer), types.NoneType ], 'out': numpy.ndarray, }, 'clip') if isinstance(dvar, StypyTypeError): return dvar if 'out' in dvar.keys(): set_contained_elements_type( localization, dvar['out'], get_contained_elements_type(localization, arguments[0])) return dvar['out'] return call_utilities.create_numpy_array( get_contained_elements_type(localization, arguments[0]))
def trace(localization, proxy_obj, arguments): dvar = call_utilities.parse_varargs_and_kwargs( localization, arguments, ['offset', 'axis1', ' axis2', 'dtype', 'out'], { 'offset': Integer, 'axis1': Integer, 'axis2': Integer, 'dtype': type, 'out': numpy.ndarray, }, 'trace') if isinstance(dvar, StypyTypeError): return dvar dim = call_utilities.get_dimensions(localization, arguments[0]) if dim == 1: return call_utilities.cast_to_numpy_type( get_contained_elements_type(localization, arguments[0])) else: ret = call_utilities.create_numpy_array( call_utilities.get_inner_type(localization, arguments[0])) if 'out' in dvar.keys(): if dim == 1 or not (call_utilities.get_dimensions( localization, dvar['out']) == 1): return StypyTypeError( localization, "Wrong dimensions of out parameter in trace call") set_contained_elements_type( localization, dvar['out'], get_contained_elements_type(localization, arguments[0])) return dvar['out'] return ret
def nan_to_num(localization, proxy_obj, arguments): if RealNumber == type(arguments[0]): return call_utilities.cast_to_numpy_type(arguments[0]) if can_store_elements(arguments[0]): return call_utilities.create_numpy_array( get_contained_elements_type(arguments[0])) return call_utilities.create_numpy_array(arguments[0].wrapped_type)
def einsum(localization, proxy_obj, arguments): if isinstance(arguments[-1], dict): if Str == type(arguments[0]): arg_num = 2 else: arg_num = 1 dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments, ['out', 'dtype', 'order', 'casting', 'optimize'], { 'out': IterableDataStructure, 'dtype': type, 'order': Str, 'casting': Str, 'optimize': [bool, Str] }, 'einsum', arg_num) if isinstance(dvar, StypyTypeError): return dvar val_temp = call_utilities.check_possible_values(dvar, 'order', ['C', 'F', 'A', 'K']) if isinstance(val_temp, StypyTypeError): return val_temp val_temp = call_utilities.check_possible_values(dvar, 'casting', ['no', 'equiv', 'safe', 'same_kind', 'unsafe']) if isinstance(val_temp, StypyTypeError): return val_temp val_temp = call_utilities.check_possible_values(dvar, 'optimize', ['greedy', 'optimal', False, True]) if isinstance(val_temp, StypyTypeError): return val_temp arguments = arguments[:-1] else: dvar = dict() typ = None if Str == type(arguments[0]): arg_list = arguments[1:] if Number == type(arguments[1]) and 'out' in dvar: return dvar['out'] else: arg_list = arguments for arg in arg_list: if call_utilities.is_iterable(arg): typ_temp = call_utilities.cast_to_numpy_type(call_utilities.get_inner_type(localization, arg)) typ = call_utilities.cast_to_greater_numpy_type(typ, typ_temp) union = UnionType.add(typ, call_utilities.create_numpy_array(DynamicType)) if 'out' in dvar: set_contained_elements_type(localization, dvar['out'], DynamicType) return call_utilities.create_numpy_array(DynamicType) return union
def __getitem__(localization, proxy_obj, arguments): if isinstance(arguments[0], tuple): num = len(arguments[0]) typ = call_utilities.cast_to_numpy_type(arguments[0][0].get_wrapped_type().start) union = None for i in range(num): union = union_type.UnionType.add(union, call_utilities.create_numpy_array_n_dimensions(typ, num)) tup = call_utilities.wrap_contained_type((union,)) tup.set_contained_type(union) return tup return None
def negative(localization, proxy_obj, arguments): dvar = call_utilities.parse_varargs_and_kwargs( localization, arguments, ['out'], { 'out': numpy.ndarray, }, 'logical_not') if isinstance(dvar, StypyTypeError): return dvar if Number == type(arguments[0]): return call_utilities.cast_to_numpy_type(arguments[0]) if 'out' in dvar.keys(): set_contained_elements_type( localization, dvar['out'], get_contained_elements_type(localization, arguments[0])) return dvar['out'] return call_utilities.create_numpy_array( get_contained_elements_type(localization, arguments[0]))
def sum(localization, proxy_obj, arguments): dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments, ['axis', 'dtype', 'out'], { 'axis': [types.NoneType, Integer, IterableDataStructureWithTypedElements(Integer)], 'dtype': type, 'out': numpy.ndarray, 'keepdims': bool}, 'sum') if isinstance(dvar, StypyTypeError): return dvar r = TypeWrapper.get_wrapper_of(proxy_obj.__self__) if 'out' in dvar.keys(): set_contained_elements_type(localization, dvar['out'], get_contained_elements_type(localization, r)) return dvar['out'] if 'axis' in dvar.keys(): return call_utilities.create_numpy_array(get_contained_elements_type(localization, r)) return call_utilities.cast_to_numpy_type(get_contained_elements_type(localization, r))
def round_(localization, proxy_obj, arguments): if Number == type(arguments[0]): return call_utilities.cast_to_numpy_type(arguments[0]) dvar = call_utilities.parse_varargs_and_kwargs( localization, arguments, ['decimals', 'out'], { 'decimals': Integer, 'out': numpy.ndarray, }, 'round_') if isinstance(dvar, StypyTypeError): return dvar if 'out' in dvar.keys(): set_contained_elements_type( localization, dvar['out'], get_contained_elements_type(localization, arguments[0])) return dvar['out'] return call_utilities.create_numpy_array( get_contained_elements_type(localization, arguments[0]))
def real_if_close(localization, proxy_obj, arguments): if call_utilities.is_numpy_array(arguments[0]): return call_utilities.cast_to_numpy_type(arguments[0]) return call_utilities.create_numpy_array(arguments[0], False)