Example #1
0
def _add_aliases():
    for type_name, info in typeinfo.items():
        if isinstance(info, type):
            continue
        name = english_lower(type_name)

        # insert bit-width version for this class (if relevant)
        base, bit, char = bitname(info.type)
        if base[-3:] == 'int' or char[0] in 'ui':
            continue
        if base != '':
            myname = "%s%d" % (base, bit)
            if (name not in ('longdouble', 'clongdouble')
                    or myname not in allTypes):
                base_capitalize = english_capitalize(base)
                if base == 'complex':
                    na_name = '%s%d' % (base_capitalize, bit // 2)
                elif base == 'bool':
                    na_name = base_capitalize
                else:
                    na_name = "%s%d" % (base_capitalize, bit)

                allTypes[myname] = info.type

                # add mapping for both the bit name and the numarray name
                sctypeDict[myname] = info.type
                sctypeDict[na_name] = info.type

                # add forward, reverse, and string mapping to numarray
                sctypeNA[na_name] = info.type
                sctypeNA[info.type] = na_name
                sctypeNA[info.char] = na_name
        if char != '':
            sctypeDict[char] = info.type
            sctypeNA[char] = na_name
def _add_aliases():
    for type_name, info in typeinfo.items():
        if isinstance(info, type):
            continue
        name = english_lower(type_name)

        # insert bit-width version for this class (if relevant)
        base, bit, char = bitname(info.type)
        if base[-3:] == 'int' or char[0] in 'ui':
            continue
        if base != '':
            myname = "%s%d" % (base, bit)
            if (name not in ('longdouble', 'clongdouble') or
                   myname not in allTypes):
                base_capitalize = english_capitalize(base)
                if base == 'complex':
                    na_name = '%s%d' % (base_capitalize, bit//2)
                elif base == 'bool':
                    na_name = base_capitalize
                else:
                    na_name = "%s%d" % (base_capitalize, bit)

                allTypes[myname] = info.type

                # add mapping for both the bit name and the numarray name
                sctypeDict[myname] = info.type
                sctypeDict[na_name] = info.type

                # add forward, reverse, and string mapping to numarray
                sctypeNA[na_name] = info.type
                sctypeNA[info.type] = na_name
                sctypeNA[info.char] = na_name
        if char != '':
            sctypeDict[char] = info.type
            sctypeNA[char] = na_name
Example #3
0
def _add_types():
    for type_name, info in typeinfo.items():
        name = english_lower(type_name)
        if not isinstance(info, type):
            # define C-name and insert typenum and typechar references also
            allTypes[name] = info.type
            sctypeDict[name] = info.type
            sctypeDict[info.char] = info.type
            sctypeDict[info.num] = info.type

        else:  # generic class
            allTypes[name] = info
def _add_types():
    for type_name, info in typeinfo.items():
        name = english_lower(type_name)
        if not isinstance(info, type):
            # define C-name and insert typenum and typechar references also
            allTypes[name] = info.type
            sctypeDict[name] = info.type
            sctypeDict[info.char] = info.type
            sctypeDict[info.num] = info.type

        else:  # generic class
            allTypes[name] = info
Example #5
0
def _construct_lookups():
    for name, val in typeinfo.items():
        if not isinstance(val, tuple):
            continue
        obj = val[-1]
        nbytes[obj] = val[2] // 8
        _alignment[obj] = val[3]
        if (len(val) > 5):
            _maxvals[obj] = val[4]
            _minvals[obj] = val[5]
        else:
            _maxvals[obj] = None
            _minvals[obj] = None
Example #6
0
def _construct_lookups():
    for name, val in typeinfo.items():
        if not isinstance(val, tuple):
            continue
        obj = val[-1]
        nbytes[obj] = val[2] // 8
        _alignment[obj] = val[3]
        if (len(val) > 5):
            _maxvals[obj] = val[4]
            _minvals[obj] = val[5]
        else:
            _maxvals[obj] = None
            _minvals[obj] = None
Example #7
0
def _construct_lookups():
    for name, info in typeinfo.items():
        if isinstance(info, type):
            continue
        obj = info.type
        nbytes[obj] = info.bits // 8
        _alignment[obj] = info.alignment
        if len(info) > 5:
            _maxvals[obj] = info.max
            _minvals[obj] = info.min
        else:
            _maxvals[obj] = None
            _minvals[obj] = None
def _construct_lookups():
    for name, info in typeinfo.items():
        if isinstance(info, type):
            continue
        obj = info.type
        nbytes[obj] = info.bits // 8
        _alignment[obj] = info.alignment
        if len(info) > 5:
            _maxvals[obj] = info.max
            _minvals[obj] = info.min
        else:
            _maxvals[obj] = None
            _minvals[obj] = None
Example #9
0
 def __new__(cls,name):
     if isinstance(name,dtype):
         dtype0 = name
         name = None
         for n,i in typeinfo.items():
             if isinstance(i,tuple) and dtype0.type is i[-1]:
                 name = n
                 break
     obj = cls._type_cache.get(name.upper(),None)
     if obj is not None:
         return obj
     obj = object.__new__(cls)
     obj._init(name)
     cls._type_cache[name.upper()] = obj
     return obj
Example #10
0
        warnings.warn(
            'sctypeNA and typeNA will be removed in v1.18 '
            'of numpy',
            VisibleDeprecationWarning,
            stacklevel=2)
        return dict.get(self, key, default)


sctypeNA = TypeNADict(
)  # Contails all leaf-node types -> numarray type equivalences
allTypes = {}  # Collect the types we will add to the module

# separate the actual type info from the abstract base classes
_abstract_types = {}
_concrete_typeinfo = {}
for k, v in typeinfo.items():
    # make all the keys lowercase too
    k = english_lower(k)
    if isinstance(v, type):
        _abstract_types[k] = v
    else:
        _concrete_typeinfo[k] = v

_concrete_types = set(v.type for k, v in _concrete_typeinfo.items())


def _bits_of(obj):
    try:
        info = next(v for v in _concrete_typeinfo.values() if v.type is obj)
    except StopIteration:
        if obj in _abstract_types.values():
Example #11
0
    """
    if s:
        return english_upper(s[0]) + s[1:]
    else:
        return s


sctypeDict = {}      # Contains all leaf-node scalar types with aliases
sctypeNA = {}        # Contails all leaf-node types -> numarray type equivalences
allTypes = {}      # Collect the types we will add to the module here


# separate the actual type info from the abtract base classes
_abstract_types = {}
_concrete_typeinfo = {}
for k, v in typeinfo.items():
    # make all the keys lowercase too
    k = english_lower(k)
    if isinstance(v, type):
        _abstract_types[k] = v
    else:
        _concrete_typeinfo[k] = v


def _evalname(name):
    k = 0
    for ch in name:
        if ch in '0123456789':
            break
        k += 1
    try:
Example #12
0
def _construct_char_code_lookup():
    for name, info in typeinfo.items():
        if not isinstance(info, type):
            if info.char not in ['p', 'P']:
                _sctype2char_dict[info.type] = info.char
def _construct_char_code_lookup():
    for name, info in typeinfo.items():
        if not isinstance(info, type):
            if info.char not in ['p', 'P']:
                _sctype2char_dict[info.type] = info.char