-
Notifications
You must be signed in to change notification settings - Fork 26
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
Pass a python function to a matlab function? #89
Comments
That is not possible at the moment, I'm afraid. But you can pass Matlab functions to Matlab:
|
Thank you!Bastibe. If one can pass a function, that will be really cool. |
It can be done, but I don't have the time to implement the functionality at the moment, sorry. One would have to create a proxy function on the Matlab side that wraps a call back to Python. At the moment, there is no back channel for Matlab to ask things from Python, so this is not a trivial thing to do. |
Perhaps data interface such as TCP/IP can works. If the datatype can be freely transported , the tool will be more awesome |
The data is not the (biggest) issue. Transplant already serializes all data through a TCP connection or a local socket. The problem is that you have to create a function inside Matlab that behaves just like the Python function. This is easier when passing a Matlab function to Python: A new function object is created in Python's local scope that passes all its arguments to Matlab, computes the results there, then passes the result or error back to Python. But the other way around is much more demanding: How would you handle keyword arguments? Is it safe to create a function in Matlab's global scope? How do you handle generators, or async functions, or callable objects? How would you handle a Python function that returns something that is not serializable to Matlab data? How would you handle Exceptions? The thing is, Python is a much more powerful language than Matlab. Representing Matlab functions and data in Python is possible because Matlab functions and data are simple things. Representing a Python It can be done, but it is not a trivial thing to do. There will be plenty of corner cases. (But you can already grab a Matlab function and pass it back to Matlab.) |
I am a little bit confused about how to use
transplant.Matlab
I want to pass a python function and several other parameters to a matlab function, for example
matlab.fminsearch
. So I tryBut
func(1)
returnsMany Thanks
The text was updated successfully, but these errors were encountered: