Opened 13 years ago

Last modified 13 years ago

#1595 closed defect (fixed)

sum-function does not work with arrays with three or more dimensions

Reported by: Teemu Lempinen Owned by: Teemu Lempinen
Priority: high Milestone:
Component: Version: 1.7.0
Keywords: Cc: Teemu Lempinen,

Description

sum-function does not work properly if an array given to it has three or more dimensions. I suppose it should handle any number of dimensions.

 model ArrayTest
   Real Valve1[2,2,2] = fill(1,2,2,2);
   Real total;
 equation
   total = sum(Valve1);
 end ArrayTest;

flattens to

 class ArrayTest
   Real Valve1[1,1,1] = 1.0;
   Real Valve1[1,1,2] = 1.0;
   Real Valve1[1,2,1] = 1.0;
   Real Valve1[1,2,2] = 1.0;
   Real Valve1[2,1,1] = 1.0;
   Real Valve1[2,1,2] = 1.0;
   Real Valve1[2,2,1] = 1.0;
   Real Valve1[2,2,2] = 1.0;
   Real total;
 equation
   total = {Valve1[1,1,1] + (Valve1[1,2,1] + (Valve1[2,1,1] + Valve1[2,2,1])),Valve1[1,1,2] + (Valve1[1,2,2] + (Valve1[2,1,2] + Valve1[2,2,2]))};
 end ArrayTest;
 [ArrayTest2.mo:3:3-3:13:writable] Error: Internal error Initial value of unknown type: {4.0,4.0}
 [SimCodeC.tpl:2372:14-2372:14:writable] Error: Template error: initial value of unknown type: {4.0,4.0}

(Sorry about the formatting issues in the last bug report. I was lazy and tried to use the WYSIWYG)

Change History (4)

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

Do not be tempted to try this model with the changes that fixed the previous bug; the code compiles but will give the wrong result because sum seems to be totally wrong...

total = {1.0 +<ADD_ARR></tp:REAL[2, 2]/> (1.0 +<ADD_ARR></tp:REAL[2, 2]/> (1.0 +<ADD_ARR></tp:REAL[2, 2]/> 1.0)),1.0 +<ADD_ARR></tp:REAL[2, 2]/> (1.0 +<ADD_ARR></tp:REAL[2, 2]/> (1.0 +<ADD_ARR></tp:REAL[2, 2]/> 1.0))}

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

Fixed in r9696 (compiles fine). The sum call is evaluated during initialization - it is not optimized to 8.0 which could have some minor impact on performance compared to 2d or 1d arrays.

comment:3 by Teemu Lempinen, 13 years ago

Still does not work with the model in the bug description. The generated model exe crashes with the following message:

messages = "Simulation execution failed for model: ArrayTest
Assertion failed: 0&&\"Only concatenation dimension 1 and 2 supported\", file re
al_array.c, line 710

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

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

Ok, this is now fixed in r9705 (? not finished yet), but in a lazy way. I added more optimizations to sums (so it works if the elements of the matrix are known; but might not work if you call sum(fn(A))). I think the C runtime has rather large problems with 3d-matrices, and I do not have enough time to look into it right now.

Note: See TracTickets for help on using tickets.