Skip to content
Closed
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
2 changes: 2 additions & 0 deletions src/middle/SignatureMismatch.ml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ let rec check_same_type depth t1 t2 =
match (t1, t2) with
| t1, t2 when t1 = t2 -> None
| UnsizedType.(UReal, UInt) when depth < 1 -> None
| UnsizedType.(UComplex, UInt) when depth < 1 -> None
| UnsizedType.(UComplex, UReal) when depth < 1 -> None
| UFun (_, _, s1, _), UFun (_, _, s2, _)
when Fun_kind.without_propto s1 <> Fun_kind.without_propto s2 ->
Some
Expand Down
3 changes: 1 addition & 2 deletions src/middle/Stan_math_signatures.ml
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,6 @@ let () =
List.iter
~f:(fun x -> add_unqualified ("add", ReturnType x, [x; x], AoS))
bare_types ;
add_unqualified ("add", ReturnType UComplex, [UComplex; UReal], AoS) ;
add_unqualified ("add", ReturnType UVector, [UVector; UReal], AoS) ;
add_unqualified ("add", ReturnType URowVector, [URowVector; UReal], AoS) ;
add_unqualified ("add", ReturnType UMatrix, [UMatrix; UReal], AoS) ;
Expand Down Expand Up @@ -924,6 +923,7 @@ let () =
, AoS ) )
bare_types )
(List.range 1 8) ;
add_unqualified ("arg", ReturnType UReal, [UComplex], AoS) ;
add_unqualified ("asin", ReturnType UComplex, [UComplex], AoS) ;
add_unqualified ("asinh", ReturnType UComplex, [UComplex], AoS) ;
add_unqualified ("atan", ReturnType UComplex, [UComplex], AoS) ;
Expand Down Expand Up @@ -1796,7 +1796,6 @@ let () =
, [UArray UInt; URowVector; UVector; UVector; UReal]
, AoS ) ;
add_nullary "negative_infinity" ;
add_unqualified ("norm", ReturnType UReal, [UReal], AoS) ;
add_unqualified ("norm", ReturnType UReal, [UComplex], AoS) ;
add_unqualified
( "normal_id_glm_lpdf"
Expand Down
18 changes: 0 additions & 18 deletions test/integration/bad/compound-assign/stanc.expected
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ Ill-typed arguments supplied to assignment operator +=: lhs has type (real) => r
(vector, int) => void
(vector, real) => void
(vector, vector) => void
(complex, int) => void
(complex, real) => void
(complex, complex) => void
(row_vector, int) => void
(row_vector, real) => void
Expand Down Expand Up @@ -121,8 +119,6 @@ Ill-typed arguments supplied to assignment operator +=: lhs has type array[] mat
(vector, int) => void
(vector, real) => void
(vector, vector) => void
(complex, int) => void
(complex, real) => void
(complex, complex) => void
(row_vector, int) => void
(row_vector, real) => void
Expand All @@ -147,8 +143,6 @@ Ill-typed arguments supplied to assignment operator +=: lhs has type matrix and
(vector, int) => void
(vector, real) => void
(vector, vector) => void
(complex, int) => void
(complex, real) => void
(complex, complex) => void
(row_vector, int) => void
(row_vector, real) => void
Expand Down Expand Up @@ -185,8 +179,6 @@ Ill-typed arguments supplied to assignment operator +=: lhs has type array[] rea
(vector, int) => void
(vector, real) => void
(vector, vector) => void
(complex, int) => void
(complex, real) => void
(complex, complex) => void
(row_vector, int) => void
(row_vector, real) => void
Expand All @@ -211,8 +203,6 @@ Ill-typed arguments supplied to assignment operator +=: lhs has type array[] row
(vector, int) => void
(vector, real) => void
(vector, vector) => void
(complex, int) => void
(complex, real) => void
(complex, complex) => void
(row_vector, int) => void
(row_vector, real) => void
Expand All @@ -238,8 +228,6 @@ Ill-typed arguments supplied to assignment operator +=: lhs has type vector and
(vector, int) => void
(vector, real) => void
(vector, vector) => void
(complex, int) => void
(complex, real) => void
(complex, complex) => void
(row_vector, int) => void
(row_vector, real) => void
Expand All @@ -264,8 +252,6 @@ Ill-typed arguments supplied to assignment operator +=: lhs has type int and rhs
(vector, int) => void
(vector, real) => void
(vector, vector) => void
(complex, int) => void
(complex, real) => void
(complex, complex) => void
(row_vector, int) => void
(row_vector, real) => void
Expand All @@ -290,8 +276,6 @@ Ill-typed arguments supplied to assignment operator +=: lhs has type real and rh
(vector, int) => void
(vector, real) => void
(vector, vector) => void
(complex, int) => void
(complex, real) => void
(complex, complex) => void
(row_vector, int) => void
(row_vector, real) => void
Expand All @@ -316,8 +300,6 @@ Ill-typed arguments supplied to assignment operator +=: lhs has type array[] vec
(vector, int) => void
(vector, real) => void
(vector, vector) => void
(complex, int) => void
(complex, real) => void
(complex, complex) => void
(row_vector, int) => void
(row_vector, real) => void
Expand Down
1 change: 0 additions & 1 deletion test/integration/bad/stanc.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,6 @@ Ill-typed arguments supplied to infix operator +. Available signatures:
(real, vector) => vector
(vector, real) => vector
(vector, vector) => vector
(complex, real) => complex
(complex, complex) => complex
(real, row_vector) => row_vector
(row_vector, real) => row_vector
Expand Down
23 changes: 23 additions & 0 deletions test/integration/good/code-gen/complex_functions.stan
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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);

}
38 changes: 26 additions & 12 deletions test/integration/good/code-gen/complex_scalar.stan
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ functions {
complex foo(){
return to_complex();
}

real foo1(complex z){
return 1.0;
}

complex foo2(real r){
return to_complex(r);
}
Expand All @@ -20,6 +22,7 @@ functions {
complex[] foo6(real r){
return {to_complex(r), to_complex(r,r)};
}

complex[] foo7(complex[] z){
return z;
}
Expand Down Expand Up @@ -66,7 +69,7 @@ transformed data {
td_complex_array = d_complex_array;
td_complex_array = {td_complex, 1, to_complex(2,3)};
td_complex_array[1] = to_complex(5.1,6);

td_complex_array_2d = d_complex_array_2d;
td_complex_array_2d = {{1, td_complex, 3}, {to_complex(), to_complex(1.1), to_complex(1,2.1)}};
td_complex_array_2d[1,1] = to_complex(1,2);
Expand All @@ -77,11 +80,11 @@ transformed data {
for (td_j in 1:2) {
for (td_k in 1:3) {
td_complex_array_2d[td_j, td_k] = to_complex(1, 2.2);}}

for (td_j in td_complex_array_2d){
for (td_k in td_j){
td_complex = td_k;}}

td_r = get_real(td_complex);
td_r = get_imag(td_complex);
td_r = get_real(td_complex_array[1]);
Expand All @@ -90,6 +93,8 @@ transformed data {
td_r = get_imag(td_complex_array_2d[1,1]);

td_complex = foo();
td_r = foo1(1);
td_r = foo1(2.5);
td_r = foo1(td_complex);
td_complex = foo2(td_r);
td_complex = foo3(td_complex);
Expand All @@ -112,7 +117,7 @@ transformed parameters {
complex tp_complex;
complex tp_complex_array[2];
complex tp_complex_array_2d[2, 3];

tp_complex = tp_r;
tp_complex = d_i;
tp_complex = d_r;
Expand All @@ -135,7 +140,7 @@ transformed parameters {
tp_complex_array = p_complex_array;
tp_complex_array = {tp_complex, 1, to_complex(2,3)};
tp_complex_array[1] = to_complex(5.1,6);

tp_complex_array_2d = d_complex_array_2d;
tp_complex_array_2d = p_complex_array_2d;
tp_complex_array_2d = {{1, tp_complex, 3}, {to_complex(), to_complex(1.1), to_complex(1,2.1)}};
Expand All @@ -151,7 +156,7 @@ transformed parameters {
for (tp_j in tp_complex_array_2d){
for (tp_k in tp_j){
tp_complex = tp_k;}}

tp_r = get_real(tp_complex);
tp_r = get_imag(tp_complex);
tp_r = get_real(tp_complex_array[1]);
Expand Down Expand Up @@ -208,7 +213,7 @@ generated quantities {
gq_complex_array = p_complex_array;
gq_complex_array = {gq_complex, 1, to_complex(2,3)};
gq_complex_array[1] = to_complex(5.1,6);

gq_complex_array_2d = d_complex_array_2d;
gq_complex_array_2d = p_complex_array_2d;
gq_complex_array_2d = {{1, gq_complex, 3}, {to_complex(), to_complex(1.1), to_complex(1,2.1)}};
Expand All @@ -224,7 +229,7 @@ generated quantities {
for (gq_j in gq_complex_array_2d){
for (gq_k in gq_j){
gq_complex = gq_k;}}

gq_r = get_real(gq_complex);
gq_r = get_imag(gq_complex);
gq_r = get_real(gq_complex_array[1]);
Expand All @@ -247,7 +252,7 @@ generated quantities {
complex z = to_complex(1,2);
complex y = to_complex(3,4);
int i_arr[0];
int i_arr_1[1];
int i_arr_1[1];

gq_complex = z+y;
gq_complex = z+gq_r;
Expand Down Expand Up @@ -347,7 +352,7 @@ generated quantities {
gq_i = (d_complex != d_r);
gq_i = (p_r != d_complex);
gq_i = (p_complex != d_r);

gq_r = abs(z);
gq_r = abs(p_complex);
gq_r = abs(d_complex);
Expand Down Expand Up @@ -402,7 +407,7 @@ generated quantities {
gq_r = get_imag(z);
gq_r = get_imag(p_complex);
gq_r = get_imag(d_complex);

gq_r = get_real(z);
gq_r = get_real(p_complex);
gq_r = get_real(d_complex);
Expand Down Expand Up @@ -500,9 +505,18 @@ generated quantities {
gq_complex = to_complex(p_r);
gq_complex = to_complex(d_r);

gq_complex += 1;
gq_complex += 3.1;
gq_complex += 4i;
print(gq_complex);
gq_complex = add(1,3i);
gq_complex = add(3i,1);
gq_complex = add(3i,0.5);
gq_complex = add(0.5,3i);

// test imaginary literal
complex zi = 1+3.14i;
zi = zi * 0i;
complex yi = to_complex(0, 1.1) + to_complex(0.0, 2.2) + to_complex();
real x = get_real(3i - 40e-3i);
}
}
Loading