Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#3409 closed defect (fixed)

Wrong array concatenation with zeros operator

Reported by: Rüdiger Franke Owned by: somebody
Priority: high Milestone: 1.9.4
Component: Frontend Version: trunk
Keywords: Cc: Niklas Worschech

Description

This case is motivated by Modelica.Mechanics.MultiBody.Visualizers.Colors.ColorMaps.jet which is used by Modelica.Mechanics.MultiBody.Examples.Elementary.Surfaces. Interestingly the MSL test validates nevertheless in the C runtime.

package ArrayConcat
  function f
    input Real v[:];
    output Real m[size(v, 1), 2];
  algorithm
     m := [zeros(size(v, 1)), v];
  end f;

  model Test
    Real m[:,:] = f({0.1, 0.2, 0.3});
  end Test;
end ArrayConcat;

OpenModelica builds an Integer array (maybe motivated by the zeros), fills it with the Real vector v (the values are corrupted) and then casts the Integer array to a Real array:

setCommandLineOptions("+d=nogen,initialization");
loadFile("ArrayConcat.mo");
simulate(ArrayConcat.Test);
val(m[1,2], 1);
val(m[2,2], 1);
val(m[3,2], 1);

gives with the C runtime:

4.591870180066958e+18
4.596373779694328e+18
4.599075939470751e+18

The Cpp runtime fails to compile the model due to type mismatch in the SCode.

Change History (13)

comment:1 by Niklas Worschech, 9 years ago

Cc: Niklas Worschech added

comment:2 by Niklas Worschech, 9 years ago

one problem in the cpp runtime is that the array concatenation function assumes the arrays have a row-major oder. I will fix this.

comment:3 by Niklas Worschech, 9 years ago

The compilation in the cpp runimte fails, becaues the array concatenation function accepts only arrays of the same type.

comment:4 by Rüdiger Franke, 9 years ago

The Cpp code genration shows up a problem with the initialization of array dimensions for this example (compiler complains about dim -1). I had tried to fix this but then encountered the type issue as well. This must be solved in the backend first.

comment:5 by Niklas Worschech, 9 years ago

I am not sure if this is a backend problem. Because the specification allows array concatenation of different types.

comment:6 by Rüdiger Franke, 9 years ago

OK, then we could solve it in the runtime as well -- a solution in the backend appears to be not trivial.

in reply to:  5 comment:7 by Martin Sjölund, 9 years ago

Component: BackendFrontend

Replying to niklwors:

I am not sure if this is a backend problem. Because the specification allows array concatenation of different types.

Yes, but the front-end is responsible for type-checking expressions. That is where the problem lies.

comment:8 by Martin Sjölund, 9 years ago

Milestone: 1.9.31.9.4

Moved to new milestone 1.9.4

comment:9 by Per Östlund, 9 years ago

Fixed in the frontend in ceb1975. Do you want this ticket kept open for the cpp runtime issues? Just close it otherwise.

comment:10 by Rüdiger Franke, 9 years ago

The further Cpp issues that caused Modelica.Mechanics.MultiBody.Examples.Elementary.Surfaces to fail (array dim of -1) appear fixed in 1.9.3. This means that the Cpp runtime now builds simulators for the whole MSL 3.2.1!

comment:11 by Rüdiger Franke, 9 years ago

Resolution: fixed
Status: newclosed

comment:12 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.4-1.9.x

Milestone renamed

comment:13 by Martin Sjölund, 9 years ago

Milestone: 1.9.4-1.9.x1.9.4

Milestone renamed

Note: See TracTickets for help on using tickets.