Skip to content

Relational operators and optimizations for `all()`

Ryan Curtin requested to merge rcurtin/bandicoot-code:relational into unstable

I realized that the most common use of all() is for relational expressions like all(X > 3), and there is actually some complexity in those. Based on Armadillo's implementation, I adapted the relevant classes to Bandicoot:

  • There are now several mtop_rel_* classes to handle relational expressions against a scalar (like X > 3). If evaluated, like Armadillo, they return a coot::Mat<uword>. Kernels were required for every possible relational operation (>, <, >=, <=, ==, !=).
  • Scalar relational expressions are twoway kernels, and so there is extra support to optimize relational expressions on conversions, like conv_to<Mat<eT2>>::from(X) > 3.
  • The mtGlue class needed to be added, to handle glue-expressions with a different output type.
  • The Glue_traits types were adapted from Armadillo for Bandicoot Glue types.
  • Several mtglue_rel_* classes are added to handle elementwise relational expressions like X > Y or similar.
  • Integrating conversions into elementwise relational operations is a bit trickier, so this is not done.
  • A couple extra optimizations for all() are added; e.g., all(X > 0) for unsigned integer X is equivalent to all(X).
  • Tests are added for all of these things.

I'll let this sit for a few days and then merge it.

The support here will be needed for any(), which is what I will implement next. :)

Merge request reports