Home | History | Annotate | Download | only in data
      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 
     16 #include "tensorflow/core/kernels/data/dataset_utils.h"
     17 
     18 namespace tensorflow {
     19 
     20 namespace dataset {
     21 
     22 Status MakeIteratorFromInputElement(
     23     IteratorContext* ctx, const std::vector<Tensor>& input_element,
     24     int64 thread_index, CapturedFunction* captured_func, StringPiece prefix,
     25     std::unique_ptr<IteratorBase>* out_iterator) {
     26   std::vector<Tensor> return_values;
     27 
     28   TF_RETURN_IF_ERROR(
     29       captured_func->RunWithBorrowedArgs(ctx, input_element, &return_values));
     30 
     31   if (!(return_values.size() == 1 && return_values[0].dtype() == DT_VARIANT &&
     32         TensorShapeUtils::IsScalar(return_values[0].shape()))) {
     33     return errors::InvalidArgument(
     34         "Function must return a single scalar of dtype DT_VARIANT.");
     35   }
     36 
     37   // Retrieve the dataset that was created in `f`.
     38   DatasetBase* returned_dataset;
     39   TF_RETURN_IF_ERROR(
     40       GetDatasetFromVariantTensor(return_values[0], &returned_dataset));
     41 
     42   // Create an iterator for the dataset that was returned by `f`.
     43   *out_iterator = returned_dataset->MakeIterator(
     44       strings::StrCat(prefix, "[", thread_index, "]"));
     45   return Status::OK();
     46 }
     47 
     48 }  // namespace dataset
     49 
     50 }  // namespace tensorflow
     51