Skip to content

Commit

Permalink
Merge pull request #664 from stan-dev/bugfix/elementwise-pow
Browse files Browse the repository at this point in the history
Bugfix/elementwise pow and empty matrices
  • Loading branch information
rok-cesnovar authored Aug 7, 2020
2 parents 3032660 + f55adde commit 16bb25b
Show file tree
Hide file tree
Showing 10 changed files with 4,634 additions and 904 deletions.
17 changes: 12 additions & 5 deletions src/middle/Stan_math_signatures.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1079,11 +1079,18 @@ let () =
add_unqualified ("is_nan", ReturnType UInt, [UReal]) ;
add_binary "lbeta" ;
add_binary "lchoose" ;
add_unqualified
("linspaced_array", ReturnType (UArray UReal), [UInt; UReal; UReal]) ;
add_unqualified
("linspaced_row_vector", ReturnType URowVector, [UInt; UReal; UReal]) ;
add_unqualified ("linspaced_vector", ReturnType UVector, [UInt; UReal; UReal]) ;
add_qualified
( "linspaced_array"
, ReturnType (UArray UReal)
, [(DataOnly, UInt); (DataOnly, UReal); (DataOnly, UReal)] ) ;
add_qualified
( "linspaced_row_vector"
, ReturnType URowVector
, [(DataOnly, UInt); (DataOnly, UReal); (DataOnly, UReal)] ) ;
add_qualified
( "linspaced_vector"
, ReturnType UVector
, [(DataOnly, UInt); (DataOnly, UReal); (DataOnly, UReal)] ) ;
add_unqualified ("lkj_corr_cholesky_log", ReturnType UReal, [UMatrix; UReal]) ;
add_unqualified ("lkj_corr_cholesky_lpdf", ReturnType UReal, [UMatrix; UReal]) ;
add_unqualified ("lkj_corr_cholesky_rng", ReturnType UMatrix, [UInt; UReal]) ;
Expand Down
18 changes: 11 additions & 7 deletions src/stan_math_backend/Expression_gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ and gen_operator_app = function
fun ppf es ->
pp_scalar_binary ppf "(%a@ /@ %a)" "elt_divide(@,%a,@ %a)" es
| Pow -> fun ppf es -> pp_binary_f ppf "pow" es
| EltPow ->
fun ppf es -> pp_scalar_binary ppf "(%a@ *@ %a)" "pow(@,%a,@ %a)" es
| EltPow -> fun ppf es -> pp_binary_f ppf "pow" es
| Equals -> fun ppf es -> pp_binary_f ppf "logical_eq" es
| NEquals -> fun ppf es -> pp_binary_f ppf "logical_neq" es
| Less -> fun ppf es -> pp_binary_f ppf "logical_lt" es
Expand Down Expand Up @@ -358,11 +357,16 @@ and pp_user_defined_fun ppf (f, es) =
and pp_compiler_internal_fn ut f ppf es =
let pp_array_literal ppf es =
let pp_add_method ppf () = pf ppf ")@,.add(" in
pf ppf "stan::math::array_builder<%a>()@,.add(%a)@,.array()"
pp_unsizedtype_local
(promote_adtype es, promote_unsizedtype es)
(list ~sep:pp_add_method pp_expr)
es
if List.length es = 0 then
pf ppf "stan::math::array_builder<%a>()@,.add(0)@,.array()"
pp_unsizedtype_local
(promote_adtype es, promote_unsizedtype es)
else
pf ppf "stan::math::array_builder<%a>()@,.add(%a)@,.array()"
pp_unsizedtype_local
(promote_adtype es, promote_unsizedtype es)
(list ~sep:pp_add_method pp_expr)
es
in
match Internal_fun.of_string_opt f with
| Some FnMakeArray -> pp_array_literal ppf es
Expand Down
3 changes: 2 additions & 1 deletion src/stan_math_backend/Stan_math_code_gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,8 @@ using stan::model::index_min_max;
using stan::model::index_multi;
using stan::model::index_omni;
using stan::model::nil_index_list;
using namespace stan::math; |}
using namespace stan::math;
using stan::math::pow; |}

(** Functions needed in the model class not defined yet in stan math.
FIXME: Move these to the Stan repo when these repos are joined.
Expand Down
3 changes: 2 additions & 1 deletion test/integration/good/code-gen/cl.expected
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ using stan::model::index_min_max;
using stan::model::index_multi;
using stan::model::index_omni;
using stan::model::nil_index_list;
using namespace stan::math;
using namespace stan::math;
using stan::math::pow;

static int current_statement__ = 0;
static const std::vector<string> locations_array__ = {" (found before start of program)",
Expand Down
2,570 changes: 1,931 additions & 639 deletions test/integration/good/code-gen/cpp.expected

Large diffs are not rendered by default.

Loading

0 comments on commit 16bb25b

Please sign in to comment.