#6720: make it easy to use sage from matlab
-------------------------+--------------------------------------------------
Reporter: was | Owner: was
Type: enhancement | Status: new
Priority: major | Milestone: sage-wishlist
Component: interfaces | Keywords:
Reviewer: | Author:
Merged: |
-------------------------+--------------------------------------------------
Old description:
> From Josh Kantor
> {{{
> It was easier to work on a matlab python bridge just writing pure python
> C/api code. I have a file matpy.c in my home directory on sage.math.
> On sage.math if you start matlab and do
>
> >> mex -g -I/usr/local/sage/local/include/python2.5 matpy.c
> /usr/lib/libpython2.5.so.1
>
> Then you can do
>
> >> matpy(pythonfilename, pythonfunc, v1,v2,...,vn)
>
> The function pythonfunc in pythonfilename will be called with arguments
> v1,v2,..,v_n which are matlab matrices or vectors, converted to python
> lists of lists.
>
> Before starting matlab you may need to do
>
> export PYTHONPATH= <current directory path>
>
> to make sure it sees files in the current directory.
>
> Currently it doesn't process return values and of course its just a
> prototype.
>
> Josh Kantor
> }}}
>
> Including at an example or something based on the above could be very
> useful for some people.
New description:
From Josh Kantor
{{{
It was easier to work on a matlab python bridge just writing pure python
C/api code. I have a file matpy.c in my home directory on sage.math.
On sage.math if you start matlab and do
>> mex -v -I/usr/local/sage/local/include/python2.5 matpy.c
/usr/lib/libpython2.5.so.1
Then you can do
>> matpy(pythonfilename, pythonfunc, v1,v2,...,vn)
The function pythonfunc in pythonfilename will be called with arguments
v1,v2,..,v_n which are matlab matrices or vectors, converted to python
lists of lists.
Before starting matlab you may need to do
export PYTHONPATH= <current directory path>
to make sure it sees files in the current directory.
Currently it doesn't process return values and of course its just a
prototype.
Josh Kantor
}}}
Including at an example or something based on the above could be very
useful for some people.
--
Comment(by jkantor):
For a toy example of how to use this, consider a file test.py containing
{{{
def random_func(l):
f=open("log.out",'w')
f.write(str(l))
return l
}}}
At your shell execute
{{{
$export PYTHONPATH=<path to current directory>
}}}
Then start matlab, then run (I am assuming you have put matpy.c in your
current directory also)
{{{
>> mex -v -I/usr/local/sage/local/include/python2.5 matpy.c
/usr/lib/libpython2.5.so.1
}}}
You should get two warnings and no errors.
The first time you do this you may need to do
{{{
>> mex -setup
}}}
and choose the option that uses gcc.
Create some matrix and call random_func with it.
{{{
>> m=[1 2 3; 4 5 6; 7 8 9];
>> matpy('test','random_func',m)
}}}
Now random_func should have written the string representation of m as a
list of lists to log.out (transposed because matlab stores in fortran
order).
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/6720#comment:2>
Sage <http://sagemath.org/>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---