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 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 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 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 dot(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(
            localization, arguments, ['out'], {
                'out': numpy.ndarray,
            }, 'dot')

        if isinstance(dvar, StypyTypeError):
            return dvar

        if Number == type(arguments[0]) and Number == type(arguments[1]):
            return call_utilities.cast_to_greater_numpy_type(
                arguments[0], arguments[1])

        if Number == type(arguments[0]) and call_utilities.is_iterable(
                arguments[1]):
            c_t = get_contained_elements_type(localization, arguments[1])
            if not 'out' in dvar.keys():
                return call_utilities.create_numpy_array(c_t)
            else:
                set_contained_elements_type(localization, dvar['out'], c_t)
                return dvar['out']

        if Number == type(arguments[1]) and call_utilities.is_iterable(
                arguments[0]):
            c_t = get_contained_elements_type(localization, arguments[0])
            if not 'out' in dvar.keys():
                return call_utilities.create_numpy_array(c_t)
            else:
                set_contained_elements_type(localization, dvar['out'], c_t)
                return dvar['out']

        if call_utilities.is_iterable(
                arguments[0]) and call_utilities.is_iterable(arguments[1]):
            if call_utilities.get_dimensions(
                    localization,
                    arguments[0]) == 1 and call_utilities.get_dimensions(
                        localization, arguments[1]) == 1:
                return call_utilities.cast_to_greater_numpy_type(
                    call_utilities.get_inner_type(localization, arguments[0]),
                    call_utilities.get_inner_type(localization, arguments[1]))

            typ = call_utilities.cast_to_greater_numpy_type(
                call_utilities.get_inner_type(localization, arguments[0]),
                call_utilities.get_inner_type(localization, arguments[1]))
            for i in range(
                    call_utilities.get_dimensions(localization, arguments[0])):
                typ = call_utilities.create_numpy_array(typ)

            if not 'out' in dvar.keys():
                return typ
            else:
                set_contained_elements_type(
                    localization, dvar['out'],
                    get_contained_elements_type(localization, typ))
                return dvar['out']

        return arguments[0]
Beispiel #6
0
    def iadd(localization, proxy_obj, arguments):
        if call_utilities.is_iterable(
                arguments[0]) and call_utilities.is_iterable(arguments[1]):
            if isinstance(
                    arguments[0].get_wrapped_type(), list) and isinstance(
                        arguments[1].get_wrapped_type(), tuple):
                t1 = get_contained_elements_type(localization, arguments[0])
                t2 = get_contained_elements_type(localization, arguments[1])

                tEnd = UnionType.add(t1, t2)

                set_contained_elements_type(localization, arguments[0], tEnd)
                return arguments[0]

        return None
Beispiel #7
0
    def unique(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments, ['return_index', 'return_inverse', 'return_counts'], {
            'return_index': bool,
            'return_inverse': bool,
            'return_counts': bool,
        }, 'unique')

        if isinstance(dvar, StypyTypeError):
            return dvar

        if Number == type(arguments[0]):
            ret_arr = call_utilities.create_numpy_array(arguments[0])
        else:
            ret_arr = call_utilities.create_numpy_array(get_contained_elements_type(localization, arguments[0]))

        if len(dvar.keys()) == 0:
            return ret_arr

        tup = wrap_type(tuple())
        union = UnionType.add(ret_arr, call_utilities.create_numpy_array(numpy.int32()))

        if len(dvar.keys()) == 1:
            set_contained_elements_type(localization, tup, union)
        if len(dvar.keys()) == 2:
            union = UnionType.add(union, call_utilities.create_numpy_array(numpy.int32()))
            set_contained_elements_type(localization, tup, union)
        if len(dvar.keys()) == 3:
            union = UnionType.add(union, call_utilities.create_numpy_array(numpy.int32()))
            union = UnionType.add(union, call_utilities.create_numpy_array(numpy.int32()))
            set_contained_elements_type(localization, tup, union)

        return tup
    def reshape(localization, proxy_obj, arguments):
        if Number == type(arguments[0]):
            return call_utilities.create_numpy_array(arguments[0], False)

        shape_levels = len(arguments) - 1
        if Str == type(arguments[-1]):
            shape_levels -= 1

        if shape_levels == 0:
            return StypyTypeError(
                localization,
                "Invalid 'shape' parameter for reshape call: There must be at least one shape element"
            )

        if IterableDataStructure == type(arguments[1]):
            shape_levels = 2

        if len(arguments) > 2 and not Str == type(
                arguments[-1]) and not Integer == type(arguments[-1]):
            return StypyTypeError(
                localization,
                "Invalid 'order' parameter for reshape call: {0}".format(
                    str(arguments[-1])))

        contained = get_contained_elements_type(localization, arguments[0])

        for i in range(shape_levels):
            contained = call_utilities.create_numpy_array(contained)
        return contained
Beispiel #9
0
    def outer(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments, ['out'],{
            'out': numpy.ndarray,
        }, 'outer', 2)

        if isinstance(dvar, StypyTypeError):
            return dvar

        t1 = get_contained_elements_type(localization, arguments[0])
        t2 = get_contained_elements_type(localization, arguments[1])
        l = wrap_contained_type(list())
        set_contained_elements_type(localization, l, call_utilities.cast_to_greater_numpy_type(t1, t2))

        if 'out' in dvar:
            set_contained_elements_type(localization, dvar['out'], l)

        return call_utilities.create_numpy_array(l)
 def heappush(localization, proxy_obj, arguments):
     ex_type = get_contained_elements_type(localization, arguments[0])
     if ex_type is UndefinedType:
         u = arguments[1]
     else:
         u = UnionType.add(ex_type, arguments[1])
     set_contained_elements_type(localization, arguments[0], u)
     return types.NoneType
Beispiel #11
0
    def tile(localization, proxy_obj, arguments):
        dims = 1
        if len(arguments) == 2 and call_utilities.is_iterable(arguments[1]):
            dims = call_utilities.get_dimensions(localization, arguments[1])

        if Number == type(arguments[0]):
            return call_utilities.create_numpy_array_n_dimensions(arguments[0], dims)

        return call_utilities.create_numpy_array_n_dimensions(get_contained_elements_type(localization, arguments[0]), dims)
Beispiel #12
0
    def block(localization, proxy_obj, arguments):
        union = None
        for arg in arguments:
            if call_utilities.is_iterable(arg):
                union = UnionType.add(
                    union, get_contained_elements_type(localization, arg))
            else:
                union = UnionType.add(union, arg)

        return call_utilities.create_numpy_array(union)
Beispiel #13
0
    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))
