MCPcopy Index your code
hub / github.com/pytorch/pytorch / build_err_msg

Function build_err_msg

torch/_numpy/testing/utils.py:98–129  ·  view source on GitHub ↗
(
    arrays,
    err_msg,
    header="Items are not equal:",
    verbose=True,
    names=("ACTUAL", "DESIRED"),
    precision=8,
)

Source from the content-addressed store, hash-verified

96
97
98def build_err_msg(
99 arrays,
100 err_msg,
101 header="Items are not equal:",
102 verbose=True,
103 names=("ACTUAL", "DESIRED"),
104 precision=8,
105):
106 msg = ["\n" + header]
107 if err_msg:
108 if err_msg.find("\n") == -1 and len(err_msg) < 79 - len(header):
109 msg = [msg[0] + " " + err_msg]
110 else:
111 msg.append(err_msg)
112 if verbose:
113 for i, a in enumerate(arrays):
114 if isinstance(a, ndarray):
115 # precision argument is only needed if the objects are ndarrays
116 # r_func = partial(array_repr, precision=precision)
117 r_func = ndarray.__repr__
118 else:
119 r_func = repr
120
121 try:
122 r = r_func(a)
123 except Exception as exc:
124 r = f"[repr failed for <{type(a).__name__}>: {exc}]"
125 if r.count("\n") > 3:
126 r = "\n".join(r.splitlines()[:3])
127 r += "..."
128 msg.append(f" {names[i]}: {r}")
129 return "\n".join(msg)
130
131
132def assert_equal(actual, desired, err_msg="", verbose=True):

Callers 5

assert_equalFunction · 0.85
_build_err_msgFunction · 0.85
assert_approx_equalFunction · 0.85
func_assert_same_posFunction · 0.85
assert_array_compareFunction · 0.85

Calls 5

isinstanceFunction · 0.85
findMethod · 0.45
appendMethod · 0.45
countMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…