|
| 1 | +/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. |
| 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 | +#pragma once |
| 16 | + |
| 17 | +#include "unsupported/Eigen/CXX11/Tensor" |
| 18 | + |
| 19 | +namespace paddle { |
| 20 | +namespace framework { |
| 21 | + |
| 22 | +// Helper to define Tensor types given that the scalar is of type T. |
| 23 | +template <typename T, int NDIMS = 1, typename IndexType = Eigen::DenseIndex> |
| 24 | +struct TTypes { |
| 25 | + // Rank-<NDIMS> tensor of scalar type T. |
| 26 | + typedef Eigen::TensorMap<Eigen::Tensor<T, NDIMS, Eigen::RowMajor, IndexType>, |
| 27 | + Eigen::Aligned> |
| 28 | + Tensor; |
| 29 | + typedef Eigen::TensorMap< |
| 30 | + Eigen::Tensor<const T, NDIMS, Eigen::RowMajor, IndexType>, Eigen::Aligned> |
| 31 | + ConstTensor; |
| 32 | + |
| 33 | + // Scalar tensor (implemented as a rank-0 tensor) of scalar type T. |
| 34 | + typedef Eigen::TensorMap< |
| 35 | + Eigen::TensorFixedSize<T, Eigen::Sizes<>, Eigen::RowMajor, IndexType>, |
| 36 | + Eigen::Aligned> |
| 37 | + Scalar; |
| 38 | + typedef Eigen::TensorMap<Eigen::TensorFixedSize<const T, Eigen::Sizes<>, |
| 39 | + Eigen::RowMajor, IndexType>, |
| 40 | + Eigen::Aligned> |
| 41 | + ConstScalar; |
| 42 | + |
| 43 | + // Rank-1 tensor (vector) of scalar type T. |
| 44 | + typedef Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, IndexType>, |
| 45 | + Eigen::Aligned> |
| 46 | + Flat; |
| 47 | + typedef Eigen::TensorMap< |
| 48 | + Eigen::Tensor<const T, 1, Eigen::RowMajor, IndexType>, Eigen::Aligned> |
| 49 | + ConstFlat; |
| 50 | + typedef Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, IndexType>, |
| 51 | + Eigen::Aligned> |
| 52 | + Vec; |
| 53 | + typedef Eigen::TensorMap< |
| 54 | + Eigen::Tensor<const T, 1, Eigen::RowMajor, IndexType>, Eigen::Aligned> |
| 55 | + ConstVec; |
| 56 | + |
| 57 | + // Rank-2 tensor (matrix) of scalar type T. |
| 58 | + typedef Eigen::TensorMap<Eigen::Tensor<T, 2, Eigen::RowMajor, IndexType>, |
| 59 | + Eigen::Aligned> |
| 60 | + Matrix; |
| 61 | + typedef Eigen::TensorMap< |
| 62 | + Eigen::Tensor<const T, 2, Eigen::RowMajor, IndexType>, Eigen::Aligned> |
| 63 | + ConstMatrix; |
| 64 | +}; |
| 65 | + |
| 66 | +} // namespace framework |
| 67 | +} // namespace paddle |
0 commit comments