bastibe / transplant

Transplant is an easy way of calling Matlab from Python
https://transplant.readthedocs.io
Other
110 stars 26 forks source link

Few suggestions #46

Closed tsdev closed 7 years ago

tsdev commented 7 years ago

As playing for a longer time with transplant I have suggestions for a few minor improvements. Maybe you find some of the usefull.

tsdev commented 7 years ago

I made a speed test on my system pyspinw_speed This is just timing the command

A = m.zeros(pow(10,N),1)

It seems transferring and converting doubles of 100 MB takes about 1 s, it was 4 s on another computer compared to the negligible time it takes to create these matrices in Matlab. This shows that enabling keeping variables in the Matlab proxy would greatly increase the speed when Matlab commands are called in a chain.

bastibe commented 7 years ago

Thank you for these suggestions! They are greatly appreciated!

in transplant_remote.m calling nargout(msg('name')) instead of nargout(fun) solves the problem with class methods in some case, so I added this little extension to transplant_remote.m, maybe you like it:

Very cool! If I'm not mistaken, this could be implemented a bit simpler: 08478bbe8ab42777ff0cc7b893cda29ab6f05212 Can you check if this works as intended?

python keyword arguments could be automatically translated to matlab string value pairs, such as mlab.myfun(option1=value1) would be called in Matlab myfun(option1,value1). You might not like it though due to ambiguity.

Sure, why not. This should be easy to implement, and I can't see any downside to it. I have an implementation in 2d68de51c79c9c46602ab0ec17ff4e44a534105c, which seems to work on my test cases. Does it work for yours as well?

in Matlab the usage of the struct data type is far more common than the usage of the containers.Map so it would be nice to make it a bit easyer to work with structures. For example using the MatlabStruct class in python should be applied recursively to all nested structures. Again it might be again an ambiguity problem.

This is a harder problem. The main issue is that Python dicts can use arbitrary keys, and Matlab structs can not. This is why I opted for Maps instead of structs. Now that I think about it, Python dicts support all kinds of things as keys, and not just strings, which still blows up Matlab, so maybe the current solution is not a good one, either.

Do you have an opinion on how to solve this problem better?

calling a chain of functions on large matrices or other objects makes transferring large amount of data multiple times between python and matlab, e.g. [...]

This is a very cool idea! The network delay is unavoidable, and in fact I am quite proud of Transplant's performance. Still, your solution would simplify many use cases. I have opened a new issue for this in #48, let's continue the discussion there.

tsdev commented 7 years ago

Thanks for going through my ideas. I checked 2d68de5 it works as intended, while I opened a new issue to discuss 08478bb.