|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. |
| 7 | + */ |
| 8 | + |
| 9 | +#include <executorch/kernels/test/FunctionHeaderWrapper.h> // Declares the operator |
| 10 | +#include <executorch/kernels/test/TestUtil.h> |
| 11 | +#include <executorch/runtime/core/exec_aten/exec_aten.h> |
| 12 | +#include <executorch/runtime/core/exec_aten/testing_util/tensor_factory.h> |
| 13 | +#include <executorch/runtime/core/exec_aten/testing_util/tensor_util.h> |
| 14 | + |
| 15 | +#include <gtest/gtest.h> |
| 16 | + |
| 17 | +using namespace ::testing; |
| 18 | +using executorch::aten::ScalarType; |
| 19 | +using executorch::aten::Tensor; |
| 20 | +using torch::executor::testing::TensorFactory; |
| 21 | + |
| 22 | +class OpViewAsRealTest : public OperatorTest { |
| 23 | + protected: |
| 24 | + Tensor& view_as_real_copy_out(const Tensor& self, Tensor& out) { |
| 25 | + return torch::executor::aten::view_as_real_copy_outf(context_, self, out); |
| 26 | + } |
| 27 | + |
| 28 | + |
| 29 | + template <typename CTYPE, ScalarType DTYPE> |
| 30 | + void run_complex_smoke_test() { |
| 31 | + TensorFactory<DTYPE> tf; |
| 32 | + constexpr auto REAL_DTYPE = executorch::runtime::toRealValueType(DTYPE); |
| 33 | + TensorFactory<REAL_DTYPE> tf_out; |
| 34 | + using REAL_CTYPE = |
| 35 | + typename executorch::runtime::ScalarTypeToCppType<REAL_DTYPE>::type; |
| 36 | + Tensor in = tf.make( |
| 37 | + {2, 2}, |
| 38 | + {CTYPE{REAL_CTYPE(3), REAL_CTYPE(4)}, |
| 39 | + CTYPE{REAL_CTYPE(-1.7), REAL_CTYPE(7.4)}, |
| 40 | + CTYPE{REAL_CTYPE(5), REAL_CTYPE(-12)}, |
| 41 | + CTYPE{REAL_CTYPE(8.3), REAL_CTYPE(0.1)}}); |
| 42 | + Tensor out = tf_out.zeros({2, 2, 2}); |
| 43 | + Tensor expected = tf_out.make({2, 2, 2}, {3, 4, -1.7, 7.4, 5, -12, 8.3, 0.1}); |
| 44 | + Tensor ret = view_as_real_copy_out(in, out); |
| 45 | + EXPECT_TENSOR_EQ(out, ret); |
| 46 | + EXPECT_TENSOR_EQ(out, expected); |
| 47 | + } |
| 48 | +}; |
| 49 | + |
| 50 | + |
| 51 | +TEST_F(OpViewAsRealTest, ComplexSmokeTest) { |
| 52 | +#define RUN_SMOKE_TEST(ctype, dtype) \ |
| 53 | + run_complex_smoke_test<ctype, ScalarType::dtype>(); |
| 54 | + ET_FORALL_COMPLEXH_TYPES(RUN_SMOKE_TEST); |
| 55 | +#undef RUN_SMOKE_TEST |
| 56 | +} |
0 commit comments