spot-toolbox / spotless

A fork of the Systems Polynomial Optimization Toolbox.
28 stars 35 forks source link

@msspoly/subsasgn.m can not handle empty vectors as indizes #18

Open tarquasso opened 7 years ago

tarquasso commented 7 years ago

Affects @msspoly/subsasgn.m

Can not handle a index assignment using zeros(0,n) or zeros(n,0) see this test script:

nq = 3;
q=msspoly('q',nq);
s=msspoly('s',nq);
c=msspoly('c',nq);
qt=TrigPoly(q,s,c);

J = zeros(3,3) * qt;

pos_row_indices = 1:3;

v_or_qdot_indices = zeros(0,1);

Jpos = zeros(3,0);

J(pos_row_indices, v_or_qdot_indices) = Jpos;

It fails with this error:

In an assignment  A(:) = B, the number of elements in A and B must be the same.

Error in msspoly/subsasgn (line 89)
            p1.dim(2) = max(max(js),p1.dim(2));

Error in TrigPoly/subsasgn (line 365)
        a.p=subsasgn(a.p,s,b);

Error in msspoly_subsasgn_test (line 15)
J(pos_row_indices, v_or_qdot_indices) = Jpos;
tarquasso commented 7 years ago

Proposing to fix it by:

            if(numel(s.subs{1}) == 0 || numel(s.subs{2}) == 0)
              q = p1;
              return
            end

added after case 2