Skip to content

Commit 5692dc4

Browse files
authored
Merge pull request #1456 from stan-dev/test-coverage
Add a bunch of edge-case tests
2 parents ae2e897 + 26acd24 commit 5692dc4

File tree

131 files changed

+2864
-149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+2864
-149
lines changed

src/frontend/Deprecation_analysis.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ let expired (major, minor) =
1111
let deprecated_functions = String.Map.of_alist_exn []
1212
let stan_lib_deprecations = deprecated_functions
1313

14+
(* TODO deprecate other pre-variadics like algebra_solver? *)
1415
let deprecated_odes =
1516
String.Map.of_alist_exn
1617
[ ("integrate_ode", ("ode_rk45", (3, 0)))

src/frontend/Preprocessor.ml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@ let restore_prior_lexbuf () =
8383
lexbuf.lex_start_p <- old_pos;
8484
old_lexbuf
8585

86-
let maybe_remove_quotes str =
87-
let open String in
88-
if is_prefix str ~prefix:"\"" && is_suffix str ~suffix:"\"" then
89-
drop_suffix (drop_prefix str 1) 1
90-
else str
91-
9286
let find_include_fs lookup_paths fname =
9387
let rec loop paths =
9488
match paths with
@@ -131,7 +125,7 @@ let find_include fname =
131125

132126
let try_get_new_lexbuf fname =
133127
let lexbuf = Stack.top_exn include_stack in
134-
let new_lexbuf, file = find_include (maybe_remove_quotes fname) in
128+
let new_lexbuf, file = find_include fname in
135129
lexer_logger ("opened " ^ file);
136130
new_lexbuf.lex_start_p <-
137131
new_file_start_position file

src/frontend/Typechecker.ml

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,12 @@ let verify_identifier id : unit =
113113
"Variable name 'jacobian' will be a reserved word starting in Stan 2.38. \
114114
Please rename it!";
115115
if id.name = !model_name then
116-
Semantic_error.ident_is_model_name id.id_loc id.name |> error
117-
else if
116+
Semantic_error.ident_is_model_name id.id_loc id.name |> error;
117+
if
118118
String.is_suffix id.name ~suffix:"__"
119119
|| List.mem reserved_keywords id.name ~equal:String.equal
120120
then Semantic_error.ident_is_keyword id.id_loc id.name |> error
121121

122-
let distribution_name_variants name =
123-
match Utils.split_distribution_suffix name with
124-
| Some (stem, "lpmf") -> [name; stem ^ "_lpdf"]
125-
| Some (stem, "lpdf") -> [name; stem ^ "_lpmf"]
126-
| _ -> [name]
127-
128122
(** verify that the variable being declared is previous unused.
129123
allowed to shadow StanLib *)
130124
let verify_name_fresh_var loc tenv name =
@@ -160,10 +154,8 @@ let verify_name_fresh_udf loc tenv name =
160154
- is not already in use (for now)
161155
*)
162156
let verify_name_fresh tenv id ~is_udf =
163-
let f =
164-
if is_udf then verify_name_fresh_udf id.id_loc tenv
165-
else verify_name_fresh_var id.id_loc tenv in
166-
List.iter ~f (distribution_name_variants id.name)
157+
if is_udf then verify_name_fresh_udf id.id_loc tenv id.name
158+
else verify_name_fresh_var id.id_loc tenv id.name
167159

