Skip to content

Commit 38c30d6

Browse files
swolchokfacebook-github-bot
authored andcommitted
use utils:{min,max}_override in {min,max}imum ops (#3453)
Summary: Pull Request resolved: #3453 Noticed this inconsistency with clamp. Reviewed By: manuelcandales Differential Revision: D56846313 fbshipit-source-id: 2fd891fd774101ad56c21cbea4984e2d9a7c9c20
1 parent 21f5fbf commit 38c30d6

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

kernels/portable/cpu/op_maximum.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,14 @@
88

99
#include <executorch/kernels/portable/cpu/scalar_utils.h>
1010
#include <executorch/kernels/portable/cpu/util/broadcast_util.h>
11+
#include <executorch/kernels/portable/cpu/util/math_util.h>
1112
#include <executorch/runtime/kernel/kernel_includes.h>
1213

1314
namespace torch {
1415
namespace executor {
1516
namespace native {
1617
namespace {
1718

18-
template <class T>
19-
const T& max(const T& a, const T& b) {
20-
return (b > a) ? b : a;
21-
}
22-
2319
template <
2420
bool can_cast,
2521
typename CTYPE_A,
@@ -40,7 +36,7 @@ struct MaximumInner<true, CTYPE_A, CTYPE_B, CTYPE_IN, CTYPE_OUT> {
4036
[](const CTYPE_A val_a, const CTYPE_B val_b) {
4137
CTYPE_IN a_casted = static_cast<CTYPE_IN>(val_a);
4238
CTYPE_IN b_casted = static_cast<CTYPE_IN>(val_b);
43-
CTYPE_IN value = max(a_casted, b_casted);
39+
CTYPE_IN value = utils::max_override(a_casted, b_casted);
4440

4541
return static_cast<CTYPE_OUT>(value);
4642
},

kernels/portable/cpu/op_minimum.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,14 @@
88

99
#include <executorch/kernels/portable/cpu/scalar_utils.h>
1010
#include <executorch/kernels/portable/cpu/util/broadcast_util.h>
11+
#include <executorch/kernels/portable/cpu/util/math_util.h>
1112
#include <executorch/runtime/kernel/kernel_includes.h>
1213

1314
namespace torch {
1415
namespace executor {
1516
namespace native {
1617
namespace {
1718

18-
template <class T>
19-
const T& min(const T& a, const T& b) {
20-
return (b < a) ? b : a;
21-
}
22-
2319
template <
2420
bool can_cast,
2521
typename CTYPE_A,
@@ -40,7 +36,7 @@ struct MinimumInner<true, CTYPE_A, CTYPE_B, CTYPE_IN, CTYPE_OUT> {
4036
[](const CTYPE_A val_a, const CTYPE_B val_b) {
4137
CTYPE_IN a_casted = static_cast<CTYPE_IN>(val_a);
4238
CTYPE_IN b_casted = static_cast<CTYPE_IN>(val_b);
43-
CTYPE_IN value = min(a_casted, b_casted);
39+
CTYPE_IN value = utils::min_override(a_casted, b_casted);
4440

4541
return static_cast<CTYPE_OUT>(value);
4642
},

kernels/portable/cpu/targets.bzl

+2
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ _ATEN_OPS = (
560560
name = "op_maximum",
561561
deps = [
562562
"//executorch/kernels/portable/cpu/util:broadcast_util",
563+
"//executorch/kernels/portable/cpu/util:math_util",
563564
":scalar_utils",
564565
],
565566
),
@@ -591,6 +592,7 @@ _ATEN_OPS = (
591592
name = "op_minimum",
592593
deps = [
593594
"//executorch/kernels/portable/cpu/util:broadcast_util",
595+
"//executorch/kernels/portable/cpu/util:math_util",
594596
":scalar_utils",
595597
],
596598
),

0 commit comments

Comments
 (0)