Opened 10 years ago

Last modified 10 years ago

#2805 new defect

Array of Records

Reported by: Vitalij Ruge Owned by: somebody
Priority: normal Milestone: Future
Component: Frontend Version: trunk
Keywords: Cc:

Description

There some issues with Arrays of Records, which has variable Array size.

package MyRecord
  record arrayRecord
    Real[:] v;
  end arrayRecord;

  model test1 "work"
    arrayRecord r[2] = {arrayRecord({1}), arrayRecord({1, 2})};
  end test1;

  model test2 "don't work"
    arrayRecord r1 = arrayRecord({1});
    arrayRecord r2 = arrayRecord({1, 2});
    arrayRecord r[2] = {r1, r2};
  end test2;

  model test3 "don't work"
    function f
      input arrayRecord in_r;
      output arrayRecord out_r = in_r;
    end f;

    arrayRecord r1 = arrayRecord({1});
    arrayRecord r2 = arrayRecord({1, 2});
    arrayRecord r[2] = {f(r1), f(r2)};
  end test3;

  model test4 "work"
    function f
      input arrayRecord in_r;
      output arrayRecord out_r = in_r;
    end f;

    constant arrayRecord r1 = arrayRecord({1});
    constant arrayRecord r2 = arrayRecord({1, 2});
    arrayRecord r[2] = {f(r1), f(r2)};
  end test4;
end MyRecord;

Change History (2)

comment:1 by Adrian Pop, 10 years ago

Vitalij, can you give more info on this?
What doesn't work, how it should actually be, etc.

comment:2 by Vitalij Ruge, 10 years ago

The goal is to create an Array of Records.
like

  R r1 = R(...); // record constructor
  R r2 = R(...); // record constructor
  R[2] r = {r1, r2};

where

record R;
  Real[n] x;
  parameter Integer n;
end R;

If r1.n is inequal r2.n we handling r1 and r2 as different datatypes and not more of type record R.
e.g.

r1: { Real[3] x; parameter Integer n = 3};
r2: { Real[5] x; parameter Integer n = 5};

So R[2] r = {r1,r2} became illegal, because r1 and r2 has other datatypes. Of the other hand it is possible to write

  R[2] r = {R(...)/*=r1*/, R(...)/*=r2*/};

or

  R[2] r = {f(r1)/*=r1*/, f(r2)/*=r2*/};

where f(r1) return (record out_r = r1). In this case we have the same function output datatype reacord R
and R[2] became legal.

But in both cases we shold have the same R[2] r, which we fill with the same information r1 and r2.

In addition for

  R[2] r = {f(r1)/*=r1*/, f(r2)/*=r2*/};

If r1 and r2 are not constant, we will runnig in some other issues, with match dimension r.x.

Note: See TracTickets for help on using tickets.