Beispiel #15
0
    def convolve(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments, ['mode'],{
            'mode': Str,
        }, 'convolve', 2)

        dvar = call_utilities.check_possible_values(dvar, 'mode', ['full', 'same', 'valid'])
        if isinstance(dvar, StypyTypeError):
            return dvar

        if Number == type(arguments[0]):
            type1 = arguments[0]
        else:
            type1 = get_contained_elements_type(localization, arguments[0])

        if Number == type(arguments[1]):
            type2 = arguments[1]
        else:
            type2 = get_contained_elements_type(localization, arguments[1])

        return call_utilities.create_numpy_array(call_utilities.cast_to_greater_numpy_type(type1, type2))
    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]))
Beispiel #17
0
    def cross(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments, ['axisa', 'axisb','axisc', 'axis'],{
            'axisa': Integer,
            'axisb': Integer,
            'axisc': Integer,
            'axis': Integer,
        }, 'cross', 2)

        if isinstance(dvar, StypyTypeError):
            return dvar

        if Number == type(arguments[0]):
            type1 = arguments[0]
        else:
            type1 = get_contained_elements_type(localization, arguments[0])

        if Number == type(arguments[1]):
            type2 = arguments[1]
        else:
            type2 = get_contained_elements_type(localization, arguments[1])

        return call_utilities.create_numpy_array(call_utilities.cast_to_greater_numpy_type(type1, type2))
Beispiel #18
0
    def ediff1d(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments, ['to_end', 'to_begin'], {
            'to_end': IterableDataStructure,
            'to_begin': IterableDataStructure,
        }, 'ediff1d')

        if isinstance(dvar, StypyTypeError):
            return dvar

        if Number == type(arguments[0]):
            return call_utilities.create_numpy_array(arguments[0])
        else:
            return call_utilities.create_numpy_array(get_contained_elements_type(localization, arguments[0]))
