1 /* Copyright 2015 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 #ifndef TENSORFLOW_FRAMEWORK_TENSOR_UTIL_H_ 17 #define TENSORFLOW_FRAMEWORK_TENSOR_UTIL_H_ 18 19 #include "tensorflow/core/framework/tensor.h" 20 21 #include <vector> 22 namespace tensorflow { 23 namespace tensor { 24 25 // DeepCopy returns a tensor whose contents are a deep copy of the 26 // contents of 'other'. This function is intended only for 27 // convenience, not speed. 28 // 29 // REQUIRES: 'other' must point to data stored in CPU memory. 30 // REQUIRES: 'other' must be a Tensor of a copy-able type if 31 // 'other' is not appropriately memory-aligned. 32 Tensor DeepCopy(const Tensor& other); 33 34 // Concatenates 'tensors' into a single tensor, along their 0th dimension. 35 // 36 // REQUIRES: All members of 'tensors' must have the same data type parameter. 37 // REQUIRES: Each member of 'tensors' must have at least one dimension. 38 // REQUIRES: Each member of 'tensors' must point to data stored in CPU memory. 39 // REQUIRES: Each member of 'tensors' must be a Tensor of a copy-able type if it 40 // is not appropriately memory-aligned. 41 Status Concat(const gtl::ArraySlice<Tensor>& tensors, 42 Tensor* result) TF_MUST_USE_RESULT; 43 44 // Splits 'tensor' into 'sizes.size()' individual tensors, along the 0th 45 // dimension. The ith output tensor has 0th-dimension size 'sizes[i]'. 46 // 47 // REQUIRES: 'tensor' must have at least one dimension. 48 // REQUIRES: 'tensor.dim_size(0)' must equal the sum of the elements of 'sizes'. 49 // REQUIRES: 'tensor' must point to data stored in CPU memory. 50 // REQUIRES: 'tensor' must be a Tensor of a copy-able type if it is not 51 // appropriately memory-aligned. 52 // 53 // Split() and Concat() are inverse operations. 54 Status Split(const Tensor& tensor, const gtl::ArraySlice<int64>& sizes, 55 std::vector<Tensor>* result) TF_MUST_USE_RESULT; 56 57 } // namespace tensor 58 } // namespace tensorflow 59 60 #endif // TENSORFLOW_FRAMEWORK_TENSOR_UTIL_H_ 61