-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Add promoter expression #1004
Merged
WardBrian
merged 25 commits into
stan-dev:master
from
SteveBronder:feature/add-promoter
Jan 12, 2022
+2,939
−1,922
Merged
Add promoter expression #1004
Changes from 15 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
b84f321
Allow complex promotion in functions, not just operators
WardBrian 2dc3b02
Add another test
WardBrian b372606
Update tests
WardBrian 1027b24
Adds promoter Expr type
SteveBronder b9fcb46
add promotion backend
SteveBronder 7a06aad
fixup rest of backend to compile tests
SteveBronder 4b7142a
Start AST-level promotion
WardBrian 199c58d
Promotions from signatures
WardBrian e6020bd
Fix merge
WardBrian 2949fe5
Merge branch 'master' into feature/add-promoter
WardBrian 1cdb7b5
Reorg
WardBrian eb4dc85
Use promote_scalar instead
WardBrian f7fe919
Reorganize tests
WardBrian 8bf389f
Add test
WardBrian 94d9e9e
Comment cleanup
WardBrian 31311bd
Quick cleanup per review
WardBrian cab7b60
Use promotion in ternary if expression
WardBrian b763cc4
Merge branch 'master' into feature/add-promoter
WardBrian 7556e05
Consolidate test
WardBrian b2124bf
Change ternary test
WardBrian f17fc05
Cleanup
WardBrian b438d96
Make sure promotion is of scalar type only
WardBrian 093b6cd
Merge branch 'master' into feature/add-promoter
WardBrian d906688
Reorg/add tests
WardBrian af2d260
More array tests
WardBrian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
functions { | ||
complex ident (complex x){ | ||
return x; | ||
} | ||
|
||
real foo(array[] real zs){ | ||
return zs[0]; | ||
} | ||
} | ||
|
||
generated quantities { | ||
real z = 1; | ||
complex zi = ident(z); | ||
array[4] int zs = {1,2,3,4}; | ||
real x = foo(zs); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
320 changes: 167 additions & 153 deletions
320
test/integration/good/compiler-optimizations/cpp.expected
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
functions { | ||
void printer(array[] real x){ | ||
print(x); | ||
} | ||
} | ||
|
||
model { | ||
array[3] int d = {1,2,3}; | ||
printer(d); | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
functions { | ||
void promote_complex_array(array[] complex zs){ | ||
print(zs[0]); | ||
} | ||
} | ||
|
||
generated quantities { | ||
real x = norm(1); | ||
x = norm(1.5); | ||
x = norm(3i); | ||
|
||
real y = abs(4+3i); | ||
y = arg(4+1i); | ||
y = arg(2.5); | ||
y = arg(1); | ||
|
||
complex z; | ||
z = conj(4.1+7i); | ||
z = conj(4.1); | ||
z = conj(0); | ||
|
||
z = proj(4.1+7i); | ||
z = proj(4.1); | ||
z = proj(0); | ||
|
||
z = polar(1.5,0.5); | ||
z = polar(2,3); | ||
|
||
array[3] int xs = {1,2,3}; | ||
promote_complex_array(xs); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(include ../dune) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
$ ../../../../../install/default/bin/stanc --auto-format array_promotion.stan | ||
functions { | ||
void printer(array[] real x) { | ||
print(x); | ||
} | ||
} | ||
model { | ||
array[3] int d = {1, 2, 3}; | ||
printer(d); | ||
} | ||
|
||
$ ../../../../../install/default/bin/stanc --auto-format bad_newton_x_r_type.stan | ||
functions { | ||
vector algebra_system(vector y, vector theta, array[] real x_r, | ||
array[] int x_i) { | ||
vector[2] f_y; | ||
f_y[1] = y[1] - theta[1]; | ||
f_y[2] = y[2] - theta[2]; | ||
return f_y; | ||
} | ||
} | ||
data { | ||
|
||
} | ||
transformed data { | ||
vector[2] y; | ||
array[0] int x_r; | ||
array[0] int x_i; | ||
} | ||
parameters { | ||
vector[2] theta_p; | ||
real dummy_parameter; | ||
} | ||
transformed parameters { | ||
vector[2] y_s_p; | ||
y_s_p = algebra_solver_newton(algebra_system, y, theta_p, x_r, x_i); | ||
} | ||
model { | ||
dummy_parameter ~ normal(0, 1); | ||
} | ||
|
||
$ ../../../../../install/default/bin/stanc --auto-format bad_newton_x_r_type_control.stan | ||
functions { | ||
vector algebra_system(vector y, vector theta, array[] real x_r, | ||
array[] int x_i) { | ||
vector[2] f_y; | ||
f_y[1] = y[1] - theta[1]; | ||
f_y[2] = y[2] - theta[2]; | ||
return f_y; | ||
} | ||
} | ||
data { | ||
|
||
} | ||
transformed data { | ||
vector[2] y; | ||
array[0] int x_r; | ||
array[0] int x_i; | ||
} | ||
parameters { | ||
vector[2] theta_p; | ||
real dummy_parameter; | ||
} | ||
transformed parameters { | ||
vector[2] y_s_p; | ||
y_s_p = algebra_solver_newton(algebra_system, y, theta_p, x_r, x_i, 0.01, | ||
0.01, 10); | ||
} | ||
model { | ||
dummy_parameter ~ normal(0, 1); | ||
} | ||
|
||
$ ../../../../../install/default/bin/stanc --auto-format bad_x_r_type.stan | ||
functions { | ||
vector algebra_system(vector y, vector theta, array[] real x_r, | ||
array[] int x_i) { | ||
vector[2] f_y; | ||
f_y[1] = y[1] - theta[1]; | ||
f_y[2] = y[2] - theta[2]; | ||
return f_y; | ||
} | ||
} | ||
data { | ||
|
||
} | ||
transformed data { | ||
vector[2] y; | ||
array[0] int x_r; | ||
array[0] int x_i; | ||
} | ||
parameters { | ||
vector[2] theta_p; | ||
real dummy_parameter; | ||
} | ||
transformed parameters { | ||
vector[2] y_s_p; | ||
y_s_p = algebra_solver(algebra_system, y, theta_p, x_r, x_i); | ||
} | ||
model { | ||
dummy_parameter ~ normal(0, 1); | ||
} | ||
|
||
$ ../../../../../install/default/bin/stanc --auto-format bad_x_r_type_control.stan | ||
functions { | ||
vector algebra_system(vector y, vector theta, array[] real x_r, | ||
array[] int x_i) { | ||
vector[2] f_y; | ||
f_y[1] = y[1] - theta[1]; | ||
f_y[2] = y[2] - theta[2]; | ||
return f_y; | ||
} | ||
} | ||
data { | ||
|
||
} | ||
transformed data { | ||
vector[2] y; | ||
array[0] int x_r; | ||
array[0] int x_i; | ||
} | ||
parameters { | ||
vector[2] theta_p; | ||
real dummy_parameter; | ||
} | ||
transformed parameters { | ||
vector[2] y_s_p; | ||
y_s_p = algebra_solver(algebra_system, y, theta_p, x_r, x_i, 0.01, 0.01, | ||
10); | ||
} | ||
model { | ||
dummy_parameter ~ normal(0, 1); | ||
} | ||
|
||
$ ../../../../../install/default/bin/stanc --auto-format complex_functions.stan | ||
functions { | ||
void promote_complex_array(array[] complex zs) { | ||
print(zs[0]); | ||
} | ||
} | ||
generated quantities { | ||
real x = norm(1); | ||
x = norm(1.5); | ||
x = norm(3i); | ||
|
||
real y = abs(4 + 3i); | ||
y = arg(4 + 1i); | ||
y = arg(2.5); | ||
y = arg(1); | ||
|
||
complex z; | ||
z = conj(4.1 + 7i); | ||
z = conj(4.1); | ||
z = conj(0); | ||
|
||
z = proj(4.1 + 7i); | ||
z = proj(4.1); | ||
z = proj(0); | ||
|
||
z = polar(1.5, 0.5); | ||
z = polar(2, 3); | ||
|
||
array[3] int xs = {1, 2, 3}; | ||
promote_complex_array(xs); | ||
} | ||
|
||
$ ../../../../../install/default/bin/stanc --auto-format propto-bad1.stan | ||
model { | ||
target += normal_lupdf(1 | {0}, 1); | ||
} | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[optional] this could be a bit smarter, like promoting literals to literals and collapsing promotion of promotion.