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 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 testNumericSummaryOnInt(self): x = np.array([-3] * 50 + [3] * 200 + [0], dtype=np.int32) out = tensor_format.numeric_summary(x) self.assertEqual("| - 0 + | total |", out.lines[0]) self.assertEqual("| 50 1 200 | 251 |", out.lines[1]) self.assertEqual( "| min max mean std |", out.lines[2]) self.assertEqual( "| -3 3 1.79282868526 2.39789673081 |", out.lines[3])
def testNumericSummaryOnBool(self): x = np.array([False, True, True, False], dtype=np.bool_) out = tensor_format.numeric_summary(x) cli_test_utils.assert_lines_equal_ignoring_whitespace( self, ["| False True | total |", "| 2 2 | 4 |"], out.lines) x = np.array([True] * 10, dtype=np.bool_) out = tensor_format.numeric_summary(x) cli_test_utils.assert_lines_equal_ignoring_whitespace( self, ["| True | total |", "| 10 | 10 |"], out.lines) x = np.array([False] * 10, dtype=np.bool_) out = tensor_format.numeric_summary(x) cli_test_utils.assert_lines_equal_ignoring_whitespace( self, ["| False | total |", "| 10 | 10 |"], out.lines) x = np.array([], dtype=np.bool_) out = tensor_format.numeric_summary(x) self.assertEqual(["No numeric summary available due to empty tensor."], out.lines)
def testNumericSummaryOnBool(self): x = np.array([False, True, True, False], dtype=np.bool) out = tensor_format.numeric_summary(x) cli_test_utils.assert_lines_equal_ignoring_whitespace( self, ["| False True | total |", "| 2 2 | 4 |"], out.lines) x = np.array([True] * 10, dtype=np.bool) out = tensor_format.numeric_summary(x) cli_test_utils.assert_lines_equal_ignoring_whitespace( self, ["| True | total |", "| 10 | 10 |"], out.lines) x = np.array([False] * 10, dtype=np.bool) out = tensor_format.numeric_summary(x) cli_test_utils.assert_lines_equal_ignoring_whitespace( self, ["| False | total |", "| 10 | 10 |"], out.lines) x = np.array([], dtype=np.bool) out = tensor_format.numeric_summary(x) self.assertEqual(["No numeric summary available due to empty tensor."], out.lines)
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 testNumericSummaryOnBool(self): x = np.array([False, True, True, False], dtype=np.bool) out = tensor_format.numeric_summary(x) self.assertEqual(2, len(out.lines)) self.assertEqual("| False True | total |", out.lines[0]) self.assertEqual("| 2 2 | 4 |", out.lines[1]) x = np.array([True] * 10, dtype=np.bool) out = tensor_format.numeric_summary(x) self.assertEqual(2, len(out.lines)) self.assertEqual("| True | total |", out.lines[0]) self.assertEqual("| 10 | 10 |", out.lines[1]) x = np.array([False] * 10, dtype=np.bool) out = tensor_format.numeric_summary(x) self.assertEqual(2, len(out.lines)) self.assertEqual("| False | total |", out.lines[0]) self.assertEqual("| 10 | 10 |", out.lines[1]) x = np.array([], dtype=np.bool) out = tensor_format.numeric_summary(x) self.assertEqual(["No numeric summary available due to empty tensor."], out.lines)
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) self.assertEqual( "| nan -inf - 0 + +inf | total |", out.lines[0]) self.assertEqual( "| 2 1 3 4 5 6 | 21 |", out.lines[1]) self.assertEqual( "| min max mean std |", out.lines[2]) self.assertEqual( "| -4.0 2.0 0.0 1.95789002075 |", out.lines[3])
def testNumericSummaryOnFloatMissingCategories(self): x = np.array([np.nan, np.nan]) out = tensor_format.numeric_summary(x) self.assertEqual(2, len(out.lines)) self.assertEqual("| nan | total |", out.lines[0]) self.assertEqual("| 2 | 2 |", out.lines[1]) x = np.array([-np.inf, np.inf, 0, 0, np.inf, np.inf]) out = tensor_format.numeric_summary(x) self.assertEqual("| -inf 0 +inf | total |", out.lines[0]) self.assertEqual("| 1 2 3 | 6 |", out.lines[1]) self.assertEqual("| min max mean std |", out.lines[2]) self.assertEqual("| 0.0 0.0 0.0 0.0 |", out.lines[3]) x = np.array([-120, 120, 130]) out = tensor_format.numeric_summary(x) self.assertEqual("| - + | total |", out.lines[0]) self.assertEqual("| 1 2 | 3 |", out.lines[1]) self.assertEqual( "| min max mean std |", out.lines[2]) self.assertEqual( "| -120 130 43.3333333333 115.566238822 |", out.lines[3])
def testNumericSummaryOnStrTensor(self): x = np.array(["spam", "egg"], dtype=np.object_) out = tensor_format.numeric_summary(x) self.assertEqual( ["No numeric summary available due to tensor dtype: object."], out.lines)
def testNumericSummaryOnEmptyFloat(self): x = np.array([], dtype=np.float32) out = tensor_format.numeric_summary(x) self.assertEqual(["No numeric summary available due to empty tensor."], out.lines)
def testNumericSummaryOnStrTensor(self): x = np.array(["spam", "egg"], dtype=np.object) out = tensor_format.numeric_summary(x) self.assertEqual( ["No numeric summary available due to tensor dtype: object."], out.lines)
def testNumericSummaryOnEmptyFloat(self): x = np.array([], dtype=np.float32) out = tensor_format.numeric_summary(x) self.assertEqual(["No numeric summary available due to empty tensor."], out.lines)