1/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15#ifndef TENSORFLOW_CORE_UTIL_BATCH_UTIL_H_
16#define TENSORFLOW_CORE_UTIL_BATCH_UTIL_H_
17
18#include "tensorflow/core/framework/tensor.h"
19#include "tensorflow/core/lib/core/status.h"
20
21namespace tensorflow {
22namespace batch_util {
23
24// Copies element into the index^th slice of parent (in the 0th dimension).
25//
26// NOTE(mrry): The `element` argument is taken by value. Use `std::move()`
27// to move the `element` argument into this function, and the implementation
28// may be able to optimize the copy to a move. This is particularly important
29// for DT_STRING tensors.
30Status CopyElementToSlice(Tensor element, Tensor* parent, int64_t index);
31
32// Copies the index^th slice of parent (in the 0th dimension) into element.
33Status CopySliceToElement(const Tensor& parent, Tensor* element, int64_t index);
34
35// Copies 'num_slices' contiguous slices from 'src' tensor starting from index
36// 'src_offset' into target tensor 'dst', and places them into slices
37// starting from 'dst_offset'.
38//
39// This function requires 'src' and 'dst' to have compatible shapes. That is it
40// requires cum_prod(src.shape[1:] == cum_prod(dst->shape[1:]). For example if
41// source is of shape [x, 2, 1] and dst is a tensor of shape [y, 1, 2], this
42// function can still proceed successfully.
43Status CopyContiguousSlices(const Tensor& src, int64_t src_offset,
44 int64_t dst_offset, int64_t num_slices,
45 Tensor* dst);
46
47// Copies the index^th slice of parent (in the 0th dimension) into element.
48//
49// NOTE(mrry): The implementation may be able to optimize the copy to a move.
50// This is particularly important for DT_STRING tensors.
51Status MaybeMoveSliceToElement(Tensor* parent, Tensor* element, int64_t index);
52
53// Zero-initializes the tensor `element` using the scalar stored in `padding`.
54// Both `element` and `padding` must have matching `dtype`.
55Status SetElementZero(Tensor* element, const Tensor& padding);
56
57// Copies `element` into a (0th dimension) slice of `parent`, assuming
58// the shape of `element` is strictly not larger along any axis than a
59// slice.
60Status CopyElementToLargerSlice(const Tensor& element, Tensor* parent,
61 int index);
62
63} // namespace batch_util
64} // namespace tensorflow
65
66#endif // TENSORFLOW_CORE_UTIL_BATCH_UTIL_H_
67