﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
5715	Bad simplification for n*n when n is Integer	Adrian Pop	Martin Sjölund	"Consider this:
{{{#!mo
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}}} 

{{{#!mo
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: 
{{{#!C
  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:
{{{#!mo
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;
}}}
"	defect	closed	high	1.16.0	Frontend		fixed		
