#5715 closed defect (fixed)
Bad simplification for n*n when n is Integer
Reported by: | Adrian Pop | Owned by: | Martin Sjölund |
---|---|---|---|
Priority: | high | Milestone: | 1.16.0 |
Component: | Frontend | Version: | |
Keywords: | Cc: |
Description
Consider this:
function eig input Real a[n*n*2]; input Integer n; output Real vec[2*n]; output Real mat[n*n*2]; external "C" eigCompute(a,vec,mat,n) annotation(Library="eigenSolver", Include="#include \"eig.h\""); end eig; model testEigenSolver parameter Integer n = 3; Real a[n*n*2] = {1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10}; Real vec[2*n]; Real mat[n*n*2]; equation (vec,mat)=eig(a,n); end testEigenSolver;
The external function doesn't matter, just put something in those vectors.
The old front-end translates n*n
to n^2.0
function eig input Real[2 * n ^ 2.0] a; // n*n -> n^2.0 is just an abomination! input Integer n; output Real[2 * n] vec; output Real[2 * n ^ 2.0] mat; external "C" eigCompute(a, vec, mat, n); end eig;
which makes it so mat
variable will *ALWAYS* be zero after return from eig
because the mat
variable array in function eig
will have mat->dim_size[0] == 0
as in generated omc_eig
we have:
modelica_real tmp1; alloc_real_array(&(_vec), 1, (((modelica_integer) 2)) * (_n)); // _vec has no default value. tmp1 = _n; alloc_real_array(&(_mat), 1, (((modelica_integer) 2)) * ((tmp1 * tmp1))); // _mat has no default value.
The NF does much better, and it works fine:
function eig input Real[n * n * 2] a; input Integer n; output Real[2 * n] vec; output Real[n * n * 2] mat; external "C" eigCompute(a, vec, mat, n); end eig;
Change History (3)
comment:1 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → accepted |
comment:2 by , 5 years ago
Resolution: | → fixed |
---|---|
Status: | accepted → closed |
comment:3 by , 5 years ago
Milestone: | Future → 1.16.0 |
---|
Note:
See TracTickets
for help on using tickets.
https://github.com/OpenModelica/OpenModelica/pull/693