/* Copyright 2015 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ #ifndef TENSORFLOW_CORE_FRAMEWORK_TENSOR_TYPES_H_ #define TENSORFLOW_CORE_FRAMEWORK_TENSOR_TYPES_H_ #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" namespace tensorflow { // Helper to define Tensor types given that the scalar is of type T. template struct TTypes { // Rank- tensor of scalar type T. typedef Eigen::TensorMap, Eigen::Aligned> Tensor; typedef Eigen::TensorMap< Eigen::Tensor, Eigen::Aligned> ConstTensor; // Unaligned Rank- tensor of scalar type T. typedef Eigen::TensorMap > UnalignedTensor; typedef Eigen::TensorMap< Eigen::Tensor > UnalignedConstTensor; typedef Eigen::TensorMap, Eigen::Aligned> Tensor32Bit; // Scalar tensor (implemented as a rank-0 tensor) of scalar type T. typedef Eigen::TensorMap< Eigen::TensorFixedSize, Eigen::RowMajor, IndexType>, Eigen::Aligned> Scalar; typedef Eigen::TensorMap, Eigen::RowMajor, IndexType>, Eigen::Aligned> ConstScalar; // Unaligned Scalar tensor of scalar type T. typedef Eigen::TensorMap< Eigen::TensorFixedSize, Eigen::RowMajor, IndexType> > UnalignedScalar; typedef Eigen::TensorMap, Eigen::RowMajor, IndexType> > UnalignedConstScalar; // Rank-1 tensor (vector) of scalar type T. typedef Eigen::TensorMap, Eigen::Aligned> Flat; typedef Eigen::TensorMap< Eigen::Tensor, Eigen::Aligned> ConstFlat; typedef Eigen::TensorMap, Eigen::Aligned> Vec; typedef Eigen::TensorMap< Eigen::Tensor, Eigen::Aligned> ConstVec; // Unaligned Rank-1 tensor (vector) of scalar type T. typedef Eigen::TensorMap > UnalignedFlat; typedef Eigen::TensorMap< Eigen::Tensor > UnalignedConstFlat; typedef Eigen::TensorMap > UnalignedVec; typedef Eigen::TensorMap< Eigen::Tensor > UnalignedConstVec; // Rank-2 tensor (matrix) of scalar type T. typedef Eigen::TensorMap, Eigen::Aligned> Matrix; typedef Eigen::TensorMap< Eigen::Tensor, Eigen::Aligned> ConstMatrix; // Unaligned Rank-2 tensor (matrix) of scalar type T. typedef Eigen::TensorMap > UnalignedMatrix; typedef Eigen::TensorMap< Eigen::Tensor > UnalignedConstMatrix; }; typedef typename TTypes::Tensor32Bit::Index Index32; template Eigen::DSizes To32BitDims(const DSizes& in) { Eigen::DSizes out; for (int i = 0; i < DSizes::count; ++i) { out[i] = in[i]; } return out; } template typename TTypes::Tensor32Bit To32Bit(TensorType in) { typedef typename TTypes::Tensor32Bit RetType; return RetType(in.data(), To32BitDims(in.dimensions())); } } // namespace tensorflow #endif // TENSORFLOW_CORE_FRAMEWORK_TENSOR_TYPES_H_