apache / arrow

Apache Arrow is the universal columnar format and multi-language toolbox for fast data interchange and in-memory analytics
https://arrow.apache.org/
Apache License 2.0
14.57k stars 3.54k forks source link

[C++][Compute] Add quotient and modulo kernels #28497

Open asfimport opened 3 years ago

asfimport commented 3 years ago

Add a pair of binary kernels to compute the:

Reporter: Ian Cook / @ianmcook

Related issues:

Note: This issue was originally created as ARROW-12755. Please see the migration documentation for further details.

asfimport commented 3 years ago

Antoine Pitrou / @pitrou: Perhaps this could be a single "divmod" kernel if that makes the computation more efficient?

(note "divmod" is the Python name for that functionality)

Should also choose what happens for negative divisors.

asfimport commented 3 years ago

yibocai#1: For the record, libdivide may be useful for optimal integer division performance. https://github.com/ridiculousfish/libdivide

NOTE: this is only for vector/scalar, when there's only one divisor.

asfimport commented 3 years ago

yibocai#1: I agree "divmod" to return quotient and remainder at once is more efficient. x86 idiv instruction always returns quotient together with remainder. In computation cost, div = mod = divmod. Arm sdiv instruction does division only. So div < mod = divmod. We can use the existing "division" kernel if we only want the quotient. https://godbolt.org/z/fvGh3vh3f

asfimport commented 3 years ago

Eduardo Ponce / @edponce: @cyb70289 thanks for the tips!

asfimport commented 2 years ago

Krisztian Szucs / @kszucs: Since the PR is in draft, I'm postponing to 8.0

asfimport commented 2 years ago

Apache Arrow JIRA Bot: This issue was last updated over 90 days ago, which may be an indication it is no longer being actively worked. To better reflect the current state, the issue is being unassigned per project policy. Please feel free to re-take assignment of the issue if it is being actively worked, or if you plan to start that work soon.

asfimport commented 1 year ago

Dr. Jan-Philip Gehrcke: Bonjour! I wanted to use the modulo operator today in a filter expression in a scanner. Antoine and Jacob pointed me here. https://github.com/apache/arrow/pull/11116 has stalled a bit seemingly. If I can, I would love to help land that.

asfimport commented 1 year ago

Eduardo Ponce / @edponce: Hi, [~jgehrcke]! I will be glad to share with you this PR and what is missing to get it over the finish line. As I understand this PR is mostly complete, but it requires to be fully rebased (I did some minor updates a few minutes ago) and we need to add more unit tests.

randolf-scholz commented 6 months ago

A modulo kernel would also be nice for duration types (which are just integers under the hood). For instance, in time series a common task is autodetect the frequency at which time stamps are provided, which can be done by computing the GCD of all time deltas.