Open ryanmrichard opened 4 years ago
Interestingly it appears to work if the this
tensor for the reduction (lhs
in my MWE) is the empty sparse tensor.
this is not a bug, this is a missing feature ... the binary reduction op is run over a logical-and of the shapes to the two arguments. Indeed, note that in MyReducer
there are no operator()
overloads where the first or the second argument is "missing".
@evaleev is correct. I didn't encounter any cases where it wasn't necessary to have a logical-or reduction, or could not be accomplished by other means. In this case, you can:
double v = (lhs("i") - rhs("i")).sum();
The feature could be added with a small amount of work in the binary reduction expression function. I can point out the bit of code, if anyone wants to take a stab at it.
@justusc the subtraction was an example. What I'm literally trying to do is to implement Numpy's allclose
, i.e., std::fabs(lhs) <= atol + rtol * std::fabs(rhs)
followed by logical-and (lhs
and rhs
are elements of the tensors atol
and rtol
define "close") are followed by logical-and. The problem is the comparison is skipped for zero tiles, which is fine only if both tiles are supposed to be zero.
@justusc thanks, I think expr.h:665-671
+ minor mods elsewhere ... with c++17 it will be a relatively straightforward spaghetty of if constexpr
@evaleev yes, that is what I was going to point out. On a side note, c++17 would have made a lot of TA code much simpler.
Not sure if this is a feature or a bug, but as far as I can tell the reduction functor is not used to reduce the tiles to scalars if one of the tiles is zero. For reductions without the zero-product property, this produces an incorrect result. MWE below.
I would expect the following to print 1, but it prints 0:
If you change
temp(0) = 0.0;
totemp(0) = 2.0
the code correctly prints -1.