def testTupleInputs(self):
     elements = [(1, 2), (3, 4)]
     dataset = from_list.from_list(elements)
     self.assertEqual(
         [np.shape(c) for c in elements[0]],
         [shape for shape in dataset_ops.get_legacy_output_shapes(dataset)])
     self.assertDatasetProduces(dataset, expected_output=elements)
 def testDictionary(self):
     dataset = from_list.from_list([{"a": 1, "b": 3}, {"a": 2, "b": 4}])
     self.assertEqual({
         "a": 1,
         "b": 3
     }, self.evaluate(random_access.at(dataset, 0)))
     self.assertEqual({
         "a": 2,
         "b": 4
     }, self.evaluate(random_access.at(dataset, 1)))
 def testNumpy(self):
     elements = [
         np.tile(np.array([[0], [1]], dtype=np.uint64), 2),
         np.tile(np.array([[2], [256]], dtype=np.uint64), 2),
         np.tile(np.array([[4], [65536]], dtype=np.uint64), 2),
         np.tile(np.array([[8], [4294967296]], dtype=np.uint64), 2),
     ]
     dataset = from_list.from_list(elements)
     for i in range(len(elements)):
         result = self.evaluate(random_access.at(dataset, i))
         self.assertAllEqual(elements[i], result)
 def testUintInputs(self):
     elements = [(np.tile(np.array([[0], [1]], dtype=np.uint8), 2),
                  np.tile(np.array([[2], [256]], dtype=np.uint16), 2),
                  np.tile(np.array([[4], [65536]], dtype=np.uint32), 2),
                  np.tile(np.array([[8], [4294967296]], dtype=np.uint64),
                          2))]
     dataset = from_list.from_list(elements)
     self.assertEqual(
         (dtypes.uint8, dtypes.uint16, dtypes.uint32, dtypes.uint64),
         dataset_ops.get_legacy_output_types(dataset))
     self.assertDatasetProduces(dataset, elements)
 def testDictInputs(self):
     elements = [{
         "foo": [1, 2, 3],
         "bar": [[4.0], [5.0], [6.0]]
     }, {
         "foo": [4, 5, 6],
         "bar": [[7.0], [8.0], [9.0]]
     }]
     dataset = from_list.from_list(elements)
     self.assertEqual(dtypes.int32,
                      dataset_ops.get_legacy_output_types(dataset)["foo"])
     self.assertEqual(dtypes.float32,
                      dataset_ops.get_legacy_output_types(dataset)["bar"])
     self.assertEqual((3, ),
                      dataset_ops.get_legacy_output_shapes(dataset)["foo"])
     self.assertEqual((3, 1),
                      dataset_ops.get_legacy_output_shapes(dataset)["bar"])
     self.assertDatasetProduces(dataset, expected_output=elements)
 def testNonRectangularInputs(self):
     elements = [[[1]], [[2, 3]], [[4, 5, 6]]]
     dataset = from_list.from_list(elements)
     self.assertEqual(tensor_shape.Dimension(1),
                      dataset_ops.get_legacy_output_shapes(dataset)[0])
     self.assertDatasetProduces(dataset, expected_output=elements)
 def testInvalidInputs(self, elements):
     with self.assertRaises(ValueError):
         from_list.from_list(elements._obj)
 def _build_list_dataset(self, elements):
     return from_list.from_list(elements)
 def testName(self):
     dataset = from_list.from_list([42], name="from_list")
     self.assertDatasetProduces(dataset, [42])
Beispiel #10
0
 def testMultipleElements(self):
     dataset = from_list.from_list([[1, 2], [3, 4], [5, 6]])
     self.assertEqual(1, self.evaluate(random_access.at(dataset, 0))[0])
     self.assertEqual(2, self.evaluate(random_access.at(dataset, 0))[1])
     self.assertEqual(3, self.evaluate(random_access.at(dataset, 1))[0])
     self.assertEqual(4, self.evaluate(random_access.at(dataset, 1))[1])
Beispiel #11
0
 def testTwoDimensionalArray(self):
     tensor = [[1, 2], [3, 4]]
     dataset = from_list.from_list(tensor)
     for i in range(2):
         results = self.evaluate(random_access.at(dataset, i))
         self.assertAllEqual(tensor[i], results)
Beispiel #12
0
 def testOneDimensionalArray(self):
     tensor = [1, 2, 3]
     dataset = from_list.from_list(tensor)
     for i in range(len(tensor)):
         results = self.evaluate(random_access.at(dataset, i))
         self.assertAllEqual(tensor[i], results)
Beispiel #13
0
 def testInvalidIndex(self):
     dataset = from_list.from_list([1, 2, 3])
     with self.assertRaises(errors.OutOfRangeError):
         self.evaluate(random_access.at(dataset, -1))
     with self.assertRaises(errors.OutOfRangeError):
         self.evaluate(random_access.at(dataset, 3))