Opened 8 years ago

Last modified 3 years ago

#3592 assigned defect

Eigen values fails with error

Reported by: adeas31 Owned by: Karim.Abdelhak
Priority: high Milestone:
Component: Code Generation Version: v1.14.0-dev-nightly
Keywords: Cc: dma@…, davide.bazzi@…

Description

Using Matrices.eigenValues results in following error,

[CodegenCFunctions.tpl: 4698:15-4698:15]: Template error: This should have been handled in indexed assign and should not have gotten here. eigenvalues[:,2]

Use the attached file. If a parameter prefix is added to Real A then it works fine.

Attachments (1)

EigenTest.mo (217 bytes) - added by adeas31 8 years ago.

Download all attachments as: .zip

Change History (21)

Changed 8 years ago by adeas31

comment:1 Changed 8 years ago by sjoelund.se

  • Milestone changed from 1.9.4 to 1.9.5

Milestone pushed to 1.9.5

comment:2 Changed 8 years ago by sjoelund.se

  • Milestone changed from 1.9.5 to 1.10.0

Milestone renamed

comment:3 Changed 7 years ago by sjoelund.se

  • Milestone changed from 1.10.0 to 1.11.0

Ticket retargeted after milestone closed

comment:4 Changed 7 years ago by sjoelund.se

  • Milestone changed from 1.11.0 to 1.12.0

Milestone moved to 1.12.0 due to 1.11.0 already being released.

comment:5 Changed 7 years ago by kgkhoroshev

The bug is still actual(ver. 1.12.0 on Ubuntu 16.04). Thanks to adeas31 for "a parameter prefix" solution.

comment:6 Changed 6 years ago by casella

  • Milestone changed from 1.12.0 to Future

The milestone of this ticket has been reassigned to "Future".

If you think the issue is still valid and relevant for you, please select milestone 1.13.0 for back-end, code generation and run-time issues, or 2.0.0 for front-end issues.

If you are aware that the problem is no longer present, please select the milestone corresponding to the version of OMC you used to check that, and set the status to "worksforme".

In both cases, a short informative comment would be welcome.

comment:7 Changed 5 years ago by casella

  • Milestone changed from Future to 1.14.0

This is actually also relevant for work we are carrying out at Politecnico.

I did some analysis. If A is defined as a parameter, the old frontend evaluates the eigenValues() function during flattening, so that the code generation is trivial (BTW, the new frontend doesn't do that, therefore the model also fails with parameter A).

Apparently, something goes wrong with the code generation when the eigenValues function is involved.

comment:8 follow-up: Changed 5 years ago by casella

This model shows that the problem is with code generation for the external function dgeev()

model M
  Real A[3,3] = {{1, 0, 0}, {0,1,0}, {0,0,1}};
  Real eigval[3,2];
  Integer info;
  Real eigvec[3,3];
equation
 (eigval[:,1], eigval[:,2], eigvec, info) = Modelica.Math.Matrices.LAPACK.dgeev(A);
end M;

The error output is:

[CodegenCFunctions.tpl: 4978:15-4978:15]: Template error: daeExpCrefLhsSimContext:
This should have been handled in indexed assign and should not have gotten here 
eigval[:,2].

comment:9 Changed 5 years ago by casella

  • Cc davide.bazzi@… added
  • Owner changed from perost to Karim.Abdelhak
  • Status changed from new to assigned
  • Version set to v1.14.0-dev-nightly

@Karim.Abdelhak, I tentatively assign this to you, feel free to reassign it to somebody else if you deem it appropriate.

comment:10 Changed 5 years ago by casella

From what I understand, it is a problem with external functions returning more than one output

comment:11 in reply to: ↑ 8 ; follow-up: Changed 5 years ago by Karim.Abdelhak

Replying to casella:

The error output is:

[CodegenCFunctions.tpl: 4978:15-4978:15]: Template error: daeExpCrefLhsSimContext:
This should have been handled in indexed assign and should not have gotten here 
eigval[:,2].

Just to a question to clarify it for me:
Is it expected to be flattened out to eigval[1,2],eigval[2,2],... or is the code generation expected to generate arrays in the target code?

As it seems we flattened it out before, but generally we want to avoid flattening as much as possible in the future. I will try to recover the old behaviour, but i guess we have to think about it in general.

comment:12 in reply to: ↑ 11 Changed 5 years ago by casella

Replying to Karim.Abdelhak:

Just to a question to clarify it for me:
Is it expected to be flattened out to eigval[1,2],eigval[2,2],... or is the code generation expected to generate arrays in the target code?

I guess for the time being our strategy is to get omc to deal with as many models as possible using the old strategy (-> full flattening to scalars).

As a medium-long term goal we should implement a vector-preserving backend, but that's another story, we need to get all valid Modelica models to work ASAP, even if the efficiency is not optimal.

As it seems we flattened it out before, but generally we want to avoid flattening as much as possible in the future. I will try to recover the old behaviour, but i guess we have to think about it in general.

Agreed. BTW, which old behaviour do you refer to? This ticket has been open for three years, so I guess this function never worked at all so far in OMC.

comment:13 Changed 5 years ago by casella

@karim, your PR #2979 apparently didn't solve the problem, I'm still getting

[CodegenCFunctions.tpl: 5030:15-5030:15]: Template error: This should have been handled in indexed assign and should not have gotten here. eigenvalues[:,2].

if I run the test attached to this ticket

comment:14 follow-up: Changed 5 years ago by casella

@karim, can you have a look at this issue?

comment:15 in reply to: ↑ 14 Changed 5 years ago by Karim.Abdelhak

Replying to casella:

@karim, can you have a look at this issue?

I have quite some work to do at the moment, but when i start to work on tickets again i will look deeper into this issue.

comment:16 Changed 5 years ago by casella

OK, no problem :)

comment:17 Changed 5 years ago by casella

  • Milestone changed from 1.14.0 to 1.16.0

Releasing 1.14.0 which is stable and has many improvements w.r.t. 1.13.2. This issue is rescheduled to 1.16.0

comment:18 Changed 3 years ago by casella

  • Milestone changed from 1.16.0 to 1.17.0

Retargeted to 1.17.0 after 1.16.0 release

comment:19 Changed 3 years ago by casella

  • Milestone changed from 1.17.0 to 1.18.0

Retargeted to 1.18.0 because of 1.17.0 timed release.

comment:20 Changed 3 years ago by casella

  • Milestone 1.18.0 deleted

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.