File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
runtime/core/exec_aten/util Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -455,6 +455,31 @@ inline bool canCast(
455
455
return true ;
456
456
}
457
457
458
+ /* *
459
+ * When casting from floating point to integral type, if the floating value is
460
+ * outside the integral type range, then an error is thrown if sanitization is
461
+ * enabled. To circumvent this, we cast the floating point to int64_t first.
462
+ */
463
+ template <
464
+ typename To,
465
+ typename From,
466
+ typename std::enable_if<
467
+ (std::is_floating_point<From>::value && std::is_integral<To>::value),
468
+ int >::type = 0 >
469
+ To convert (From val) {
470
+ return static_cast <To>(static_cast <int64_t >(val));
471
+ }
472
+
473
+ template <
474
+ typename To,
475
+ typename From,
476
+ typename std::enable_if<
477
+ !(std::is_floating_point<From>::value && std::is_integral<To>::value),
478
+ int >::type = 0 >
479
+ To convert (From val) {
480
+ return static_cast <To>(val);
481
+ }
482
+
458
483
/* *
459
484
* Implements type promotion rules that are consistent with ATen behaviour,
460
485
* which in turn is consistent with NumPy's promote_types.
You can’t perform that action at this time.
0 commit comments