| 145 | // Uses Eigen to transpose. |
| 146 | template <typename Device, typename T, int NDIMS> |
| 147 | void TransposeUsingEigen(const Device& d, const Tensor& in, |
| 148 | const gtl::ArraySlice<int32> perm, bool conjugate, |
| 149 | Tensor* out) { |
| 150 | Eigen::array<int, NDIMS> p; |
| 151 | for (int i = 0; i < NDIMS; ++i) p[i] = perm[i]; |
| 152 | auto x = typename TTypes<T, NDIMS>::ConstTensor( |
| 153 | reinterpret_cast<const T*>(in.tensor_data().data()), |
| 154 | in.shape().AsEigenDSizes<NDIMS>()); |
| 155 | auto y = typename TTypes<T, NDIMS>::Tensor( |
| 156 | reinterpret_cast<T*>(const_cast<char*>(out->tensor_data().data())), |
| 157 | out->shape().AsEigenDSizes<NDIMS>()); |
| 158 | if (conjugate) { |
| 159 | y.device(d) = x.conjugate().shuffle(p); |
| 160 | } else { |
| 161 | y.device(d) = x.shuffle(p); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | template <typename Device> |
| 166 | Status DoTransposeImpl(const Device& d, const Tensor& in, |