def random(localization, proxy_obj, arguments):
        # if len(arguments) == 0:
        #     return float()
        #
        # dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments, ['size'], {
        #     'size': [Integer, IterableDataStructureWithTypedElements(Integer)],
        # }, 'random', 0)
        #
        # if isinstance(dvar, StypyTypeError):
        #     return dvar
        #
        # if call_utilities.is_iterable(arguments[0]):
        #     inner_array = call_utilities.create_numpy_array(numpy.float64())
        #     return call_utilities.create_numpy_array(inner_array)
        #
        # return float()
        if len(arguments) == 0:
            return float()

        dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments, ['size'], {
            'size': [Integer, IterableDataStructureWithTypedElements(Integer)],
        }, 'random', 0)

        if isinstance(dvar, StypyTypeError):
            return dvar

        if call_utilities.is_iterable(arguments[0]):
            inner_array = call_utilities.create_numpy_array_n_dimensions(numpy.float64(), call_utilities.get_dimensions(localization, arguments[0]))
            return call_utilities.create_numpy_array(inner_array)

        return call_utilities.create_numpy_array(numpy.float64())
    def any(localization, proxy_obj, arguments):
        if Number == type(arguments[0]):
            return numpy.bool_()

        dvar = call_utilities.parse_varargs_and_kwargs(
            localization, arguments, ['axis', 'out', 'keepdims'], {
                'axis': [
                    types.NoneType, Integer,
                    IterableDataStructureWithTypedElements(Integer)
                ],
                'out':
                numpy.ndarray,
                'keepdims':
                bool
            }, 'any')

        if isinstance(dvar, StypyTypeError):
            return dvar

        if 'out' in dvar.keys():
            set_contained_elements_type(localization, dvar['out'],
                                        numpy.bool_())
            return dvar['out']

        if 'axis' in dvar.keys():
            return call_utilities.create_numpy_array(numpy.bool_())
        return numpy.bool_()
    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 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 randint(localization, proxy_obj, arguments):
        if len(arguments) == 1:
            return int()

        dvar = call_utilities.parse_varargs_and_kwargs(
            localization, arguments, ['high', 'size', 'dtype'], {
                'high': Integer,
                'size':
                [Integer,
                 IterableDataStructureWithTypedElements(Integer)],
                'dtype': type,
            }, 'randint', 1)

        if isinstance(dvar, StypyTypeError):
            return dvar

        if 'dtype' in dvar:
            if not Integer == dvar['dtype']:
                return StypyTypeError(
                    localization, "Unsupported type {0} for randint".format(
                        str(dvar['dtype'])))
        if 'size' in dvar:
            return call_utilities.create_numpy_array(numpy.int32())

        return int()
예제 #6
0
    def fromarrays(localization, proxy, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(
            localization, arguments, [
                'dtype', 'shape', 'formats', 'names', 'titles', 'aligned',
                'byteorder'
            ], {
                'dtype': type,
                'shape': AnyType,
                'formats': AnyType,
                'names': [Str,
                          IterableDataStructureWithTypedElements(Str)],
                'titles': [Str,
                           IterableDataStructureWithTypedElements(Str)],
                'aligned': bool,
                'byteorder': AnyType
            }, 'fromarrays')

        if isinstance(dvar, StypyTypeError):
            return dvar

        arr = arguments[0]

        contained = get_contained_elements_type(arr)
        if isinstance(contained, union_type.UnionType):
            contained = contained.types

        try:
            return numpy.core.records.fromarrays(contained, dvar)
        except Exception as ex:
            return DynamicType
    def MaskedArray(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments, ['mask'], {
            'mask': IterableDataStructure,
        }, 'MaskedArray')

        if isinstance(dvar, StypyTypeError):
            return dvar
        # import numpy

        # x = numpy.ndarray([1])
        # mx = numpy.ma.masked_array(x, mask=[0])
        # return mx
        # # t = call_utilities.get_inner_type(localization, arguments[0])
        # # t = 0.0
        # #
        # # return numpy.ma.masked_array(numpy.ndarray(t), [True], t)

        # arr1 = 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]),  call_utilities.get_inner_type(localization, arguments[0]), False)
        #
        # if 'mask' in dvar.keys():
        #     arr2 = call_utilities.create_numpy_array_n_dimensions(
        #         call_utilities.cast_to_numpy_type(call_utilities.get_inner_type(localization, dvar['mask'])),
        #         call_utilities.get_dimensions(localization, dvar['mask']),  call_utilities.get_inner_type(localization, arguments[0]), False)
        #
        #     arr = numpy.ma.masked_array(arr1, arr2)
        # else:
        #     arr = numpy.ma.masked_array(arr1)
        #
        # return arr
        mask = call_utilities.wrap_contained_type(numpy.ma.core.MaskedArray(arguments[0], mask=[False]))
        mask.set_contained_type(mask.wrapped_type.min())
        return mask
    def uniform(localization, proxy_obj, arguments):
        if len(arguments) == 0:
            return float()

        dvar = call_utilities.parse_varargs_and_kwargs(
            localization, arguments, ['low', 'high', 'size'], {
                'low': [
                    RealNumber,
                    IterableDataStructureWithTypedElements(RealNumber)
                ],
                'high': [
                    RealNumber,
                    IterableDataStructureWithTypedElements(RealNumber)
                ],
                'size':
                [Integer,
                 IterableDataStructureWithTypedElements(Integer)],
            }, 'uniform', 0)

        if isinstance(dvar, StypyTypeError):
            return dvar

        if call_utilities.check_parameter_type(dvar, 'low', IterableDataStructureWithTypedElements(RealNumber)) or \
                call_utilities.check_parameter_type(dvar, 'high', IterableDataStructureWithTypedElements(RealNumber)) or \
                call_utilities.check_parameter_type(dvar, 'size', IterableDataStructureWithTypedElements(RealNumber)):
            return call_utilities.create_numpy_array(numpy.float64())

        if 'size' in dvar.keys():
            return call_utilities.create_numpy_array(numpy.float64())

        return float()
예제 #9
0
    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
예제 #10
0
    def zeros_like(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments, ['dtype', 'order', 'subok'], {
            'dtype': type,
            'order': Str,
            'subok': bool,
        }, 'ones')

        if isinstance(dvar, StypyTypeError):
            return dvar

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

        t = call_utilities.check_possible_values(dvar, 'order', ['C', 'F', 'A', 'K'])
        if isinstance(t, StypyTypeError):
            return t

        if Number == type(arguments[0]):
            return call_utilities.create_numpy_array(arguments[0], dtype=dtype)
        else:
            dims = call_utilities.get_dimensions(localization, arguments[0])
            typ = call_utilities.create_numpy_array_n_dimensions(call_utilities.get_inner_type(localization, arguments[0]),
                                                                 dims, dtype=dtype)
            return typ
    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]))
