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

Passing arrays to MathLink #71

Closed
gganapat opened this issue Nov 6, 2023 · 2 comments
Closed

Passing arrays to MathLink #71

gganapat opened this issue Nov 6, 2023 · 2 comments

Comments

@gganapat
Copy link

gganapat commented Nov 6, 2023

Hi, while trying out MathLink.jl for Wolfram/Mathematica, I'm stuck on passing on arrays to be evaluated.

In Pluto;

a = 10;

weval(W`Sqrt[$a]`) gives right answer but if I do

a = collect(10:30)

weval(W`Sqrt[$a]`),

I get

Part::partd: Part specification Sqrt[[10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]] is longer than depth of object. Part::partd: Part specification Sqrt[[10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]] is longer than depth of object.

I tried different things, but stuck on how to proceed. Basically Mathematica/Wolfram Engine is looking for lists in the form {10,11,12,..} but $a passes [10,11,12..]

I'm finding MathLink.jl really neat but some sticking points exist.

Thanks!

@fremling
Copy link
Collaborator

fremling commented Nov 6, 2023

Hi,

The problem with your approach is that $a is creating a table that will have valid julia syntax, whereas you want somethings that will have valid mathematica syntax.

The way around this is to use that MathLink can construct Mathematica functions the same way as Mathematica varaibles, using the W"<var>" command. There for try this code:

a = collect(10:30)
weval(W"Sqrt"(a))

Here the W"Sqrt" will handle the vector a = collect(10:30) correctly.

@gganapat
Copy link
Author

gganapat commented Nov 7, 2023

Thank you! This worked perfectly well.

gani -

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