Opened 10 years ago

Closed 4 years ago

#2530 closed defect (fixed)

translation error of model in comment1: "model MatricesExp...."

Reported by: carlj@… Owned by: sjoelund.se
Priority: high Milestone: 1.16.0
Component: Backend Version: trunk
Keywords: Cc:

Description

When trying to instantiate Modelica.Math.exp in MSL 3.2.1, one gets the following errors:

Error: Internal error Cannot vectorize call with dimension [size(A, 1)]
Error: No matching function found for abs in component <NO COMPONENT>
candidates are .SystemModeler.Internal.intAbs<function>(Integer v) => Integer
 -.SystemModeler.Internal.realAbs<function>(Real v) => Real
Error: Failed to elaborate expression: abs(B[:,i]).
Error: Wrong type or wrong number of arguments to sum(abs(B[:,i]))'.
 (in component <NO COMPONENT>).
Error: Failed to elaborate expression: sum(abs(B[:,i])).
Error: Failed to elaborate expression: sum(abs(B[:,i])) - abs(B[i,i]).
Error: Internal error Cannot vectorize call with dimension [size(A, 1)]
Error: No matching function found for abs in component <NO COMPONENT>
candidates are .SystemModeler.Internal.intAbs<function>(Integer v) => Integer
 -.SystemModeler.Internal.realAbs<function>(Real v) => Real
Error: Failed to elaborate expression: abs(B[:,i]).
Error: Wrong type or wrong number of arguments to sum(abs(B[:,i]))'.
 (in component <NO COMPONENT>).
Error: Failed to elaborate expression: sum(abs(B[:,i])).
Error: Failed to elaborate expression: sum(abs(B[:,i])) - abs(B[i,i]).
Error: Failed to elaborate rhs of CO:=sum(abs(B[:,i])) - abs(B[i,i]);.
Error: Failed to instantiate statement:
  CO:=sum(abs(B[:,i])) - abs(B[i,i]);
Error: Failed to instantiate statement:
  for i in 1:na loop
      CO:=sum(abs(B[:,i])) - abs(B[i,i]);
    RO:=sum(abs(B[i,:])) - abs(B[i,i]);
    G:=RO / radix;
    F:=1;
    S:=CO + RO;
    while (not (CO >= G or CO == 0)) loop
          F:=F * radix;
      CO:=CO * radix2;
    end while;
    G:=RO * radix;
    while (not (CO < G or RO == 0)) loop
          F:=F / radix;
      CO:=CO / radix2;
    end while;
    if not (CO + RO) / F >= 0.95 * S then 
      G:=1 / F;
      D[i]:=D[i] * F;
      B[i,:]:=B[i,:] * G;
      B[:,i]:=B[:,i] * F;
      noconv:=true;
    else

    end if;
  end for;
Error: Failed to instantiate statement:
  while (noconv) loop
      noconv:=false;
    for i in 1:na loop
          CO:=sum(abs(B[:,i])) - abs(B[i,i]);
      RO:=sum(abs(B[i,:])) - abs(B[i,i]);
      G:=RO / radix;
      F:=1;
      S:=CO + RO;
      while (not (CO >= G or CO == 0)) loop
              F:=F * radix;
        CO:=CO * radix2;
      end while;
      G:=RO * radix;
      while (not (CO < G or RO == 0)) loop
              F:=F / radix;
        CO:=CO / radix2;
      end while;
      if not (CO + RO) / F >= 0.95 * S then 
        G:=1 / F;
        D[i]:=D[i] * F;
        B[i,:]:=B[i,:] * G;
        B[:,i]:=B[:,i] * F;
        noconv:=true;
      else

      end if;
    end for;
  end while;
Error: Failed to instantiate function .Modelica.Math.Matrices.balance in scope Modelica.Math.Matrices.exp.
Error: Failed to elaborate expression: balance(A).
Error: Failed to instantiate statement:
  (Diag,Atransf):=balance(A);
Error: Failed to instantiate function .Modelica.Math.Matrices.exp in scope MatricesExp.
Error: Failed to elaborate expression: Modelica.Math.Matrices.exp(A).
Error: Error occurred while flattening model MatricesExp
Error: Internal error Instantiation of MatricesExp failed with no error message.

Change History (9)

comment:1 Changed 10 years ago by carlj@…

Here is a model:

model MatricesExp
  Real A[2,2] = [1,2;3,4];
  Real B[2,2] = Modelica.Math.Matrices.exp(A);
end MatricesExp;

comment:2 Changed 10 years ago by sjoelund.se

I get a different error (the bug described in the messages above is a duplicate of #2529):

[Modelica 3.2.1/Math/package.mo:3259:5-3259:22:writable] Error: Wrong type or wrong number of arguments to identity(na)'.

I will keep it open until we fix the rest though.

comment:3 Changed 10 years ago by sjoelund.se

  • Owner changed from somebody to sjoelund.se
  • Status changed from new to assigned

comment:4 Changed 10 years ago by sjoelund.se

  • Resolution set to fixed
  • Status changed from assigned to closed

Fixed in r18627.

comment:5 Changed 6 years ago by anonymous

  • Component changed from Frontend to Backend
  • Milestone changed from 1.9.1 to 1.13.0
  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Summary changed from Can not instantiate Modelica.Math.exp to translation error of model in comment1: "model MatricesExp...."

comment:6 Changed 5 years ago by casella

  • Milestone changed from 1.13.0 to 1.14.0

Rescheduled to 1.14.0 after 1.13.0 releasee

comment:7 Changed 5 years ago by casella

The issue reported in comment:2 is still there.

Is it because na is a protected parameter with binding

na = size(A, 1)

where A is a variable?

comment:8 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:9 Changed 4 years ago by anonymous

  • Resolution set to fixed
  • Status changed from reopened to closed

works now on
Windows: OpenModelica v1.16.0-dev-232-g98b88856b (64-bit)
Linux: OpenModelica v1.16.0-dev-246-g46500237 (64-bit)

OM result verified with

  1. Julia exp([1 2; 3 4])
  2. WolframAlpha

https://www.wolframalpha.com/input/?i=exponential+of+matrix&assumption=%7B%22F%22%2C+%22MatrixExponentialCalculator%22%2C+%22matrixexp%22%7D+-%3E%22%7B%7B1%2C+2%7D%2C+%7B3%2C+4%7D%7D%22

Note: See TracTickets for help on using tickets.