66 * LICENSE file in the root directory of this source tree.
77 */
88
9- #include < executorch/kernels/portable/cpu/util/functional_util .h>
9+ #include < executorch/kernels/portable/cpu/util/elementwise_util .h>
1010#include < executorch/runtime/kernel/kernel_includes.h>
1111#include < executorch/runtime/platform/assert.h>
1212
@@ -33,12 +33,17 @@ Tensor& neg_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
3333 ET_KERNEL_CHECK (
3434 ctx, tensors_have_same_dim_order (in, out), InvalidArgument, out);
3535
36- ET_SWITCH_REALHBF16_TYPES (in.scalar_type (), ctx, " neg.out" , CTYPE, [&] {
37- apply_unary_map_fn (
38- [](const CTYPE val_in) { return static_cast <CTYPE>(-val_in); },
39- in.const_data_ptr <CTYPE>(),
40- out.mutable_data_ptr <CTYPE>(),
41- in.numel ());
36+ static constexpr const char op_name[] = " neg.out" ;
37+ ET_SWITCH_REALHBF16_TYPES (in.scalar_type (), ctx, op_name, CTYPE, [&] {
38+ utils::internal::apply_unitensor_elementwise_fn<
39+ CTYPE,
40+ op_name,
41+ utils::SupportedTensorDtypes::SAME_AS_COMMON>(
42+ [](const auto val_in) { return -val_in; },
43+ ctx,
44+ in,
45+ utils::SupportedTensorDtypes::REALHBF16,
46+ out);
4247 });
4348
4449 return out;
0 commit comments