1/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#ifndef TENSORFLOW_CORE_KERNELS_CROSS_OP_H_
17#define TENSORFLOW_CORE_KERNELS_CROSS_OP_H_
18
19#include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
20#include "tensorflow/core/framework/tensor_shape.h"
21#include "tensorflow/core/framework/tensor_types.h"
22
23namespace tensorflow {
24
25namespace functor {
26
27template <typename Device, typename Type>
28struct Cross {
29 void operator()(const Device &d,
30 typename TTypes<Type, 2>::ConstTensor in0_data,
31 typename TTypes<Type, 2>::ConstTensor in1_data,
32 typename TTypes<Type, 2>::Tensor output_data) {
33 auto s1 = output_data.template chip<1>(0);
34 auto s2 = output_data.template chip<1>(1);
35 auto s3 = output_data.template chip<1>(2);
36
37 auto u1 = in0_data.template chip<1>(0);
38 auto u2 = in0_data.template chip<1>(1);
39 auto u3 = in0_data.template chip<1>(2);
40
41 auto v1 = in1_data.template chip<1>(0);
42 auto v2 = in1_data.template chip<1>(1);
43 auto v3 = in1_data.template chip<1>(2);
44
45 s1.device(d) = u2 * v3 - u3 * v2;
46 s2.device(d) = u3 * v1 - u1 * v3;
47 s3.device(d) = u1 * v2 - u2 * v1;
48 }
49};
50
51} // namespace functor
52} // namespace tensorflow
53
54#endif // TENSORFLOW_CORE_KERNELS_CROSS_OP_H_
55