Skip to content
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

Adding back in rvalue checks on 1d indexes #849

Merged
merged 1 commit into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/stan_math_backend/Expression_gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ let minus_one e =

let is_single_index = function Index.Single _ -> true | _ -> false

let dont_need_range_check = function
| Index.Single Expr.Fixed.({pattern= Var id; _}) ->
not (Utils.is_user_ident id)
| _ -> false

let promote_adtype =
List.fold
~f:(fun accum expr ->
Expand Down Expand Up @@ -499,7 +504,7 @@ and pp_expr ppf Expr.Fixed.({pattern; meta} as e) =
when Some Internal_fun.FnReadData = Internal_fun.of_string_opt f ->
pp_indexed_simple ppf (strf "%a" pp_expr e, idx)
| _
when List.for_all ~f:is_single_index idx
when List.for_all ~f:dont_need_range_check idx
&& not (UnsizedType.is_indexing_matrix (Expr.Typed.type_of e, idx))
->
pp_indexed_simple ppf (strf "%a" pp_expr e, idx)
Expand Down
8 changes: 6 additions & 2 deletions test/integration/good/code-gen/cl.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1258,11 +1258,15 @@ class optimize_glm_model final : public model_base_crtp<optimize_glm_model> {
current_statement__ = 174;
lp_accum__.add(
normal_id_glm_lpdf<false>(y_v_d_opencl__,
to_matrix_cl(X_d_a[(1 - 1)]), alpha, to_matrix_cl(beta), sigma));
to_matrix_cl(
rvalue(X_d_a, cons_list(index_uni(1), nil_index_list()),
"X_d_a")), alpha, to_matrix_cl(beta), sigma));
current_statement__ = 175;
lp_accum__.add(
normal_id_glm_lpdf<propto__>(y_v_d_opencl__,
to_matrix_cl(X_d_a[(1 - 1)]), alpha, to_matrix_cl(beta), sigma));
to_matrix_cl(
rvalue(X_d_a, cons_list(index_uni(1), nil_index_list()),
"X_d_a")), alpha, to_matrix_cl(beta), sigma));
}
} catch (const std::exception& e) {
stan::lang::rethrow_located(e, locations_array__[current_statement__]);
Expand Down
Loading