victorlei / smop

Small Matlab to Python compiler
MIT License
1.08k stars 410 forks source link

Matrix element assignment inside square brackets #142

Open andreasg123 opened 5 years ago

andreasg123 commented 5 years ago

In the code fragment below (from here: https://github.com/fhernandogallego/sparsEDA/blob/master/sparsEDA.m), the matrix element assignment inside square brackets does not get converted correctly.

Also, the planerot function is not defined. That may be a good addition for libsmop.py.

% Remove the j-th column
R(:,j) = [];
[m,n] = size(R);

% R now has nonzeros below the diagonal in columns j through n.
% We use plane rotations to zero the 'violating nonzeros'.
for k = j:n
    p = k:k+1;
    [G,R(p,k)] = planerot(R(p,k));
    if k < n
        R(p,k+1:n) = G*R(p,k+1:n);
    end
end
    # Remove the j-th column
    R[arange(),j]=[]
# sparsEDA.m:405
    m,n=size(R,nargout=2)
# sparsEDA.m:406
    # R now has nonzeros below the diagonal in columns j through n.
# We use plane rotations to zero the 'violating nonzeros'.
    for k in arange(j,n).reshape(-1):
        p=arange(k,k + 1)
# sparsEDA.m:411
        G,R(p,k)=planerot(R(p,k),nargout=2)
# sparsEDA.m:412
        if k < n:
            R[p,arange(k + 1,n)]=dot(G,R(p,arange(k + 1,n)))
  File "sparsEDA.py", line 531
    G,R(p,k)=planerot(R(p,k),nargout=2)
    ^
SyntaxError: can't assign to function call
dingshansun commented 2 years ago

I have the same problem. When I tried to use the elements from a vector, for example, A=concat([1,2,3,4,5,6,7,8,9]) B=A(arange(1,3)) the following error occurs: Traceback (most recent call last): File "<input>", line 1, in <module> TypeError: 'numpy.ndarray' object is not callable