PS a is an integer array and b is an integer scalar. On Wed, Jul 28, 2021 at 1:04 PM Rares Vernica <rvern...@gmail.com> wrote:
> Hello, > > I'm making use of the Compute Functions to do some basic arithmetic. One > operation I need to perform is the modulo, i.e., a % b. I'm debating > between two options: > > 1. Compute it using the available Compute Functions using a % b = a - a / > b * b, where / is the integer division. I assume that the divide compute > function between two integer arrays does integer division, right? My > concern with this approach is the overhead of using four Compute Functions. > > 2. Define a new Compute Function for modulo. Would something like this > suffice? > > struct Modulo { > template <typename T, typename Arg0, typename Arg1> > static enable_if_floating_point<T> Call(KernelContext*, Arg0 left, Arg1 > right, Status*) { > return left % right; > }} > auto modulo = MakeArithmeticFunctionNotNull<Modulo>("modulo", &div_doc); > AddDecimalBinaryKernels<Modulo>("modulo", &modulo); > DCHECK_OK(registry->AddFunction(std::move(modulo))); > > Thank you, > Rares >