• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 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"""take-while dataset transformation."""
16from __future__ import absolute_import
17from __future__ import division
18from __future__ import print_function
19
20from tensorflow.python.util import deprecation
21from tensorflow.python.util.tf_export import tf_export
22
23
24@deprecation.deprecated(None, "Use `tf.data.Dataset.take_while(...)")
25@tf_export("data.experimental.take_while")
26def take_while(predicate):
27  """A transformation that stops dataset iteration based on a `predicate`.
28
29  Args:
30    predicate: A function that maps a nested structure of tensors (having shapes
31      and types defined by `self.output_shapes` and `self.output_types`) to a
32      scalar `tf.bool` tensor.
33
34  Returns:
35    A `Dataset` transformation function, which can be passed to
36    `tf.data.Dataset.apply`.
37  """
38
39  def _apply_fn(dataset):
40    return dataset.take_while(predicate=predicate)
41
42  return _apply_fn
43