예제 #12
0
    def ones(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments, ['dtype', 'order'],{
            'dtype': type,
            'order': Str,
        }, 'ones')

        if isinstance(dvar, StypyTypeError):
            return dvar

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

        t = call_utilities.check_possible_values(dvar, 'order', ['C', 'F'])
        if isinstance(t, StypyTypeError):
            return t

        if Number == type(arguments[0]):
            return call_utilities.create_numpy_array(numpy.float64(), dtype=dtype)
        else:
            dims = call_utilities.get_dimensions(localization, arguments[0])
            typ = call_utilities.create_numpy_array(numpy.float64(), dtype=dtype)

            for i in range(dims):
                typ = call_utilities.create_numpy_array(typ)

            return typ
    def zeros(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(
            localization, arguments, ['dtype', 'order'], {
                'dtype': [type, IterableDataStructure],
                'order': Str,
            }, 'zeros')

        if isinstance(dvar, StypyTypeError):
            return dvar

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

        t = call_utilities.check_possible_values(dvar, 'order', ['C', 'F'])
        if isinstance(t, StypyTypeError):
            return t

        if Number == type(arguments[0]):
            return call_utilities.create_numpy_array(numpy.float64(),
                                                     dtype=dtype)
        else:
            if call_utilities.is_iterable(dtype):
                tup = call_utilities.wrap_contained_type(tuple())
                tup.set_contained_type(numpy.float64())
                contents = call_utilities.create_numpy_array(tup)
                return call_utilities.create_numpy_array(contents)

            dims = call_utilities.get_dimensions(localization, arguments[0])
            typ = call_utilities.create_numpy_array_n_dimensions(
                numpy.float64(), dims, dtype=dtype)

            return typ
    def astype(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments,
                                                       ['dtype', 'order', 'casting', 'subok', 'copy'], {
                                                           'dtype': type,
                                                           'order': Str,
                                                           'casting': Str,
                                                           'subok': bool,
                                                           'copy': bool,
                                                       }, 'astype', 0)

        if isinstance(dvar, StypyTypeError):
            return dvar

        dvar = call_utilities.check_possible_values(dvar, 'order', ['C', 'F', 'A', 'K'])
        if isinstance(dvar, StypyTypeError):
            return dvar

        dvar = call_utilities.check_possible_values(dvar, 'casting', ['no', 'equiv', 'safe', 'same_kind', 'unsafe'])
        if isinstance(dvar, StypyTypeError):
            return dvar

        r = TypeWrapper.get_wrapper_of(proxy_obj.__self__)
        dims = call_utilities.get_dimensions(localization, r)

        if dims > 1:
            return call_utilities.create_numpy_array_n_dimensions(
                call_utilities.get_contained_elements_type(localization, r),
                dims - 1, dvar['dtype'])
        else:
            return call_utilities.create_numpy_array(call_utilities.get_contained_elements_type(localization, r),
                                                     dvar['dtype'])
예제 #15
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 fit(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(
            localization, arguments,
            ['domain', 'rcond', 'full', 'w', 'window'], {
                'domain': IterableDataStructure,
                'rcond': RealNumber,
                'full': bool,
                'w': IterableDataStructure,
                'window': IterableDataStructure,
            }, 'fit', 3)

        if isinstance(dvar, StypyTypeError):
            return dvar

        ret = call_utilities.create_numpy_array_n_dimensions(
            call_utilities.get_inner_type(localization, arguments[0]),
            call_utilities.get_dimensions(localization, arguments[0]))
        ret = numpy.polynomial.Chebyshev(ret.get_wrapped_type())

        if 'full' in dvar.keys():
            tup = wrap_contained_type(tuple())
            ld = wrap_contained_type(list())
            ld.set_contained_type(
                call_utilities.get_inner_type(localization, arguments[0]))
            un = UnionType.add(ret, ld)
            tup.set_contained_type(un)
            return tup

        return ret
    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]
예제 #18
0
    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 bincount(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(
            localization, arguments, ['weights', 'minlength'], {
                'weights': IterableDataStructure,
                'minlength': Integer,
            }, 'bincount')

        if isinstance(dvar, StypyTypeError):
            return dvar

        return call_utilities.create_numpy_array(numpy.int32())
예제 #20
0
    def allclose(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments, ['rtol', 'atol','equal_nan'],{
            'rtol': RealNumber,
            'atol': RealNumber,
            'equal_nan': bool,
        }, 'allclose', 2)

        if isinstance(dvar, StypyTypeError):
            return dvar

        return bool()
    def gradient(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(
            localization, arguments, ['vargargs', 'edge_order'], {
                'varargs': IterableDataStructureWithTypedElements(RealNumber),
                'edge_order': Integer,
            }, 'gradient')

        if isinstance(dvar, StypyTypeError):
            return dvar

        return call_utilities.create_numpy_array(
            get_contained_elements_type(arguments[0]))
    def diff(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments,
                                                       ['n', 'axis'], {
                                                           'n': Integer,
                                                           'axis': Integer,
                                                       }, 'diff')

        if isinstance(dvar, StypyTypeError):
            return dvar

        return call_utilities.create_numpy_array(
            get_contained_elements_type(arguments[0]))
    def trapz(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(
            localization, arguments, ['x', 'dx', 'axis'], {
                'x': IterableDataStructureWithTypedElements(RealNumber),
                'dx': RealNumber,
                'axis': Integer,
            }, 'trapz')

        if isinstance(dvar, StypyTypeError):
            return dvar

        return numpy.float64()
예제 #24
0
    def tensordot(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments, ['axes'],{
            'axes': [Integer, IterableDataStructureWithTypedElements(Integer)],
        }, 'tensordot', 2)

        if isinstance(dvar, StypyTypeError):
            return dvar

        l = wrap_contained_type(list())
        set_contained_elements_type(localization, l, DynamicType())

        return call_utilities.create_numpy_array(l)
    def count_nonzero(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments,
                                                       ['axis'], {
                                                           'axis': Integer,
                                                       }, 'count_nonzero')

        if isinstance(dvar, StypyTypeError):
            return dvar

        if 'axis' in dvar.keys():
            return call_utilities.create_numpy_array(numpy.int64())
        else:
            return numpy.int64()
예제 #26
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]))
예제 #27
0
    def rollaxis(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(localization, arguments, ['shift', 'axis'], {
            'shift': [Integer, IterableDataStructureWithTypedElements(Integer)],
            'axis': [Integer, IterableDataStructureWithTypedElements(Integer)],
        }, 'rollaxis', 2)

        if isinstance(dvar, StypyTypeError):
            return dvar

        t = call_utilities.get_inner_type(localization, arguments[0])
        if not Number == type(t):
            return StypyTypeError(localization, "The contents of the passed array are not numeric")

        return arguments[0]
예제 #28
0
    def lookfor(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(
            localization, arguments,
            ['module', 'import_modules', 'regenerate', 'output'], {
                'module': [Str,
                           IterableDataStructureWithTypedElements(Str)],
                'import_modules': bool,
                'regenerate': bool,
                'output': file,
            }, 'lookfor')

        if isinstance(dvar, StypyTypeError):
            return dvar

        return types.NoneType
예제 #29
0
    def divide(localization, proxy_obj, arguments, func_name='divide'):
        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

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

        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 call_utilities.is_iterable(arguments[1]):
                param1 = call_utilities.get_inner_type(localization,
                                                       arguments[1])
                temp = call_utilities.get_dimensions(localization,
                                                     arguments[1])
                if temp > dims:
                    dims = temp
            else:
                param1 = arguments[1]
            if dims > 0:
                ret = call_utilities.create_numpy_array_n_dimensions(
                    call_utilities.cast_to_greater_numpy_type(param0, param1),
                    dims)
            else:
                ret = call_utilities.cast_to_greater_numpy_type(param0, param1)

        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
예제 #30
0
    def polyfit(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(
            localization, arguments, ['rcond', 'full', 'w', 'cov'], {
                'rcond': RealNumber,
                'full': bool,
                'w': IterableDataStructure,
                'cov': bool,
            }, 'polyfit', 3)

        if isinstance(dvar, StypyTypeError):
            return dvar

        import numpy
        return call_utilities.wrap_contained_type(
            numpy.polyfit(arguments[0].get_wrapped_type(),
                          arguments[1].get_wrapped_type(), arguments[2]))