Constructs a `_GeneratorDataset`. Args: init_args: A nested structure representing the arguments to `init_func`. init_func: A TensorFlow function that will be called on `init_args` each time a C++ iterator over this dataset is constructed. Returns a nested structure
(self, init_args, init_func, next_func, finalize_func)
| 2854 | """A `Dataset` that generates elements by invoking a function.""" |
| 2855 | |
| 2856 | def __init__(self, init_args, init_func, next_func, finalize_func): |
| 2857 | """Constructs a `_GeneratorDataset`. |
| 2858 | |
| 2859 | Args: |
| 2860 | init_args: A nested structure representing the arguments to `init_func`. |
| 2861 | init_func: A TensorFlow function that will be called on `init_args` each |
| 2862 | time a C++ iterator over this dataset is constructed. Returns a nested |
| 2863 | structure representing the "state" of the dataset. |
| 2864 | next_func: A TensorFlow function that will be called on the result of |
| 2865 | `init_func` to produce each element, and that raises `OutOfRangeError` |
| 2866 | to terminate iteration. |
| 2867 | finalize_func: A TensorFlow function that will be called on the result of |
| 2868 | `init_func` immediately before a C++ iterator over this dataset is |
| 2869 | destroyed. The return value is ignored. |
| 2870 | """ |
| 2871 | self._init_args = init_args |
| 2872 | |
| 2873 | self._init_structure = structure.type_spec_from_value(init_args) |
| 2874 | |
| 2875 | self._init_func = StructuredFunctionWrapper( |
| 2876 | init_func, |
| 2877 | self._transformation_name(), |
| 2878 | input_structure=self._init_structure) |
| 2879 | |
| 2880 | self._next_func = StructuredFunctionWrapper( |
| 2881 | next_func, |
| 2882 | self._transformation_name(), |
| 2883 | input_structure=self._init_func.output_structure) |
| 2884 | |
| 2885 | self._finalize_func = StructuredFunctionWrapper( |
| 2886 | finalize_func, |
| 2887 | self._transformation_name(), |
| 2888 | input_structure=self._init_func.output_structure) |
| 2889 | variant_tensor = gen_dataset_ops.generator_dataset( |
| 2890 | structure.to_tensor_list(self._init_structure, self._init_args) + |
| 2891 | self._init_func.function.captured_inputs, |
| 2892 | self._next_func.function.captured_inputs, |
| 2893 | self._finalize_func.function.captured_inputs, |
| 2894 | init_func=self._init_func.function, |
| 2895 | next_func=self._next_func.function, |
| 2896 | finalize_func=self._finalize_func.function, |
| 2897 | **self._flat_structure) |
| 2898 | super(_GeneratorDataset, self).__init__(variant_tensor) |
| 2899 | |
| 2900 | @property |
| 2901 | def element_spec(self): |
nothing calls this directly
no test coverage detected