Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/data/experimental/ops/enumerate_ops.py: 67%

9 statements  

« prev     ^ index     » next       coverage.py v7.4.0, created at 2024-01-03 07:57 +0000

1# Copyright 2017 The TensorFlow Authors. All Rights Reserved. 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14# ============================================================================== 

15"""Enumerate dataset transformations.""" 

16from tensorflow.python.util import deprecation 

17from tensorflow.python.util.tf_export import tf_export 

18 

19 

20@deprecation.deprecated(None, "Use `tf.data.Dataset.enumerate()`.") 

21@tf_export("data.experimental.enumerate_dataset") 

22def enumerate_dataset(start=0): 

23 """A transformation that enumerates the elements of a dataset. 

24 

25 It is similar to python's `enumerate`. 

26 For example: 

27 

28 ```python 

29 # NOTE: The following examples use `{ ... }` to represent the 

30 # contents of a dataset. 

31 a = { 1, 2, 3 } 

32 b = { (7, 8), (9, 10) } 

33 

34 # The nested structure of the `datasets` argument determines the 

35 # structure of elements in the resulting dataset. 

36 a.apply(tf.data.experimental.enumerate_dataset(start=5)) 

37 => { (5, 1), (6, 2), (7, 3) } 

38 b.apply(tf.data.experimental.enumerate_dataset()) 

39 => { (0, (7, 8)), (1, (9, 10)) } 

40 ``` 

41 

42 Args: 

43 start: A `tf.int64` scalar `tf.Tensor`, representing the start value for 

44 enumeration. 

45 

46 Returns: 

47 A `Dataset` transformation function, which can be passed to 

48 `tf.data.Dataset.apply`. 

49 """ 

50 

51 def _apply_fn(dataset): 

52 return dataset.enumerate(start) 

53 

54 return _apply_fn