-
Notifications
You must be signed in to change notification settings - Fork 1k
add GForce support for outer transformations #7600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
0534ed2
7b853ba
0b8220c
409f454
903e800
5ca7e41
597040e
151dc90
851ce78
b40b684
89f93f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3410,6 +3410,18 @@ is_constantish = function(q, check_singleton=FALSE) { | |
|
|
||
| .gforce_ops = c("+", "-", "*", "/", "^", "%%", "%/%") | ||
|
|
||
| # Outer transformations that can wrap GForce-optimizable expressions | ||
| # e.g., sqrt(min(x)) should be optimized to sqrt(gmin(x)) | ||
| # for the moment we only include unary elementwise functions | ||
| .gforce_outer_trans = c("sqrt", "abs", "sign", "floor", "ceiling", | ||
| "log", "log10", "log2", "log1p", "exp", "expm1", | ||
| "cos", "sin", "tan", "acos", "asin", "atan", | ||
| "cospi", "sinpi", "tanpi", | ||
| "cosh", "sinh", "tanh", "acosh", "asinh", "atanh", | ||
| "gamma", "lgamma", "digamma", "trigamma", | ||
| "is.na", "is.nan", "is.finite", "is.infinite", | ||
| "trunc", "round", "signif") | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello: "trunc" "cummax" "cummin" "cumprod" "cumsum" Note "log" can take "base = ..." as first argument. trunc can take ... also.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cumulative functions won't work. Maybe unary functions was too unprecise. I have added an "elementwise". Binary functions will optimize as long ppl provide |
||
| .unwrap_conversions = function(expr) { | ||
| while (.is_type_conversion(expr) && length(expr) >= 2L) expr = expr[[2L]] | ||
| expr | ||
|
|
@@ -3435,8 +3447,8 @@ is_constantish = function(q, check_singleton=FALSE) { | |
| )) | ||
| } | ||
|
|
||
| # check if arithmetic operator -> recursively validate ALL branches (like in AST) | ||
| if (is.symbol(q[[1L]]) && q[[1L]] %chin% .gforce_ops) { | ||
| # check if arithmetic operator or outer transformation -> recursively validate ALL branches (like in AST) | ||
| if (is.symbol(q[[1L]]) && q[[1L]] %chin% c(.gforce_ops, .gforce_outer_trans)) { | ||
| for (i in 2:length(q)) { | ||
| if (!.gforce_ok(q[[i]], x, envir)) return(FALSE) | ||
| } | ||
|
|
@@ -3467,8 +3479,8 @@ is_constantish = function(q, check_singleton=FALSE) { | |
| return(q) | ||
| } | ||
|
|
||
| # if arithmetic operator, recursively substitute its operands. we know what branches are valid from .gforce_ok | ||
| if (is.symbol(q[[1L]]) && q[[1L]] %chin% .gforce_ops) { | ||
| # if arithmetic operator or outer transformation, recursively substitute its operands. we know what branches are valid from .gforce_ok | ||
| if (is.symbol(q[[1L]]) && q[[1L]] %chin% c(.gforce_ops, .gforce_outer_trans)) { | ||
| for (i in 2:length(q)) { | ||
| q[[i]] = .gforce_jsub(q[[i]], names_x, envir) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what goes wrong if we just let any generic
foo()through here? As long as the "innermost" function is GForce-ableThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Things like
min(min(x))should already be quite problematic...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our own test suite dislikes e.g.
.Internal(mean(x))