def testLocateTensorElement2DNoEllipsisWithNumericSummary(self): a = np.linspace(0.0, 1.0 - 1.0 / 16.0, 16).reshape([4, 4]) out = tensor_format.format_tensor(a, "a", include_numeric_summary=True) cli_test_utils.assert_lines_equal_ignoring_whitespace( self, [ "Tensor \"a\":", "", "Numeric summary:", "| 0 + | total |", "| 1 15 | 16 |", "| min max mean std |" ], out.lines[:6]) cli_test_utils.assert_array_lines_close( self, [0.0, 0.9375, 0.46875, 0.28811076429], out.lines[6:7]) cli_test_utils.assert_array_lines_close(self, a, out.lines[8:]) self._checkTensorElementLocations(out, a) with self.assertRaisesRegex(ValueError, "Indices exceed tensor dimensions"): tensor_format.locate_tensor_element(out, [1, 4]) with self.assertRaisesRegex(ValueError, "Indices contain negative"): tensor_format.locate_tensor_element(out, [-1, 2]) with self.assertRaisesRegex(ValueError, "Dimensions mismatch"): tensor_format.locate_tensor_element(out, [0])
def testNumericSummaryOnFloatMissingCategories(self): x = np.array([np.nan, np.nan]) out = tensor_format.numeric_summary(x) self.assertEqual(2, len(out.lines)) cli_test_utils.assert_lines_equal_ignoring_whitespace( self, ["| nan | total |", "| 2 | 2 |"], out.lines[:2]) x = np.array([-np.inf, np.inf, 0, 0, np.inf, np.inf]) out = tensor_format.numeric_summary(x) cli_test_utils.assert_lines_equal_ignoring_whitespace( self, [ "| -inf 0 +inf | total |", "| 1 2 3 | 6 |", "| min max mean std |" ], out.lines[:3]) cli_test_utils.assert_array_lines_close(self, [0.0, 0.0, 0.0, 0.0], out.lines[3:4]) x = np.array([-120, 120, 130]) out = tensor_format.numeric_summary(x) cli_test_utils.assert_lines_equal_ignoring_whitespace( self, [ "| - + | total |", "| 1 2 | 3 |", "| min max mean std |" ], out.lines[:3]) cli_test_utils.assert_array_lines_close( self, [-120, 130, 43.3333333333, 115.566238822], out.lines[3:4])
def testNumericSummaryOnFloatMissingCategories(self): x = np.array([np.nan, np.nan]) out = tensor_format.numeric_summary(x) self.assertEqual(2, len(out.lines)) cli_test_utils.assert_lines_equal_ignoring_whitespace( self, ["| nan | total |", "| 2 | 2 |"], out.lines[:2]) x = np.array([-np.inf, np.inf, 0, 0, np.inf, np.inf]) out = tensor_format.numeric_summary(x) cli_test_utils.assert_lines_equal_ignoring_whitespace( self, ["| -inf 0 +inf | total |", "| 1 2 3 | 6 |", "| min max mean std |"], out.lines[:3]) cli_test_utils.assert_array_lines_close( self, [0.0, 0.0, 0.0, 0.0], out.lines[3:4]) x = np.array([-120, 120, 130]) out = tensor_format.numeric_summary(x) cli_test_utils.assert_lines_equal_ignoring_whitespace( self, ["| - + | total |", "| 1 2 | 3 |", "| min max mean std |"], out.lines[:3]) cli_test_utils.assert_array_lines_close( self, [-120, 130, 43.3333333333, 115.566238822], out.lines[3:4])
def testLocateTensorElement2DNoEllipsisWithNumericSummary(self): a = np.linspace(0.0, 1.0 - 1.0 / 16.0, 16).reshape([4, 4]) out = tensor_format.format_tensor(a, "a", include_numeric_summary=True) cli_test_utils.assert_lines_equal_ignoring_whitespace( self, ["Tensor \"a\":", "", "Numeric summary:", "| 0 + | total |", "| 1 15 | 16 |", "| min max mean std |"], out.lines[:6]) cli_test_utils.assert_array_lines_close( self, [0.0, 0.9375, 0.46875, 0.28811076429], out.lines[6:7]) cli_test_utils.assert_array_lines_close(self, a, out.lines[8:]) self._checkTensorElementLocations(out, a) with self.assertRaisesRegexp( ValueError, "Indices exceed tensor dimensions"): tensor_format.locate_tensor_element(out, [1, 4]) with self.assertRaisesRegexp( ValueError, "Indices contain negative"): tensor_format.locate_tensor_element(out, [-1, 2]) with self.assertRaisesRegexp( ValueError, "Dimensions mismatch"): tensor_format.locate_tensor_element(out, [0])
def testNumericSummaryOnInt(self): x = np.array([-3] * 50 + [3] * 200 + [0], dtype=np.int32) out = tensor_format.numeric_summary(x) cli_test_utils.assert_lines_equal_ignoring_whitespace( self, [ "| - 0 + | total |", "| 50 1 200 | 251 |", "| min max mean std |" ], out.lines[:3]) cli_test_utils.assert_array_lines_close( self, [-3, 3, 1.79282868526, 2.39789673081], out.lines[3:4])
def testNumericSummaryOnInt(self): x = np.array([-3] * 50 + [3] * 200 + [0], dtype=np.int32) out = tensor_format.numeric_summary(x) cli_test_utils.assert_lines_equal_ignoring_whitespace( self, ["| - 0 + | total |", "| 50 1 200 | 251 |", "| min max mean std |"], out.lines[:3]) cli_test_utils.assert_array_lines_close( self, [-3, 3, 1.79282868526, 2.39789673081], out.lines[3:4])
def testNumericSummaryOnFloatFullHouse(self): x = np.array([np.nan, np.nan, -np.inf, np.inf, np.inf, np.inf, -2, -3, -4, 0, 1, 2, 2, 2, 2, 0, 0, 0, np.inf, np.inf, np.inf]) out = tensor_format.numeric_summary(x) cli_test_utils.assert_lines_equal_ignoring_whitespace( self, ["| nan -inf - 0 + +inf | total |", "| 2 1 3 4 5 6 | 21 |", "| min max mean std |"], out.lines[:3]) cli_test_utils.assert_array_lines_close( self, [-4.0, 2.0, 0.0, 1.95789002075], out.lines[3:4])
def testNumericSummaryOnFloatFullHouse(self): x = np.array([ np.nan, np.nan, -np.inf, np.inf, np.inf, np.inf, -2, -3, -4, 0, 1, 2, 2, 2, 2, 0, 0, 0, np.inf, np.inf, np.inf ]) out = tensor_format.numeric_summary(x) cli_test_utils.assert_lines_equal_ignoring_whitespace( self, [ "| nan -inf - 0 + +inf | total |", "| 2 1 3 4 5 6 | 21 |", "| min max mean std |" ], out.lines[:3]) cli_test_utils.assert_array_lines_close( self, [-4.0, 2.0, 0.0, 1.95789002075], out.lines[3:4])