/* * Copyright (c) Meta Platforms, Inc. and affiliates. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ #include #include #include #include #include namespace torch { namespace executor { namespace native { using Tensor = executorch::aten::Tensor; using ScalarType = executorch::aten::ScalarType; Tensor& amin_out( KernelRuntimeContext& ctx, const Tensor& in, ArrayRef dim_list, bool keepdim, Tensor& out) { (void)ctx; ET_KERNEL_CHECK( ctx, check_amin_amax_args(in, dim_list, keepdim, out), InvalidArgument, out); ET_KERNEL_CHECK( ctx, resize_reduction_out(in, dim_list, keepdim, out) == Error::Ok, InvalidArgument, out); ET_KERNEL_CHECK( ctx, tensors_have_same_dim_order(in, out), InvalidArgument, out); ReduceOverDimListPlan plan(in, dim_list); ET_SWITCH_REALHBBF16_TYPES(in.scalar_type(), ctx, "amin.out", CTYPE, [&]() { CTYPE* out_data = out.mutable_data_ptr(); const bool success = parallel_for_each_reduce_over_dim_list_output_index( in, dim_list, out, [&](const auto begin, const auto end) { for (const auto out_ix : c10::irange(begin, end)) { out_data[out_ix] = plan.execute( [](CTYPE v, CTYPE min_v) { return std::isnan(v) || v < min_v ? v : min_v; }, out_ix); } }); ET_KERNEL_CHECK_MSG(ctx, success, Internal, , "parallel_for failed"); }); return out; } } // namespace native } // namespace executor } // namespace torch