Beispiel #19
0
    def concatenate(localization, proxy_obj, arguments):
        union = None
        for arg in arguments:
            if call_utilities.is_iterable(arg):
                union = UnionType.add(
                    union, get_contained_elements_type(localization, arg))
            else:
                return StypyTypeError(
                    localization,
                    "A non-iterable parameter {0} was passed to the concatenate function"
                    .format(str(arg)))

        return call_utilities.create_numpy_array(union)
Beispiel #20
0
    def ascontiguousarray(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments, ['dtype'],{
            'dtype': type,
        }, 'ascontiguousarray')

        if 'dtype' in dvar.keys():
            dtype = dvar['dtype']
        else:
            dtype = None

        if call_utilities.is_iterable(arguments[0]):
            typ = get_contained_elements_type(localization, arguments[0])
        else:
            typ = arguments[0]

        return call_utilities.create_numpy_array(typ, dtype=dtype)
    def reduceat(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(
            localization, arguments, ['axis', 'dtype', 'out'], {
                'axis': Integer,
                'dtype': type,
                'out': numpy.ndarray,
            }, 'reduceat', 2)

        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 arguments[0]
    def empty(localization, proxy_obj, arguments):
        if Number == type(arguments[0]):
            return call_utilities.create_numpy_array(numpy.float64(), False)

        dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments,
                                                       ['dtype', 'order'], {
                                                           'dtype': type,
                                                           'order': Str,
                                                       }, 'array')

        if isinstance(dvar, StypyTypeError):
            return dvar

        if 'dtype' in dvar:
            dtype = dvar['dtype']
        else:
            dtype = None

        return call_utilities.create_numpy_array(
            get_contained_elements_type(localization, arguments[0]), dtype)
Beispiel #23
0
    def dstack(localization, proxy_obj, arguments):
        elem_list = wrap_contained_type(list())
        for arg in arguments:
            if call_utilities.is_iterable(arg):
                cont = get_contained_elements_type(localization, arg)
                if call_utilities.is_iterable(cont):
                    union2 = UnionType.add(elem_list.get_contained_type(),
                                           cont.get_contained_type())
                    elem_list.set_contained_type(union2)
                else:
                    union2 = UnionType.add(elem_list.get_contained_type(),
                                           cont)
                    elem_list.set_contained_type(union2)
            else:
                return StypyTypeError(
                    localization,
                    "A non-iterable parameter {0} was passed to the dstack function"
                    .format(str(arg)))

        return call_utilities.create_numpy_array(elem_list)
Beispiel #24
0
    def stack(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments,
                                                       ['axis'], {
                                                           'axis': Integer,
                                                       }, 'stack')

        if isinstance(dvar, StypyTypeError):
            return dvar

        union = None
        for arg in arguments:
            if call_utilities.is_iterable(arg):
                union = UnionType.add(
                    union, get_contained_elements_type(localization, arg))
            else:
                return StypyTypeError(
                    localization,
                    "A non-iterable parameter {0} was passed to the stack function"
                    .format(str(arg)))

        return call_utilities.create_numpy_array(union)
    def array(localization, proxy_obj, arguments):
        if Number == type(arguments[0]):
            return call_utilities.create_numpy_array(arguments[0], False)

        dvar = call_utilities.parse_varargs_and_kwargs(
            localization, arguments,
            ['dtype', 'copy', 'order', 'subok', 'ndmin'], {
                'dtype': type,
                'copy': bool,
                'order': Str,
                'subok': bool,
                'ndmin': Integer,
            }, 'array')

        if isinstance(dvar, StypyTypeError):
            return dvar

        if 'dtype' in dvar:
            dtype = dvar['dtype']
        else:
            dtype = None

        return call_utilities.create_numpy_array(
            get_contained_elements_type(localization, arguments[0]), dtype)
 def heappop(localization, proxy_obj, arguments):
     return get_contained_elements_type(localization, arguments[0])
Beispiel #27
0
 def vsplit(localization, proxy_obj, arguments):
     return call_utilities.create_numpy_array(
         get_contained_elements_type(localization, arguments[0]))
Beispiel #28
0
 def dsplit(localization, proxy_obj, arguments):
     l = wrap_contained_type(list())
     l.set_contained_type(
         call_utilities.create_numpy_array(
             get_contained_elements_type(localization, arguments[0])))
     return l