MCPcopy Create free account
hub / github.com/numpy/numpy / print_coercion_table

Function print_coercion_table

numpy/testing/print_coercion_tables.py:42–80  ·  view source on GitHub ↗
(ntypes, inputfirstvalue, inputsecondvalue, firstarray, use_promote_types=False)

Source from the content-addressed store, hash-verified

40 print()
41
42def print_coercion_table(ntypes, inputfirstvalue, inputsecondvalue, firstarray, use_promote_types=False):
43 print('+', end=' ')
44 for char in ntypes:
45 print(char, end=' ')
46 print()
47 for row in ntypes:
48 if row == 'O':
49 rowtype = GenericObject
50 else:
51 rowtype = np.obj2sctype(row)
52
53 print(row, end=' ')
54 for col in ntypes:
55 if col == 'O':
56 coltype = GenericObject
57 else:
58 coltype = np.obj2sctype(col)
59 try:
60 if firstarray:
61 rowvalue = np.array([rowtype(inputfirstvalue)], dtype=rowtype)
62 else:
63 rowvalue = rowtype(inputfirstvalue)
64 colvalue = coltype(inputsecondvalue)
65 if use_promote_types:
66 char = np.promote_types(rowvalue.dtype, colvalue.dtype).char
67 else:
68 value = np.add(rowvalue, colvalue)
69 if isinstance(value, np.ndarray):
70 char = value.dtype.char
71 else:
72 char = np.dtype(type(value)).char
73 except ValueError:
74 char = '!'
75 except OverflowError:
76 char = '@'
77 except TypeError:
78 char = '#'
79 print(char, end=' ')
80 print()
81
82
83def print_new_cast_table(*, can_cast=True, legacy=False, flags=False):

Callers 1

Calls 3

printFunction · 0.85
addMethod · 0.45
dtypeMethod · 0.45

Tested by

no test coverage detected