@@ -101,7 +101,7 @@ void mul_kernel(TensorIteratorBase& iter) {
101
101
using comp_t = c10::complex<float >;
102
102
return comp_t {a} * comp_t {b};
103
103
});
104
- } else if (iter.is_scalar (2 ) && at::isReducedFloatingType (dtype)) {
104
+ } else if (iter.is_scalar (2 ) && iter. data_ptr ( 2 ) != nullptr && at::isReducedFloatingType (dtype)) {
105
105
AT_DISPATCH_REDUCED_FLOATING_TYPES (dtype, " mul_cpu_reduced_float" , [&]() {
106
106
using opmath_t = at::opmath_type<scalar_t >;
107
107
opmath_t b = iter.original_scalar_value <opmath_t >(2 );
@@ -125,7 +125,7 @@ void mul_kernel(TensorIteratorBase& iter) {
125
125
126
126
void div_true_kernel (TensorIteratorBase& iter) {
127
127
const auto dtype = iter.common_dtype ();
128
- if (iter.is_scalar (2 ) && at::isReducedFloatingType (dtype)) {
128
+ if (iter.is_scalar (2 ) && iter. data_ptr ( 2 ) != nullptr && at::isReducedFloatingType (dtype)) {
129
129
AT_DISPATCH_REDUCED_FLOATING_TYPES (dtype, " div_cpu_reduced_float" , [&]() {
130
130
using opmath_t = at::opmath_type<scalar_t >;
131
131
opmath_t b = iter.original_scalar_value <opmath_t >(2 );
@@ -162,19 +162,28 @@ void div_trunc_kernel(TensorIteratorBase& iter) {
162
162
return a / b;
163
163
});
164
164
});
165
- } else if (iter.is_scalar (2 ) && at::isReducedFloatingType (dtype)) {
166
- AT_DISPATCH_REDUCED_FLOATING_TYPES (dtype, " div_trunc_cpu_reduced_float" , [&]() {
167
- using opmath_t = at::opmath_type<scalar_t >;
168
- opmath_t b = iter.original_scalar_value <opmath_t >(2 );
169
- iter.remove_operand (2 );
170
- cpu_kernel_vec (iter,
171
- [=](scalar_t a) __ubsan_ignore_float_divide_by_zero__ -> scalar_t {
172
- return std::trunc (static_cast <opmath_t >(a) / b);
173
- },
174
- [=](Vectorized<scalar_t > a) {
175
- return binary_op_scalar (a, b, [](const Vectorized<opmath_t >& x, const Vectorized<opmath_t >& y) { return (x / y).trunc (); });
165
+ } else if (iter.is_scalar (2 ) && iter.data_ptr (2 ) != nullptr && at::isReducedFloatingType (dtype)) {
166
+ AT_DISPATCH_REDUCED_FLOATING_TYPES (
167
+ dtype, " div_trunc_cpu_reduced_float" , [&]() {
168
+ using opmath_t = at::opmath_type<scalar_t >;
169
+ opmath_t b = iter.original_scalar_value <opmath_t >(2 );
170
+ iter.remove_operand (2 );
171
+ cpu_kernel_vec (
172
+ iter,
173
+ [=](scalar_t a)
174
+ __ubsan_ignore_float_divide_by_zero__ -> scalar_t {
175
+ return std::trunc (static_cast <opmath_t >(a) / b);
176
+ },
177
+ [=](Vectorized<scalar_t > a) {
178
+ return binary_op_scalar (
179
+ a,
180
+ b,
181
+ [](const Vectorized<opmath_t >& x,
182
+ const Vectorized<opmath_t >& y) {
183
+ return (x / y).trunc ();
184
+ });
185
+ });
176
186
});
177
- });
178
187
} else {
179
188
AT_DISPATCH_FLOATING_TYPES_AND2 (kBFloat16 , kHalf , dtype, " div_trunc_cpu" , [&]() {
180
189
cpu_kernel_vec (iter,
@@ -223,20 +232,25 @@ void div_floor_kernel(TensorIteratorBase& iter) {
223
232
});
224
233
} else {
225
234
// See NOTE: [Floor Division in Python]
226
- if (iter.is_scalar (2 ) && at::isReducedFloatingType (dtype)) {
227
- AT_DISPATCH_REDUCED_FLOATING_TYPES (dtype, " div_floor_cpu_reduced_float" , [&]() {
228
- using opmath_t = at::opmath_type<scalar_t >;
229
- opmath_t b = iter.original_scalar_value <opmath_t >(2 );
230
- iter.remove_operand (2 );
231
- using vec_t = Vectorized<opmath_t >;
232
- cpu_kernel_vec (iter,
233
- [=](scalar_t a) -> scalar_t {
234
- return div_floor_floating (static_cast <opmath_t >(a), b);
235
- },
236
- [=](Vectorized<scalar_t > a) {
237
- return binary_op_scalar (a, b, [](const vec_t & x, const vec_t & y) { return div_floor_floating_vec (x, y); });
235
+ if (iter.is_scalar (2 ) && iter.data_ptr (2 ) != nullptr && at::isReducedFloatingType (dtype)) {
236
+ AT_DISPATCH_REDUCED_FLOATING_TYPES (
237
+ dtype, " div_floor_cpu_reduced_float" , [&]() {
238
+ using opmath_t = at::opmath_type<scalar_t >;
239
+ opmath_t b = iter.original_scalar_value <opmath_t >(2 );
240
+ iter.remove_operand (2 );
241
+ using vec_t = Vectorized<opmath_t >;
242
+ cpu_kernel_vec (
243
+ iter,
244
+ [=](scalar_t a) -> scalar_t {
245
+ return div_floor_floating (static_cast <opmath_t >(a), b);
246
+ },
247
+ [=](Vectorized<scalar_t > a) {
248
+ return binary_op_scalar (
249
+ a, b, [](const vec_t & x, const vec_t & y) {
250
+ return div_floor_floating_vec (x, y);
251
+ });
252
+ });
238
253
});
239
- });
240
254
} else {
241
255
AT_DISPATCH_FLOATING_TYPES_AND2 (kBFloat16 , kHalf , dtype, " div_floor_cpu" , [&]() {
242
256
using vec_t = Vectorized<scalar_t >;
0 commit comments