def materialize(self, shared_name=None, container=None): """Materialize creates a MaterializedIndexedDataset. IndexedDatasets can be combined through operations such as TBD. Therefore, they are only materialized when absolutely required. Args: shared_name: a string for the shared name to use for the resource. container: a string for the container to store the resource. Returns: A MaterializedIndexedDataset. """ if container is None: container = "" if shared_name is None: shared_name = "" materialized_resource = ( ged_ops.experimental_materialized_index_dataset_handle( container=container, shared_name=shared_name, output_types=nest.flatten( sparse.as_dense_types(self.output_types, self.output_classes)), output_shapes=nest.flatten( sparse.as_dense_types(self.output_shapes, self.output_classes)))) with ops.colocate_with(materialized_resource): materializer = ged_ops.experimental_indexed_dataset_materialize( self._as_variant_tensor(), materialized_resource) return MaterializedIndexedDataset(materialized_resource, materializer, self.output_classes, self.output_types, self.output_shapes)
def materialize(self, shared_name=None, container=None): """Materialize creates a MaterializedIndexedDataset. IndexedDatasets can be combined through operations such as TBD. Therefore, they are only materialized when absolutely required. Args: shared_name: a string for the shared name to use for the resource. container: a string for the container to store the resource. Returns: A MaterializedIndexedDataset. """ if container is None: container = "" if shared_name is None: shared_name = "" materialized_resource = ( ged_ops.experimental_materialized_index_dataset_handle( container=container, shared_name=shared_name, output_types=nest.flatten( sparse.as_dense_types(self.output_types, self.output_classes)), output_shapes=nest.flatten( sparse.as_dense_types(self.output_shapes, self.output_classes)))) with ops.colocate_with(materialized_resource): materializer = ged_ops.experimental_indexed_dataset_materialize( self._as_variant_tensor(), materialized_resource) return MaterializedIndexedDataset(materialized_resource, materializer, self.output_classes, self.output_types, self.output_shapes)
def testLowLevelIndexedDatasetOps(self): identity = ged_ops.experimental_identity_indexed_dataset( ops.convert_to_tensor(16, dtype=dtypes.uint64)) handle = ged_ops.experimental_materialized_index_dataset_handle( container="", shared_name="", output_types=[dtypes.uint64], output_shapes=[[]]) materialize = ged_ops.experimental_indexed_dataset_materialize( identity, handle) get_op = ged_ops.experimental_indexed_dataset_get( handle, 3, output_types=[dtypes.uint64], output_shapes=[[]]) self.evaluate(materialize) self.assertEqual([3], self.evaluate(get_op))
def testLowLevelIndexedDatasetOps(self): identity = ged_ops.experimental_identity_indexed_dataset( ops.convert_to_tensor(16, dtype=dtypes.uint64)) handle = ged_ops.experimental_materialized_index_dataset_handle( container="", shared_name="", output_types=[dtypes.uint64], output_shapes=[[]]) materialize = ged_ops.experimental_indexed_dataset_materialize( identity, handle) get_op = ged_ops.experimental_indexed_dataset_get( handle, 3, output_types=[dtypes.uint64], output_shapes=[[]]) self.evaluate(materialize) self.assertEqual([3], self.evaluate(get_op))
def testLowLevelIndexedDatasetOps(self): identity = ged_ops.experimental_identity_indexed_dataset( ops.convert_to_tensor(16, dtype=dtypes.uint64)) handle = ged_ops.experimental_materialized_index_dataset_handle( container="", shared_name="", output_types=[dtypes.uint64], output_shapes=[[]]) materialize = ged_ops.experimental_indexed_dataset_materialize( identity, handle) index = array_ops.placeholder(dtypes.uint64) get_op = ged_ops.experimental_indexed_dataset_get( handle, index, output_types=[dtypes.uint64], output_shapes=[[]]) with self.cached_session() as sess: sess.run(materialize) self.assertEqual([3], sess.run(get_op, feed_dict={index: 3}))