diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2018-09-09 15:26:16 -0700 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2018-09-10 19:15:42 -0700 |
commit | dfead64385e5ffb95b3053d5f955117fd81d4705 (patch) | |
tree | 8a79980c93cca87b9a74bb2c7c14d46f27a32033 /numpy/f2py/tests/test_compile_function.py | |
parent | 00e50a3a38d1f86e027dd1d77fd5491ade7d248a (diff) | |
download | numpy-dfead64385e5ffb95b3053d5f955117fd81d4705.tar.gz |
MAINT: Don't use `__name__` to inspect type information
It makes much more sense to get this information directly from the typeinfo / dtype, rather than roundtripping it though a string.
The following code produces the same output (on 64-bit windows, python 3) before and after this change:
```
In [4]: {
...: name: np.core.numerictypes.bitname(info.type)
...: for name, info in sorted(np.core.numerictypes._concrete_typeinfo.items())
...: }
Out[4]:
{'bool': ('bool', 8, 'b1'),
'byte': ('int', 8, 'i1'),
'cdouble': ('complex', 128, 'c16'),
'cfloat': ('complex', 64, 'c8'),
'clongdouble': ('complex', 128, 'c16'),
'datetime': ('datetime', 64, 'M8'),
'double': ('float', 64, 'f8'),
'float': ('float', 32, 'f4'),
'half': ('float', 16, 'f2'),
'int': ('int', 32, 'i4'),
'intp': ('int', 64, 'i8'),
'long': ('int', 32, 'i4'),
'longdouble': ('float', 64, 'f8'),
'longlong': ('int', 64, 'i8'),
'object': ('object', 0, 'O'),
'short': ('int', 16, 'i2'),
'string': ('bytes', 0, 'S'),
'timedelta': ('timedelta', 64, 'm8'),
'ubyte': ('uint', 8, 'u1'),
'uint': ('uint', 32, 'u4'),
'uintp': ('uint', 64, 'u8'),
'ulong': ('uint', 32, 'u4'),
'ulonglong': ('uint', 64, 'u8'),
'unicode': ('str', 0, 'U'),
'ushort': ('uint', 16, 'u2'),
'void': ('void', 0, 'V')}
```
Before this change, it was possible to call `bitname` on the abstract types, and get garbage results:
```
In [7]: {
...: name: np.core.numerictypes.bitname(t)
...: for name, t in sorted(np.core.numerictypes._abstract_types.items())
...: }
Out[7]:
{'character': ('character', 0, 'c'),
'complexfloating': ('complexfloating', 0, 'c'),
'flexible': ('flexible', 0, 'f'),
'floating': ('floating', 0, 'f'),
'generic': ('generic', 0, 'g'),
'inexact': ('inexact', 0, 'i'),
'integer': ('integer', 0, 'i'),
'number': ('number', 0, 'n'),
'signedinteger': ('signedinteger', 0, 's'),
'unsignedinteger': ('unsignedinteger', 0, 'u')}
```
Now it raises a ValueError for all abstract types
Diffstat (limited to 'numpy/f2py/tests/test_compile_function.py')
0 files changed, 0 insertions, 0 deletions