@@ -18,8 +18,11 @@ r2f_handlers[["+"]] <- function(args, scope, ..., hoist = NULL) {
1818 hoist = hoist
1919 )
2020 . [left , right ] <- promote_arith_pair(left , right , " +" )
21- . [left , right ] <- maybe_reshape_vector_matrix(left , right , hoist , scope )
22- Fortran(glue(" ({left} + {right})" ), conform(left @ value , right @ value ))
21+ . [left , right ] <- conform_elementwise_operands(left , right , hoist , scope )
22+ Fortran(
23+ glue(" ({left} + {right})" ),
24+ infer_result_variable(left @ value , right @ value )
25+ )
2326 }
2427}
2528
@@ -38,24 +41,33 @@ r2f_handlers[["-"]] <- function(args, scope, ..., hoist = NULL) {
3841 hoist = hoist
3942 )
4043 . [left , right ] <- promote_arith_pair(left , right , " -" )
41- . [left , right ] <- maybe_reshape_vector_matrix(left , right , hoist , scope )
42- Fortran(glue(" ({left} - {right})" ), conform(left @ value , right @ value ))
44+ . [left , right ] <- conform_elementwise_operands(left , right , hoist , scope )
45+ Fortran(
46+ glue(" ({left} - {right})" ),
47+ infer_result_variable(left @ value , right @ value )
48+ )
4349 }
4450}
4551
4652r2f_handlers [[" *" ]] <- function (args , scope = NULL , ... , hoist = NULL ) {
4753 . [left , right ] <- lower_elementwise_operands(args , scope , ... , hoist = hoist )
4854 . [left , right ] <- promote_arith_pair(left , right , " *" )
49- . [left , right ] <- maybe_reshape_vector_matrix(left , right , hoist , scope )
50- Fortran(glue(" ({left} * {right})" ), conform(left @ value , right @ value ))
55+ . [left , right ] <- conform_elementwise_operands(left , right , hoist , scope )
56+ Fortran(
57+ glue(" ({left} * {right})" ),
58+ infer_result_variable(left @ value , right @ value )
59+ )
5160}
5261
5362r2f_handlers [[" /" ]] <- function (args , scope = NULL , ... , hoist = NULL ) {
5463 . [left , right ] <- lower_elementwise_operands(args , scope , ... , hoist = hoist )
5564 left <- maybe_cast_double(left )
5665 right <- maybe_cast_double(right )
57- . [left , right ] <- maybe_reshape_vector_matrix(left , right , hoist , scope )
58- Fortran(glue(" ({left} / {right})" ), conform(left @ value , right @ value ))
66+ . [left , right ] <- conform_elementwise_operands(left , right , hoist , scope )
67+ Fortran(
68+ glue(" ({left} / {right})" ),
69+ infer_result_variable(left @ value , right @ value )
70+ )
5971}
6072
6173r2f_handlers [[" ^" ]] <- function (args , scope , ... , hoist = NULL ) {
@@ -68,15 +80,15 @@ r2f_handlers[["^"]] <- function(args, scope, ..., hoist = NULL) {
6880 if (identical(right @ value @ mode , " logical" )) {
6981 right <- cast_to_mode(right , " integer" , " ^" )
7082 }
71- . [left , right ] <- maybe_reshape_vector_matrix (left , right , hoist , scope )
83+ . [left , right ] <- conform_elementwise_operands (left , right , hoist , scope )
7284 mode <- reduce_promoted_mode(left , right )
7385 if (! identical(mode , " complex" )) {
7486 mode <- " double"
7587 }
7688 # Parenthesizing the exponent avoids non-standard `** -1_c_int`.
7789 Fortran(
7890 glue(" ({left} ** ({right}))" ),
79- conform (left @ value , right @ value , mode = mode )
91+ infer_result_variable (left @ value , right @ value , mode = mode )
8092 )
8193}
8294
@@ -104,17 +116,17 @@ r2f_handlers[["%%"]] <- function(args, scope, ..., hoist = NULL) {
104116 }
105117 left <- cast_to_mode(left , mode , " %%" )
106118 right <- cast_to_mode(right , mode , " %%" )
107- . [left , right ] <- maybe_reshape_vector_matrix (left , right , hoist , scope )
108- out_val <- conform (left @ value , right @ value )
119+ . [left , right ] <- conform_elementwise_operands (left , right , hoist , scope )
120+ out_val <- infer_result_variable (left @ value , right @ value )
109121 # MODULO gives result with sign(right) - matches R %% behaviour
110122 Fortran(glue(" modulo({left}, {right})" ), out_val )
111123}
112124
113125r2f_handlers [[" %/%" ]] <- function (args , scope , ... , hoist = NULL ) {
114126 . [left , right ] <- lower_elementwise_operands(args , scope , ... , hoist = hoist )
115127 . [left , right ] <- promote_arith_pair(left , right , " %/%" )
116- . [left , right ] <- maybe_reshape_vector_matrix (left , right , hoist , scope )
117- out_val <- conform (left @ value , right @ value )
128+ . [left , right ] <- conform_elementwise_operands (left , right , hoist , scope )
129+ out_val <- infer_result_variable (left @ value , right @ value )
118130
119131 expr <- switch (
120132 out_val @ mode ,
0 commit comments