#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 , 9 years ago
Cc: | added |
---|
comment:2 by , 9 years ago
comment:3 by , 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 , 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.
follow-up: 7 comment:5 by , 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 , 9 years ago
OK, then we could solve it in the runtime as well -- a solution in the backend appears to be not trivial.
comment:7 by , 9 years ago
Component: | Backend → Frontend |
---|
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:9 by , 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 , 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 , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
one problem in the cpp runtime is that the array concatenation function assumes the arrays have a row-major oder. I will fix this.