Reflect dimension in approx repr for numpy arrays.

This commit is contained in:
Kale Kundert
2018-07-30 23:22:06 -07:00
parent 253419316c
commit 7d8688d54b
2 changed files with 21 additions and 15 deletions

View File

@@ -82,14 +82,18 @@ class ApproxNumpy(ApproxBase):
"""
def __repr__(self):
# It might be nice to rewrite this function to account for the
# shape of the array...
import numpy as np
list_scalars = []
for x in np.ndindex(self.expected.shape):
list_scalars.append(self._approx_scalar(np.asscalar(self.expected[x])))
def recursive_map(f, x):
if isinstance(x, list):
return list(recursive_map(f, xi) for xi in x)
else:
return f(x)
list_scalars = recursive_map(
self._approx_scalar,
self.expected.tolist())
return "approx({!r})".format(list_scalars)
if sys.version_info[0] == 2: