Hackfut Security File Manager
Current Path:
/opt/alt/python27/lib64/python2.7/site-packages/numpy/testing
opt
/
alt
/
python27
/
lib64
/
python2.7
/
site-packages
/
numpy
/
testing
/
📁
..
📄
__init__.py
(471 B)
📄
__init__.pyc
(810 B)
📄
__init__.pyo
(810 B)
📄
decorators.py
(8.26 KB)
📄
decorators.pyc
(9.79 KB)
📄
decorators.pyo
(9.79 KB)
📄
noseclasses.py
(13.51 KB)
📄
noseclasses.pyc
(11.19 KB)
📄
noseclasses.pyo
(11.19 KB)
📄
nosetester.py
(17.93 KB)
📄
nosetester.pyc
(15.88 KB)
📄
nosetester.pyo
(15.88 KB)
📄
print_coercion_tables.py
(2.62 KB)
📄
print_coercion_tables.pyc
(3.27 KB)
📄
print_coercion_tables.pyo
(3.27 KB)
📄
setup.py
(615 B)
📄
setup.pyc
(1001 B)
📄
setup.pyo
(1001 B)
📁
tests
📄
utils.py
(64.98 KB)
📄
utils.pyc
(62.59 KB)
📄
utils.pyo
(62.59 KB)
Editing: print_coercion_tables.py
"""Prints type-coercion tables for the built-in NumPy types """ from __future__ import division, absolute_import, print_function import numpy as np # Generic object that can be added, but doesn't do anything else class GenericObject(object): def __init__(self, v): self.v = v def __add__(self, other): return self def __radd__(self, other): return self dtype = np.dtype('O') def print_cancast_table(ntypes): print('X', end=' ') for char in ntypes: print(char, end=' ') print() for row in ntypes: print(row, end=' ') for col in ntypes: print(int(np.can_cast(row, col)), end=' ') print() def print_coercion_table(ntypes, inputfirstvalue, inputsecondvalue, firstarray, use_promote_types=False): print('+', end=' ') for char in ntypes: print(char, end=' ') print() for row in ntypes: if row == 'O': rowtype = GenericObject else: rowtype = np.obj2sctype(row) print(row, end=' ') for col in ntypes: if col == 'O': coltype = GenericObject else: coltype = np.obj2sctype(col) try: if firstarray: rowvalue = np.array([rowtype(inputfirstvalue)], dtype=rowtype) else: rowvalue = rowtype(inputfirstvalue) colvalue = coltype(inputsecondvalue) if use_promote_types: char = np.promote_types(rowvalue.dtype, colvalue.dtype).char else: value = np.add(rowvalue, colvalue) if isinstance(value, np.ndarray): char = value.dtype.char else: char = np.dtype(type(value)).char except ValueError: char = '!' except OverflowError: char = '@' except TypeError: char = '#' print(char, end=' ') print() print("can cast") print_cancast_table(np.typecodes['All']) print() print("In these tables, ValueError is '!', OverflowError is '@', TypeError is '#'") print() print("scalar + scalar") print_coercion_table(np.typecodes['All'], 0, 0, False) print() print("scalar + neg scalar") print_coercion_table(np.typecodes['All'], 0, -1, False) print() print("array + scalar") print_coercion_table(np.typecodes['All'], 0, 0, True) print() print("array + neg scalar") print_coercion_table(np.typecodes['All'], 0, -1, True) print() print("promote_types") print_coercion_table(np.typecodes['All'], 0, 0, False, True)
Upload File
Create Folder