Is there any reasons we only use the empty_value
when values
is empty?
Should we do it like the following?
template<typename Op>
inline Expr ComputeReduce(const Array<Expr>& values, Expr empty_value) {
if (values.size() == 0U) {
CHECK(empty_value.defined());
return empty_value;
}
Expr res = empty_value;
for (size_t i = 0; i < values.size(); ++i) {
res = ComputeExpr<Op>(res, values[i]);
}
return res;
}
The reason why I am asking is sometime we might need to cast the reduced value to empty_value
. For example, we can have int64_t empty_value
and cast the product of Array<int32>values
to int64
when needed.