168160
let is_of_compatible_return_type rt1 srt2 =
169161
UnsizedType.(
@@ -513,10 +505,10 @@ let check_normal_fn ~is_cond_dist loc tenv id es =
513505
let is_known_family s =
514506
List.mem known_families s ~equal:String.equal in
515507
match suffix with
516-
| ("lpmf" | "lumpf") when Env.mem tenv (prefix ^ "_lpdf") ->
508+
| ("lpmf" | "lupmf") when Env.mem tenv (prefix ^ "_lpdf") ->
517509
Semantic_error.returning_fn_expected_wrong_dist_suffix_found loc
518510
(prefix, suffix)
519-
| ("lpdf" | "lumdf") when Env.mem tenv (prefix ^ "_lpmf") ->
511+
| ("lpdf" | "lupdf") when Env.mem tenv (prefix ^ "_lpmf") ->
520512
Semantic_error.returning_fn_expected_wrong_dist_suffix_found loc
521513
(prefix, suffix)
522514
| _ ->
@@ -1692,9 +1684,7 @@ and check_var_decl loc cf tenv sized_ty trans
16921684

16931685
(* function definitions *)
16941686
and exists_matching_fn_declared tenv id arg_tys rt =
1695-
let options =
1696-
List.concat_map ~f:(Env.find tenv) (distribution_name_variants id.name)
1697-
in
1687+
let options = Env.find tenv id.name in
16981688
let f = function
16991689
| Env.{kind= `UserDeclared _; type_= UFun (listedtypes, rt', _, _)}
17001690
when arg_tys = listedtypes && rt = rt' ->
@@ -1703,9 +1693,7 @@ and exists_matching_fn_declared tenv id arg_tys rt =
17031693
List.exists ~f options
17041694

17051695
and verify_unique_signature tenv loc id arg_tys rt =
1706-
let existing =
1707-
List.concat_map ~f:(Env.find tenv) (distribution_name_variants id.name)
1708-
in
1696+
let existing = Env.find tenv id.name in
17091697
let same_args = function
17101698
| Env.{type_= UFun (listedtypes, _, _, _); _}
17111699
when List.map ~f:snd arg_tys = List.map ~f:snd listedtypes ->

src/middle/UnsizedType.ml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ let pp_autodifftype ppf = function
4242
| AutoDiffable -> ()
4343
| tup -> pp_tuple_autodifftype ppf tup
4444

45-
let unsized_array_depth unsized_ty =
46-
let rec aux depth = function
47-
| UArray ut -> aux (depth + 1) ut
48-
| ut -> (ut, depth) in
49-
aux 0 unsized_ty
50-
5145
let count_dims unsized_ty =
5246
let rec aux dims = function
5347
| UArray t -> aux (dims + 1) t
@@ -176,7 +170,7 @@ let rec common_type = function
176170
let rec is_autodiffable = function
177171
| UReal | UVector | URowVector | UMatrix -> true
178172
| UArray t -> is_autodiffable t
179-
| _ -> false
173+
| _ (* wrong? *) -> false
180174

181175
let rec is_autodifftype possibly_adtype =
182176
match possibly_adtype with

src/middle/Utils.ml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,6 @@ let%expect_test "unnormalized name mangling" =
5858
stdlib_distribution_name "normal" |> ( ^ ) "; " |> print_string;
5959
[%expect {| bernoulli_logit_lpmf; normal_lpdf; normal_lpdf; normal |}]
6060

61-
let all_but_last_n l n =
62-
List.fold_right l ~init:([], n) ~f:(fun ele (accum, n) ->
63-
if n = 0 then (ele :: accum, n) else (accum, n - 1))
64-
|> fst
65-
66-
let%expect_test "all but last n" =
67-
let l = all_but_last_n [1; 2; 3; 4] 2 in
68-
print_s [%sexp (l : int list)];
69-
[%expect {| (1 2) |}]
70-
7161
(* Utilities for using Tuples and Transformations together *)
7262
let tuple_trans_exn = function
7363
| Transformation.TupleTransformation transforms -> transforms

src/stan_math_backend/Lower_stmt.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ let check_to_string = function
1616
| LowerUpper _ ->
1717
Common.ICE.internal_compiler_error
1818
[%message "LowerUpper is really two other checks tied together"]
19-
| Offset _ | Multiplier _ | OffsetMultiplier _ -> None
19+
| Offset _ | Multiplier _ | OffsetMultiplier _ ->
20+
Common.ICE.internal_compiler_error
21+
[%message "Offset and multiplier don't have a check"]
2022
| t -> constraint_to_string t
2123

2224
let math_fn_translations = function
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
functions {
2+
3+
real algebra_system_lpdf(vector x, vector y, array[] real dat,
4+
array[] int dat_int) {
5+
vector[2] f_x;
6+
f_x[1] = x[1] - y[1];
7+
f_x[2] = x[2] - y[2];
8+
return f_x[1];
9+
}
10+
}
11+
data {
12+
13+
}
14+
transformed data {
15+
vector[2] x;
16+
vector[2] y;
17+
array[0] real dat;
18+
array[0] int dat_int;
19+
20+
}
21+
parameters {
22+
vector[2] x_p;
23+
vector[2] y_p;
24+
}
25+
transformed parameters {
26+
vector[2] theta_p;
27+
28+
theta_p = solve_newton(algebra_system_lpdf, x, y, dat, dat_int);
29+
30+
}

0 commit comments

Comments
 (0)