You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/02/15 16:34:57 UTC
[GitHub] [arrow] paleolimbot opened a new pull request #12432: ARROW-13337: [R] Define Math group generics
paleolimbot opened a new pull request #12432:
URL: https://github.com/apache/arrow/pull/12432
This PR defines the `Math` group generic for `ArrowDatum`, which allows several more base R functions to be used with `Array` and `Scalar` objects. This is particularly useful for exposing decimal math kernels (which are non-existent in R to my knowledge) without having to go through a `Table`/dplyr query.
``` r
# remotes::install_github("paleolimbot/arrow/r@r-math-generics")
library(arrow, warn.conflicts = FALSE)
dec <- Array$create(12.34)$cast(decimal128(10, 2))
floor(dec)
#> Array
#> <decimal128(10, 2)>
#> [
#> 12.00
#> ]
round(dec, digits = 1)
#> Array
#> <decimal128(10, 2)>
#> [
#> 12.30
#> ]
cos(dec)
#> Array
#> <double>
#> [
#> 0.9744873987650982
#> ]
acos(dec - 12L)
#> Array
#> <double>
#> [
#> 1.2238794292677349
#> ]
# binary ops already worked
dec + 1L
#> Array
#> <decimal128(13, 2)>
#> [
#> 13.34
#> ]
dec * dec
#> Array
#> <decimal128(21, 4)>
#> [
#> 152.2756
#> ]
dec + dec
#> Array
#> <decimal128(11, 2)>
#> [
#> 24.68
#> ]
dec ^ dec
#> Array
#> <double>
#> [
#> 2.9297399331911957e+13
#> ]
```
I imagine at some point the code in arrow-datum.R and compute.R should be refactored to use all the translations that we've nicely defined in dplyr-funcs-*.R (there's a lot of overlap).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] paleolimbot commented on a change in pull request #12432: ARROW-13337: [R] Define Math group generics
Posted by GitBox <gi...@apache.org>.
paleolimbot commented on a change in pull request #12432:
URL: https://github.com/apache/arrow/pull/12432#discussion_r815899633
##########
File path: r/R/arrow-datum.R
##########
@@ -70,13 +70,50 @@ as.vector.ArrowDatum <- function(x, mode) {
#' @export
Ops.ArrowDatum <- function(e1, e2) {
Review comment:
Good catch! I had fixed unary + and - but forgot to add a test.
``` r
-(arrow::Array$create(1))
#> Error in eval_array_expression(.Generic, e1, e2): argument "e2" is missing, with no default
+(arrow::Array$create(1))
#> Error in eval_array_expression(.Generic, e1, e2): argument "e2" is missing, with no default
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] ursabot edited a comment on pull request #12432: ARROW-13337: [R] Define Math group generics
Posted by GitBox <gi...@apache.org>.
ursabot edited a comment on pull request #12432:
URL: https://github.com/apache/arrow/pull/12432#issuecomment-1066516105
Benchmark runs are scheduled for baseline = 6aa8daa6d25f4971d2fafe0eb66d0768a20cba68 and contender = ece0e23f1fd5a2ab403e4a645ed01a9c257c0260. ece0e23f1fd5a2ab403e4a645ed01a9c257c0260 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Finished :arrow_down:0.0% :arrow_up:0.0%] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/7abf20f6994a4c59aedc67da3f8f24f3...5bfb0056788b491ab430823a4dcff08c/)
[Scheduled] [test-mac-arm](https://conbench.ursa.dev/compare/runs/ea9a9cc3a7d14cc3abf9171bf3743453...a5df97e89ead4b65a33609e6c59fb8c5/)
[Scheduled] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/ca4349352e0246ad983f295538ccd05a...9cc426272df7444b8a30fcdafd833090/)
[Finished :arrow_down:1.15% :arrow_up:0.09%] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/3358dbabaff4477dad80dd789b9ddec3...30059c66dd5f4b1790577583cd9ec379/)
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] ursabot commented on pull request #12432: ARROW-13337: [R] Define Math group generics
Posted by GitBox <gi...@apache.org>.
ursabot commented on pull request #12432:
URL: https://github.com/apache/arrow/pull/12432#issuecomment-1066516105
Benchmark runs are scheduled for baseline = 6aa8daa6d25f4971d2fafe0eb66d0768a20cba68 and contender = ece0e23f1fd5a2ab403e4a645ed01a9c257c0260. ece0e23f1fd5a2ab403e4a645ed01a9c257c0260 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Scheduled] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/7abf20f6994a4c59aedc67da3f8f24f3...5bfb0056788b491ab430823a4dcff08c/)
[Scheduled] [test-mac-arm](https://conbench.ursa.dev/compare/runs/ea9a9cc3a7d14cc3abf9171bf3743453...a5df97e89ead4b65a33609e6c59fb8c5/)
[Scheduled] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/ca4349352e0246ad983f295538ccd05a...9cc426272df7444b8a30fcdafd833090/)
[Scheduled] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/3358dbabaff4477dad80dd789b9ddec3...30059c66dd5f4b1790577583cd9ec379/)
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] ursabot edited a comment on pull request #12432: ARROW-13337: [R] Define Math group generics
Posted by GitBox <gi...@apache.org>.
ursabot edited a comment on pull request #12432:
URL: https://github.com/apache/arrow/pull/12432#issuecomment-1066516105
Benchmark runs are scheduled for baseline = 6aa8daa6d25f4971d2fafe0eb66d0768a20cba68 and contender = ece0e23f1fd5a2ab403e4a645ed01a9c257c0260. ece0e23f1fd5a2ab403e4a645ed01a9c257c0260 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Finished :arrow_down:0.0% :arrow_up:0.0%] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/7abf20f6994a4c59aedc67da3f8f24f3...5bfb0056788b491ab430823a4dcff08c/)
[Finished :arrow_down:0.17% :arrow_up:0.0%] [test-mac-arm](https://conbench.ursa.dev/compare/runs/ea9a9cc3a7d14cc3abf9171bf3743453...a5df97e89ead4b65a33609e6c59fb8c5/)
[Finished :arrow_down:0.36% :arrow_up:0.0%] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/ca4349352e0246ad983f295538ccd05a...9cc426272df7444b8a30fcdafd833090/)
[Finished :arrow_down:1.15% :arrow_up:0.09%] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/3358dbabaff4477dad80dd789b9ddec3...30059c66dd5f4b1790577583cd9ec379/)
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] github-actions[bot] commented on pull request #12432: ARROW-13337: [R] Define Math group generics
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #12432:
URL: https://github.com/apache/arrow/pull/12432#issuecomment-1040495065
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] github-actions[bot] commented on pull request #12432: ARROW-13337: [R] Define Math group generics
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #12432:
URL: https://github.com/apache/arrow/pull/12432#issuecomment-1040495065
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] thisisnic closed pull request #12432: ARROW-13337: [R] Define Math group generics
Posted by GitBox <gi...@apache.org>.
thisisnic closed pull request #12432:
URL: https://github.com/apache/arrow/pull/12432
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] nealrichardson commented on a change in pull request #12432: ARROW-13337: [R] Define Math group generics
Posted by GitBox <gi...@apache.org>.
nealrichardson commented on a change in pull request #12432:
URL: https://github.com/apache/arrow/pull/12432#discussion_r817032092
##########
File path: r/R/arrow-datum.R
##########
@@ -70,13 +70,51 @@ as.vector.ArrowDatum <- function(x, mode) {
#' @export
Ops.ArrowDatum <- function(e1, e2) {
- if (.Generic == "!") {
- eval_array_expression(.Generic, e1)
- } else if (.Generic %in% names(.array_function_map)) {
- eval_array_expression(.Generic, e1, e2)
- } else {
- stop(paste0("Unsupported operation on `", class(e1)[1L], "` : "), .Generic, call. = FALSE)
+ if (missing(e2)) {
+ switch(
+ .Generic,
+ "!" = return(eval_array_expression(.Generic, e1)),
+ "+" =, "-" = return(eval_array_expression(.Generic, 0L, e1)),
Review comment:
There is a `negate_checked` function we use elsewhere for unary `-` that you can use here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] nealrichardson commented on a change in pull request #12432: ARROW-13337: [R] Define Math group generics
Posted by GitBox <gi...@apache.org>.
nealrichardson commented on a change in pull request #12432:
URL: https://github.com/apache/arrow/pull/12432#discussion_r812406136
##########
File path: r/R/arrow-datum.R
##########
@@ -70,13 +70,50 @@ as.vector.ArrowDatum <- function(x, mode) {
#' @export
Ops.ArrowDatum <- function(e1, e2) {
- if (.Generic == "!") {
- eval_array_expression(.Generic, e1)
- } else if (.Generic %in% names(.array_function_map)) {
- eval_array_expression(.Generic, e1, e2)
- } else {
- stop(paste0("Unsupported operation on `", class(e1)[1L], "` : "), .Generic, call. = FALSE)
+ if (missing(e2)) {
+ switch(
+ .Generic,
+ "!" = return(eval_array_expression(.Generic, e1)),
+ "+" =, "-" = return(eval_array_expression(.Generic, 0L, e1)),
+ )
}
+
+ switch(
+ .Generic,
+ "+" =, "-" =, "*" =, "/" =, "^" =, "%%" =, "%/%" =,
+ "==" =, "!=" =, "<" =, "<=" =, ">=" =, ">" =, "&" =, "|" = {
+ eval_array_expression(.Generic, e1, e2)
+ },
+ stop(paste0("Unsupported operation on `", class(e1)[1L], "` : "), .Generic, call. = FALSE)
+ )
+}
+
+#' @export
+Math.ArrowDatum <- function(x, ..., base = exp(1), digits = 0) {
+ switch(
+ .Generic,
+ abs =, sign =,
+ floor =, ceiling =, trunc =,
+ acos =, asin =, atan =,
+ cos =, sin =, tan = {
+ eval_array_expression(.Generic, x)
+ },
+ log = eval_array_expression("logb_checked", x, base),
+ log10 = eval_array_expression("log10_checked", x),
+ round = eval_array_expression(
+ "round",
+ x,
+ options = list(ndigits = digits, round_mode = RoundMode$HALF_TO_EVEN)
+ ),
+ sqrt =, exp =,
+ signif =, expm1 =, log1p =,
+ cospi =, sinpi =, tanpi =,
+ cosh =, sinh =, tanh =,
+ acosh =, asinh =, atanh =,
+ lgamma =, gamma =, digamma =, trigamma =,
+ cumsum =, cumprod =, cummax =, cumin =,
Review comment:
```suggestion
cumsum =, cumprod =, cummax =, cummin =,
```
##########
File path: r/R/arrow-datum.R
##########
@@ -70,13 +70,50 @@ as.vector.ArrowDatum <- function(x, mode) {
#' @export
Ops.ArrowDatum <- function(e1, e2) {
- if (.Generic == "!") {
- eval_array_expression(.Generic, e1)
- } else if (.Generic %in% names(.array_function_map)) {
- eval_array_expression(.Generic, e1, e2)
- } else {
- stop(paste0("Unsupported operation on `", class(e1)[1L], "` : "), .Generic, call. = FALSE)
+ if (missing(e2)) {
+ switch(
+ .Generic,
+ "!" = return(eval_array_expression(.Generic, e1)),
+ "+" =, "-" = return(eval_array_expression(.Generic, 0L, e1)),
+ )
}
+
+ switch(
+ .Generic,
+ "+" =, "-" =, "*" =, "/" =, "^" =, "%%" =, "%/%" =,
+ "==" =, "!=" =, "<" =, "<=" =, ">=" =, ">" =, "&" =, "|" = {
+ eval_array_expression(.Generic, e1, e2)
+ },
+ stop(paste0("Unsupported operation on `", class(e1)[1L], "` : "), .Generic, call. = FALSE)
+ )
+}
+
+#' @export
+Math.ArrowDatum <- function(x, ..., base = exp(1), digits = 0) {
+ switch(
+ .Generic,
+ abs =, sign =,
+ floor =, ceiling =, trunc =,
+ acos =, asin =, atan =,
+ cos =, sin =, tan = {
+ eval_array_expression(.Generic, x)
+ },
+ log = eval_array_expression("logb_checked", x, base),
+ log10 = eval_array_expression("log10_checked", x),
+ round = eval_array_expression(
+ "round",
+ x,
+ options = list(ndigits = digits, round_mode = RoundMode$HALF_TO_EVEN)
+ ),
+ sqrt =, exp =,
Review comment:
Can't we do these since we have support for `^`?
##########
File path: r/tests/testthat/test-compute-arith.R
##########
@@ -133,3 +133,38 @@ test_that("Dates casting", {
# Error: NotImplemented: Function add_checked has no kernel matching input types (array[date32[day]], scalar[double])
expect_equal(a + 2, Array$create(c((Sys.Date() + 1:4) + 2), NA_integer_))
})
+
+test_that("Math group generics work on Array objects", {
+ expect_equal(abs(Array$create(c(-1L, 1L))), Array$create(c(1L, 1L)))
+ expect_equal(
+ sign(Array$create(c(-1L, 1L))),
Review comment:
Just to make clear that it's not the identity function
```suggestion
sign(Array$create(c(-5L, 2L))),
```
##########
File path: r/R/arrow-datum.R
##########
@@ -70,13 +70,50 @@ as.vector.ArrowDatum <- function(x, mode) {
#' @export
Ops.ArrowDatum <- function(e1, e2) {
Review comment:
Why the changes to Ops.ArrowDatum? I don't see any test changes, and I don't follow how this change is an improvement.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] ursabot edited a comment on pull request #12432: ARROW-13337: [R] Define Math group generics
Posted by GitBox <gi...@apache.org>.
ursabot edited a comment on pull request #12432:
URL: https://github.com/apache/arrow/pull/12432#issuecomment-1066516105
Benchmark runs are scheduled for baseline = 6aa8daa6d25f4971d2fafe0eb66d0768a20cba68 and contender = ece0e23f1fd5a2ab403e4a645ed01a9c257c0260. ece0e23f1fd5a2ab403e4a645ed01a9c257c0260 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Finished :arrow_down:0.0% :arrow_up:0.0%] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/7abf20f6994a4c59aedc67da3f8f24f3...5bfb0056788b491ab430823a4dcff08c/)
[Scheduled] [test-mac-arm](https://conbench.ursa.dev/compare/runs/ea9a9cc3a7d14cc3abf9171bf3743453...a5df97e89ead4b65a33609e6c59fb8c5/)
[Scheduled] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/ca4349352e0246ad983f295538ccd05a...9cc426272df7444b8a30fcdafd833090/)
[Scheduled] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/3358dbabaff4477dad80dd789b9ddec3...30059c66dd5f4b1790577583cd9ec379/)
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] ursabot edited a comment on pull request #12432: ARROW-13337: [R] Define Math group generics
Posted by GitBox <gi...@apache.org>.
ursabot edited a comment on pull request #12432:
URL: https://github.com/apache/arrow/pull/12432#issuecomment-1066516105
Benchmark runs are scheduled for baseline = 6aa8daa6d25f4971d2fafe0eb66d0768a20cba68 and contender = ece0e23f1fd5a2ab403e4a645ed01a9c257c0260. ece0e23f1fd5a2ab403e4a645ed01a9c257c0260 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Finished :arrow_down:0.0% :arrow_up:0.0%] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/7abf20f6994a4c59aedc67da3f8f24f3...5bfb0056788b491ab430823a4dcff08c/)
[Finished :arrow_down:0.17% :arrow_up:0.0%] [test-mac-arm](https://conbench.ursa.dev/compare/runs/ea9a9cc3a7d14cc3abf9171bf3743453...a5df97e89ead4b65a33609e6c59fb8c5/)
[Scheduled] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/ca4349352e0246ad983f295538ccd05a...9cc426272df7444b8a30fcdafd833090/)
[Finished :arrow_down:1.15% :arrow_up:0.09%] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/3358dbabaff4477dad80dd789b9ddec3...30059c66dd5f4b1790577583cd9ec379/)
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org