lakras / matlab-to-julia

Translates MATLAB source code into Julia. Can be accessed here: https://lakras.github.io/matlab-to-julia

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

eye and other issues

baggepinnen opened this issue · comments

A(12*i-11:12*i-3,1:18) = [kron(Ra,eye(3)) kron(-eye(3),Rb')];
is translated to

A[12*i-11:12*i-3,1:18] = [kron(Ra,I]

It misses half the expression, but another problem is that I does not have size and thus is not a direct replacement to eye(3). kron will not know what size of I to assume. Consider defining eye(n) or use Eye from FillArrays

Hi! Thank you so much for this issue. There is a lot here, and I'm very glad you brought it up. I fixed the problem with half the expression going away, and also added using LinearAlgebra since it is necessary for I, and generally improved how packages are handled in the translation to make adding packages easier in the future.

As you might know, for normal uses, I is any size. For example:

using LinearAlgebra
A = [1 1; 1 1]
A + I
2×2 Array{Int64,2}:
 2  1
 1  2
A = [1 1 1; 1 1 1; 1 1 1]
A + I
3×3 Array{Int64,2}:
 2  1  1
 1  2  1
 1  1  2

You're absolutely right that I does not work in the context of, say, kron(A, eye(n)). I've added a special case for when eye(n) appears in the parameters of a call to kron. kron(A, eye(n)) now translates to kron(A, Eye{Int}(n)) (from FillArrays) instead of to kron(A, I). (And similar for kron(eye(n), A).) Let me know if you don't think that was a good solution, or if there are other cases when you think Eye{Int}(n) is more appropriate than I.

This has been a very fun issue. Thank you again!

Seems like a good fix to me (Y). Thanks for your efforts!

Yay! I'm so glad. Thank you again!