MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / check

Function check

imperative/python/megengine/tools/compare_binary_iodump.py:58–77  ·  view source on GitHub ↗
(v0, v1, name, max_err)

Source from the content-addressed store, hash-verified

56
57
58def check(v0, v1, name, max_err):
59 v0 = np.ascontiguousarray(v0, dtype=np.float32)
60 v1 = np.ascontiguousarray(v1, dtype=np.float32)
61 assert np.isfinite(v0.sum()) and np.isfinite(
62 v1.sum()
63 ), "{} not finite: sum={} vs sum={}".format(name, v0.sum(), v1.sum())
64 assert v0.shape == v1.shape, "{} shape mismatch: {} vs {}".format(
65 name, v0.shape, v1.shape
66 )
67 vdiv = np.max([np.abs(v0), np.abs(v1), np.ones_like(v0)], axis=0)
68 err = np.abs(v0 - v1) / vdiv
69 rst = err > max_err
70 if rst.sum():
71 idx = tuple(i[0] for i in np.nonzero(rst))
72 raise AssertionError(
73 "{} not equal: "
74 "shape={} nonequal_idx={} v0={} v1={} err={}".format(
75 name, v0.shape, idx, v0[idx], v1[idx], err[idx]
76 )
77 )
78
79
80def main():

Callers 1

mainFunction · 0.70

Calls 5

AssertionErrorClass · 0.85
isfiniteMethod · 0.45
sumMethod · 0.45
formatMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected