rsmenon / MATLink

Communicate with MATLAB from Mathematica
matlink.org
67 stars 14 forks source link

Can MATLAB function handles point to Mathematica code? #87

Closed Armavica closed 8 years ago

Armavica commented 8 years ago

Some functions in MATLAB (for example fminsearch) take as argument function handles.

In my case, I would like to use MATLAB's optimization routines on a function programmed in Mathematica. Reading the MATLink documentation and examples, I understand that passing a pointer to a Mathematica function to MATLAB is not currently supported: is this planned (may I help?) or is it simply not possible?

rsmenon commented 8 years ago

You're right that this is not currently supported. This is because of limitations in the MATLAB Engine, so you might even say that this is not possible with the current version of MATLink.

But calling Mathematica functions from MATLAB is definitely possible using MEX files and we have verified this in a prototype. We haven't pursued this further yet because:

  1. There simply hasn't been much demand for this feature.

    Szabolcs and I like it in principle and see many benefits from it (like fminsearch and other optimization/PDE routines where MATLAB is better), but in the 3 years that MATLink has been around and with thousands of users using it, we've only gotten about 2-3 requests for it. It appears that the primary user base of MATLink is a heavy Mathematica user, who needs to only reach into MATLAB for using some shared code/data from colleagues. So they are mostly fine with the current one-directional flow.

  2. Neither of us currently have the time and bandwidth to devote to this.

    Moving to MEX is not a simple step — it requires changing a lot of the underlying architecture, so it would require a lot of development time (thus potential for new bugs), designing the UX when integrating the bi-directional flow in a way that feels natural in both systems (i.e. if you're calling Mathematica from MATLAB, it should feel like you're writing MATLAB code and not some weird DSL). All this would necessitate another round of rigorous testing on a large combination matrix: P versions of MATLAB x Q versions of Mathematica x R platforms x S versions of platform... that's a lot! Given the overall low demand for this feature and the stability of the current version of MATLink, we've put this on the back burner.

With that context, there aren't any currently scheduled/planned releases although we haven't ruled out any either. However, if you'd like to contribute, we would definitely welcome it!