Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/data/experimental/ops/scan_ops.py: 67%
9 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
« 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"""Scan dataset transformation."""
16from tensorflow.python.util import deprecation
17from tensorflow.python.util.tf_export import tf_export
20@deprecation.deprecated(None, "Use `tf.data.Dataset.scan(...) instead")
21@tf_export("data.experimental.scan")
22def scan(initial_state, scan_func):
23 """A transformation that scans a function across an input dataset.
25 This transformation is a stateful relative of `tf.data.Dataset.map`.
26 In addition to mapping `scan_func` across the elements of the input dataset,
27 `scan()` accumulates one or more state tensors, whose initial values are
28 `initial_state`.
30 Args:
31 initial_state: A nested structure of tensors, representing the initial state
32 of the accumulator.
33 scan_func: A function that maps `(old_state, input_element)` to
34 `(new_state, output_element)`. It must take two arguments and return a
35 pair of nested structures of tensors. The `new_state` must match the
36 structure of `initial_state`.
38 Returns:
39 A `Dataset` transformation function, which can be passed to
40 `tf.data.Dataset.apply`.
41 """
42 def _apply_fn(dataset):
43 return dataset.scan(initial_state=initial_state, scan_func=scan_func)
45 return _apply_fn