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'])
Пример #2
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 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
Пример #4
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
Пример #5
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
Пример #6
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 argsort(localization, proxy_obj, arguments, fname='argsort'):
        dvar = call_utilities.parse_varargs_and_kwargs(
            localization, arguments, ['axis', 'kind', 'order'], {
                'axis': Integer,
                'kind': Str,
                'order': [Str,
                          IterableDataStructureWithTypedElements(Str)]
            }, fname)

        if isinstance(dvar, StypyTypeError):
            return dvar

        t = call_utilities.check_possible_values(
            dvar, 'kind', ['quicksort', 'mergesort', 'heapsort'])
        if isinstance(t, StypyTypeError):
            return t

        if Number == type(arguments[0]):
            return call_utilities.create_numpy_array(arguments[0])

        if call_utilities.is_numpy_array(arguments[0]):
            return arguments[0]
        return call_utilities.create_numpy_array(arguments[0])
    def genfromtxt(localization, proxy_obj, arguments):
        dvar = call_utilities.parse_varargs_and_kwargs(
            localization, arguments, [
                'fname', 'dtype', 'comments', 'delimiter', 'skiprows',
                'skip_header', 'skip_footer', 'converters', 'missing_values',
                'filling_values', 'usecols', 'names', 'excludelist',
                'deletechars', 'defaultfmt', 'autostrip', 'replace_space',
                'case_sensitive', 'unpack', 'usemask', 'loose',
                'invalid_raise', 'max_rows'
            ], {
                'fname':
                [file, Str,
                 IterableDataStructureWithTypedElements(Str)],
                'dtype':
                type,
                'comments':
                Str,
                'delimiter': [Str, Integer],
                'skiprows':
                Integer,
                'skip_header':
                Integer,
                'skip_footer':
                Integer,
                'converters':
                IterableDataStructureWithTypedElements(types.LambdaType),
                'missing_values':
                IterableDataStructureWithTypedElements(Str),
                'filling_values':
                IterableDataStructure,
                'usecols':
                IterableDataStructureWithTypedElements(Integer),
                'names':
                [bool, Str,
                 IterableDataStructureWithTypedElements(Str)],
                'excludelist':
                IterableDataStructureWithTypedElements(Str),
                'deletechars':
                Str,
                'defaultfmt':
                Str,
                'autostrip':
                bool,
                'replace_space':
                Str,
                'case_sensitive': [bool, Str],
                'unpack':
                bool,
                'usemask':
                bool,
                'loose':
                bool,
                'invalid_raise':
                bool,
                'max_rows':
                Integer,
            }, 'genfromtxt', 0)

        if isinstance(dvar, StypyTypeError):
            return dvar

        if 'case_sensitive' in dvar.keys():
            if Str == type(dvar['case_sensitive']):
                temp = call_utilities.check_possible_values(
                    dvar, 'case_sensitive', ['upper', 'lower'])
                if isinstance(temp, StypyTypeError):
                    return temp

        return call_utilities.create_numpy_array(DynamicType())