Giter Club home page Giter Club logo

Comments (8)

szhorvat avatar szhorvat commented on June 4, 2024 1

Callback capability is not simple, and you may want to implement calling Julia from Mathematica before tackling the callback problem. But it's up to you.

Do you know if LinkClose is triggered automatically when the link goes out of scope?

No, it's not.

Or is there another "finalizer" mechanism we can use here?

Do check out Internal`WithLocalSettings and this thread. J/Link's JavaBlock is also based on WithLocalSettings. You could make something similar to JavaBlock, which essentially solves the same problem for J/Link. Unfortunately, it's not pretty.

from mathlink.jl.

MikeInnes avatar MikeInnes commented on June 4, 2024

In theory this should be fairly simple, just a case of registering a C function pointer (created from a Julia function) with MathLink, which can accept some Mathematica expression objects and return a new one.

Unfortunately I never actually figured out how to do this, if the API exists in MathLink I couldn't see it. MATLink may well have some clues – if anyone is able to dig around and figure something out then patches for this functionality are certainly welcome.

from mathlink.jl.

szhorvat avatar szhorvat commented on June 4, 2024

I have next to zero experience with Julia, so I cannot hack on this, but if you need some help with MathLink feel free to ask me (I am one of the authors of MATLink, which uses MathLink to call MATLAB from Mathematica).

from mathlink.jl.

simonbyrne avatar simonbyrne commented on June 4, 2024

Mathematica now has an External Languages interface:
https://reference.wolfram.com/language/guide/ExternalInterpretedLanguageInterfaces.html
which may be easier for this specific aim?

from mathlink.jl.

szhorvat avatar szhorvat commented on June 4, 2024

@simonbyrne I would not recommend it. There are no documented tools there that would help, and I am very sceptical about a one-shoe-fits-all solution. Each language should have its own, tailored interface.

from mathlink.jl.

szhorvat avatar szhorvat commented on June 4, 2024

What could potentially be an alternative to MathLink is to use the same communication method as these new interfaces, but not try to fit in the ExtenalEvaluate framework (there's no documented way to do that anyway).

They use ZeroMQ for interprocess communication, through ZeroMQLink` . Most of ZeroMQLink is now in documented system functions (see Socket*).

There still needs to be a way to encode/decode data. The new WXF format could be used for this. Its structure is fully documented, so it saves some of the guesswork that's typically needed when dealing with MathLink.

I mention all this as a potential alternative to MathLink. Do not take it as a recommendation.

from mathlink.jl.

simonbyrne avatar simonbyrne commented on June 4, 2024

Thanks @szhorvat, that is very good to know.

from mathlink.jl.

simonbyrne avatar simonbyrne commented on June 4, 2024

At the moment I am thinking about a similar problem of passing a Julia function or other object into mathematica (e.g. an arbitrary Julia function to NDSolve), which would require calling back into the Julia session.

One option is to open up a new link for each such function, which could then be polled in a background task in Julia (on the Mathematica side this would mean that calling the function would result in putting the arguments on the link, and getting the results back again).

The main problem with this approach would be knowing when to clean up the task on the Julia side. @szhorvat Do you know if LinkClose is triggered automatically when the link goes out of scope? Or is there another "finalizer" mechanism we can use here?

from mathlink.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.