• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/portable/cpu/util/functional_util.h>
10 #include <executorch/runtime/kernel/kernel_includes.h>
11 #include <executorch/runtime/platform/assert.h>
12 
13 namespace torch {
14 namespace executor {
15 namespace native {
16 
17 using exec_aten::Tensor;
18 
19 Tensor&
logical_not_out(KernelRuntimeContext & ctx,const Tensor & in,Tensor & out)20 logical_not_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
21   (void)ctx;
22 
23   // Resize for dynamic shape
24   ET_KERNEL_CHECK_MSG(
25       ctx,
26       resize_tensor(out, in.sizes()) == Error::Ok,
27       InvalidArgument,
28       out,
29       "Failed to resize output tensor.");
30 
31   ET_KERNEL_CHECK(
32       ctx, tensors_have_same_dim_order(in, out), InvalidArgument, out);
33 
34   ET_KERNEL_CHECK(ctx, tensors_have_same_shape(in, out), InvalidArgument, out);
35 
36   ET_SWITCH_REAL_TYPES_AND(
37       Bool, in.scalar_type(), ctx, "logical_not.out", CTYPE_IN, [&] {
38         ET_SWITCH_REAL_TYPES_AND(
39             Bool, out.scalar_type(), ctx, "logical_not.out", CTYPE_OUT, [&] {
40               apply_unary_map_fn(
41                   [](const CTYPE_IN val_in) {
42                     return static_cast<CTYPE_OUT>(!static_cast<bool>(val_in));
43                   },
44                   in.const_data_ptr<CTYPE_IN>(),
45                   out.mutable_data_ptr<CTYPE_OUT>(),
46                   in.numel());
47             });
48       });
49 
50   return out;
51 }
52 
53 } // namespace native
54 } // namespace executor
55 } // namespace torch
56