Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrices being transposed #7

Closed
kockahonza opened this issue Nov 2, 2024 · 3 comments
Closed

Matrices being transposed #7

kockahonza opened this issue Nov 2, 2024 · 3 comments

Comments

@kockahonza
Copy link

Hi again, I'm sorry to be setting up yet another issue but I think this one is likely directly related to this package. I'm using the package to symbolically solve for eigenvalues of a matrix of Symbolics values using the "Eigensystem" wolfram command and I have noticed that the solutions returned are incorrect and I'm pretty sure correspond to the eigensystem of the matrix transpose. I suspect this has to do with julia using column major, as when I do the same call on the transpose of the matrix I get exactly the same solutions as mathematica reports in its own gui.

@eswagel
Copy link
Owner

eswagel commented Nov 5, 2024

Could you give code with the example you used? It may be as simple a fix as adding a transpose.

@kockahonza
Copy link
Author

Sure, I think this is the simplest demonstration:
in Julia

julia> @variables a, b, c, d
4-element Vector{Num}:
 a
 b
 c
 d

julia> mat = [a b; c d]
2×2 Matrix{Num}:
 a  b
 c  d

julia> SymbolicsMathLink.expr_to_mathematica(mat)
W`List[List[a, c], List[b, d]]`

copy pasting that into Mathematica for example as

aa = List[List[a, c], List[b, d]];
MatrixForm[aa]

shows the matrix transposed.

In terms of a fix, that is precisely what I have done for my code, just add a transpose call. Idk how that does in terms of efficiency etc. especially as the SymbolicsMathLink doesn't actually accept what tranpose returns but it needs to be made into a concrete matrix via for example a collect call. After reconsidering I don't think would have been caused by Julia using column major but more like a small bug somewhere in the code that constructs the List objects, fixing that would probably be the best fix.

@eswagel
Copy link
Owner

eswagel commented Nov 13, 2024

Good catch. I pushed a change to ensure the matrix is converted in row-major order. It won't be any less efficient than before.

@eswagel eswagel closed this as completed Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants