1 /* Copyright 2019 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_CORE_KERNELS_SPARSE_TRANSPOSE_OP_H_
17 #define TENSORFLOW_CORE_KERNELS_SPARSE_TRANSPOSE_OP_H_
18 
19 #include "tensorflow/core/framework/tensor.h"
20 #include "tensorflow/core/framework/tensor_types.h"
21 #include "tensorflow/core/kernels/cwise_ops.h"
22 
23 namespace tensorflow {
24 namespace functor {
25 
26 template <typename Device, typename T>
27 struct maybe_conj_inplace {
runmaybe_conj_inplace28   static void run(const Device& d, Tensor* t) {}
29 };
30 
31 template <typename Device>
32 struct maybe_conj_inplace<Device, complex64> {
33   static void run(const Device& d, Tensor* t) {
34     functor::UnaryFunctor<Device, functor::conj<complex64>> conj;
35     conj(d, t->flat<complex64>() /*out*/,
36          const_cast<const Tensor*>(t)->flat<complex64>() /*in*/);
37   }
38 };
39 
40 template <typename Device>
41 struct maybe_conj_inplace<Device, complex128> {
42   static void run(const Device& d, Tensor* t) {
43     functor::UnaryFunctor<Device, functor::conj<complex128>> conj;
44     conj(d, t->flat<complex128>() /*out*/,
45          const_cast<const Tensor*>(t)->flat<complex128>() /*in*/);
46   }
47 };
48 
49 template <typename Device, typename T>
50 struct maybe_conj {
51   static void run(const Device& d, const Tensor& in, Tensor* out) { *out = in; }
52 };
53 
54 template <typename Device>
55 struct maybe_conj<Device, complex64> {
56   static void run(const Device& d, const Tensor& in, Tensor* out) {
57     functor::UnaryFunctor<Device, functor::conj<complex64>> conj;
58     conj(d, out->flat<complex64>() /*out*/, in.flat<complex64>() /*in*/);
59   }
60 };
61 
62 template <typename Device>
63 struct maybe_conj<Device, complex128> {
64   static void run(const Device& d, const Tensor& in, Tensor* out) {
65     functor::UnaryFunctor<Device, functor::conj<complex128>> conj;
66     conj(d, out->flat<complex128>() /*out*/, in.flat<complex128>() /*in*/);
67   }
68 };
69 
70 }  // namespace functor
71 }  // namespace tensorflow
72 
73 #endif  // TENSORFLOW_CORE_KERNELS_SPARSE_TRANSPOSE_OP_H_
74