Skip to content

Braces, Square Brakets and Parenthesis are Mixed Up #16

@AlexanderNenninger

Description

@AlexanderNenninger

MATLAB input
The incorrectly translated MATLAB code. Please include any special steps to reproduce the failed translation, beyond copy/pasting the MATLAB input and clicking "translate."

function [y]=formtensor(y,mid_inv,d,ry,n)
% Merge mid_inv: y:=inv(L)*y*inv(U)
for i=1:d
    y{i} = reshape(y{i}, ry(i), n(i)*ry(i+1));
    y{i} = mid_inv{i,2}*y{i};
    y{i} = reshape(y{i}, ry(i)*n(i), ry(i+1));
    y{i} = y{i}*mid_inv{i+1,1};
    y{i} = reshape(y{i}, ry(i), n(i), ry(i+1));
end;
y = cell2core(tt_tensor, y);
end

Expected Julia output
The correct Julia translation (not what the translator outputs).

function formtensor(y,mid_inv,d,ry,n)
    # Merge mid_inv: y:=inv(L)*y*inv(U)
    for i=1:d
        y[i] = reshape(y[i], ry[i], n[i]*ry[i+1])
        y[i] = mid_inv[i,2]*y[i]
        y[i] = reshape(y[i], ry[i]*n[i], ry[i+1])
        y[i] = y[i]*mid_inv[i+1,1]
        y[i] = reshape(y[i], ry[i], n[i], ry[i+1])
    end
    cell2core(tt_tensor, y)
end

Comments, suggestions, and other helpful details
Anything else that might be helpful. Thank you!

Incorrect code:

function formtensor(y,mid_inv,d,ry,n)
# Merge mid_inv: y:=inv(L)*y*inv(U)
for i=1:d
    y[i] = reshape(y[i], ry[i], n[i]*ry[i+1])
    y(i} = mid_inv[i,2)*y{i]
    y[i] = reshape(y[i], ry[i]*n[i], ry[i+1])
    y(i} = y[i]*mid_inv{i+1,1)
    y[i] = reshape(y[i], ry[i], n[i], ry[i+1])
end
y = cell2core(tt_tensor,y]
return [y]
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions