ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 03 Aug 2012 12:03:25 +0200Math structures convertershttps://ask.sagemath.org/question/9169/math-structures-converters/Hi all,
I am a newbie here, and I am doing some experiments with SAGE. I am trying to tie up a kind of computing framework that could import data from some kind of sources, invoke generic algorhitms, and render output data.
SAGE and SAGENB are great works, thanks for developing them!
I see that SAGE can operate on many backends, but I can't figure out if it can convert data from one backend to another.
More explanation:
I have to take care mainly of Matlab syntax in this stage, but I'd like to save data in Python or a Scipy structure after import, and then perform conversion of data basing on the computing or rendering algorithm the user choose. Is it feasible with any library you developed or you know?
The "b plan" could be to use the Octave syntax which is 100% compatible. Am I right?
Respect to this question there are also performance,data size grow issues and maybe other to consider.
I hope this is the right place to post this question.
Thank you in advance
LucaSun, 22 Jul 2012 04:51:01 +0200https://ask.sagemath.org/question/9169/math-structures-converters/Comment by kcrisman for <p>Hi all,</p>
<p>I am a newbie here, and I am doing some experiments with SAGE. I am trying to tie up a kind of computing framework that could import data from some kind of sources, invoke generic algorhitms, and render output data.</p>
<p>SAGE and SAGENB are great works, thanks for developing them!</p>
<p>I see that SAGE can operate on many backends, but I can't figure out if it can convert data from one backend to another.</p>
<p>More explanation:</p>
<p>I have to take care mainly of Matlab syntax in this stage, but I'd like to save data in Python or a Scipy structure after import, and then perform conversion of data basing on the computing or rendering algorithm the user choose. Is it feasible with any library you developed or you know?</p>
<p>The "b plan" could be to use the Octave syntax which is 100% compatible. Am I right?</p>
<p>Respect to this question there are also performance,data size grow issues and maybe other to consider.</p>
<p>I hope this is the right place to post this question.</p>
<p>Thank you in advance
Luca</p>
https://ask.sagemath.org/question/9169/math-structures-converters/?comment=19364#post-id-19364This question is pretty vague and/or all-encompassing. Can you give a more explicit workflow of how you want to take data/algorithms around? You can save anything in Sage as Python, but certainly not all Matlab syntax would be "translatable" without human intervention into Sage; a lot of Sage stuff would translate back into Matlab, but probably not all of that, either (again, without human intervention).Mon, 23 Jul 2012 10:59:12 +0200https://ask.sagemath.org/question/9169/math-structures-converters/?comment=19364#post-id-19364Comment by fero for <p>Hi all,</p>
<p>I am a newbie here, and I am doing some experiments with SAGE. I am trying to tie up a kind of computing framework that could import data from some kind of sources, invoke generic algorhitms, and render output data.</p>
<p>SAGE and SAGENB are great works, thanks for developing them!</p>
<p>I see that SAGE can operate on many backends, but I can't figure out if it can convert data from one backend to another.</p>
<p>More explanation:</p>
<p>I have to take care mainly of Matlab syntax in this stage, but I'd like to save data in Python or a Scipy structure after import, and then perform conversion of data basing on the computing or rendering algorithm the user choose. Is it feasible with any library you developed or you know?</p>
<p>The "b plan" could be to use the Octave syntax which is 100% compatible. Am I right?</p>
<p>Respect to this question there are also performance,data size grow issues and maybe other to consider.</p>
<p>I hope this is the right place to post this question.</p>
<p>Thank you in advance
Luca</p>
https://ask.sagemath.org/question/9169/math-structures-converters/?comment=19350#post-id-19350let's say a simple example like: a = [ 1.1, 2.000002 ; 3, 4] , is there a way to say: sage_to_matlab(a) ? Of course I have already done this by hand with the help of str(), and " ".join() but what about number precision? and what about if I have a structure? like the one presented in Matlab "help save": s1.a = 12.7; s1.b = {'abc', [4 5; 6 7]}; s1.c = 'Hello!'; ? TIAWed, 25 Jul 2012 09:09:25 +0200https://ask.sagemath.org/question/9169/math-structures-converters/?comment=19350#post-id-19350Answer by fero for <p>Hi all,</p>
<p>I am a newbie here, and I am doing some experiments with SAGE. I am trying to tie up a kind of computing framework that could import data from some kind of sources, invoke generic algorhitms, and render output data.</p>
<p>SAGE and SAGENB are great works, thanks for developing them!</p>
<p>I see that SAGE can operate on many backends, but I can't figure out if it can convert data from one backend to another.</p>
<p>More explanation:</p>
<p>I have to take care mainly of Matlab syntax in this stage, but I'd like to save data in Python or a Scipy structure after import, and then perform conversion of data basing on the computing or rendering algorithm the user choose. Is it feasible with any library you developed or you know?</p>
<p>The "b plan" could be to use the Octave syntax which is 100% compatible. Am I right?</p>
<p>Respect to this question there are also performance,data size grow issues and maybe other to consider.</p>
<p>I hope this is the right place to post this question.</p>
<p>Thank you in advance
Luca</p>
https://ask.sagemath.org/question/9169/math-structures-converters/?answer=13891#post-id-13891thx to logix in the irc channel I found a workaround to complete the circle, saved a struct to 'test.mat' file and then reload through scipy:
import scipy.io
mat = scipy.io.loadmat('test.mat')
print mat['test_struct']
M =matrix(mat['test_struct'])
matlab("%s'" %
matlab.sage2matlab_matrix_string(M))Fri, 03 Aug 2012 12:03:25 +0200https://ask.sagemath.org/question/9169/math-structures-converters/?answer=13891#post-id-13891Answer by kcrisman for <p>Hi all,</p>
<p>I am a newbie here, and I am doing some experiments with SAGE. I am trying to tie up a kind of computing framework that could import data from some kind of sources, invoke generic algorhitms, and render output data.</p>
<p>SAGE and SAGENB are great works, thanks for developing them!</p>
<p>I see that SAGE can operate on many backends, but I can't figure out if it can convert data from one backend to another.</p>
<p>More explanation:</p>
<p>I have to take care mainly of Matlab syntax in this stage, but I'd like to save data in Python or a Scipy structure after import, and then perform conversion of data basing on the computing or rendering algorithm the user choose. Is it feasible with any library you developed or you know?</p>
<p>The "b plan" could be to use the Octave syntax which is 100% compatible. Am I right?</p>
<p>Respect to this question there are also performance,data size grow issues and maybe other to consider.</p>
<p>I hope this is the right place to post this question.</p>
<p>Thank you in advance
Luca</p>
https://ask.sagemath.org/question/9169/math-structures-converters/?answer=13851#post-id-13851If you look at [the source for the Matlab interface](http://hg.sagemath.org/sage-main/file/9ab4ab6e12d0/sage/interfaces/matlab.py#l1), you can see that it's still pretty rudimentary. In particular,
sage: M = matrix([[1.1,2.0000002],[3,4]])
sage: M._ma<tab>
doesn't reveal anything to convert it to a Matlab format. It turns out you **can** do
sage: matlab.sage2matlab_matrix_string(M)
'[1.10000000000000, 2.00000020000000; 3.00000000000000, 4.00000000000000]'
but I don't know if that's what you want.
It looks like this interface could use a lot of work. Perhaps you might contribute? Also, if you really just need an open source alternative, Octave is very good. Interestingly, there *is*
sage: M._octave_()
though of course one needs Octave installed and in the PATH to use it.
----------
On a tangential note, I've opened [Ticket 13291](http://trac.sagemath.org/sage_trac/ticket/13291) to do some minor improvement to our internal testing stuff that I found while looking at this.Wed, 25 Jul 2012 13:10:58 +0200https://ask.sagemath.org/question/9169/math-structures-converters/?answer=13851#post-id-13851Comment by fero for <p>If you look at <a href="http://hg.sagemath.org/sage-main/file/9ab4ab6e12d0/sage/interfaces/matlab.py#l1">the source for the Matlab interface</a>, you can see that it's still pretty rudimentary. In particular, </p>
<pre><code>sage: M = matrix([[1.1,2.0000002],[3,4]])
sage: M._ma<tab>
</code></pre>
<p>doesn't reveal anything to convert it to a Matlab format. It turns out you <strong>can</strong> do </p>
<pre><code>sage: matlab.sage2matlab_matrix_string(M)
'[1.10000000000000, 2.00000020000000; 3.00000000000000, 4.00000000000000]'
</code></pre>
<p>but I don't know if that's what you want.</p>
<p>It looks like this interface could use a lot of work. Perhaps you might contribute? Also, if you really just need an open source alternative, Octave is very good. Interestingly, there <em>is</em></p>
<pre><code>sage: M._octave_()
</code></pre>
<p>though of course one needs Octave installed and in the PATH to use it.</p>
<hr/>
<p>On a tangential note, I've opened <a href="http://trac.sagemath.org/sage_trac/ticket/13291">Ticket 13291</a> to do some minor improvement to our internal testing stuff that I found while looking at this.</p>
https://ask.sagemath.org/question/9169/math-structures-converters/?comment=19285#post-id-19285thx to logix in the irc channel I found a workaround to do this: import scipy.io
mat = scipy.io.loadmat('/tmp/test.mat')
print mat['test_struct']
M =matrix(mat['test_struct'])
matlab("%s'" % matlab.sage2matlab_matrix_string(M))Fri, 03 Aug 2012 12:00:35 +0200https://ask.sagemath.org/question/9169/math-structures-converters/?comment=19285#post-id-19285Comment by fero for <p>If you look at <a href="http://hg.sagemath.org/sage-main/file/9ab4ab6e12d0/sage/interfaces/matlab.py#l1">the source for the Matlab interface</a>, you can see that it's still pretty rudimentary. In particular, </p>
<pre><code>sage: M = matrix([[1.1,2.0000002],[3,4]])
sage: M._ma<tab>
</code></pre>
<p>doesn't reveal anything to convert it to a Matlab format. It turns out you <strong>can</strong> do </p>
<pre><code>sage: matlab.sage2matlab_matrix_string(M)
'[1.10000000000000, 2.00000020000000; 3.00000000000000, 4.00000000000000]'
</code></pre>
<p>but I don't know if that's what you want.</p>
<p>It looks like this interface could use a lot of work. Perhaps you might contribute? Also, if you really just need an open source alternative, Octave is very good. Interestingly, there <em>is</em></p>
<pre><code>sage: M._octave_()
</code></pre>
<p>though of course one needs Octave installed and in the PATH to use it.</p>
<hr/>
<p>On a tangential note, I've opened <a href="http://trac.sagemath.org/sage_trac/ticket/13291">Ticket 13291</a> to do some minor improvement to our internal testing stuff that I found while looking at this.</p>
https://ask.sagemath.org/question/9169/math-structures-converters/?comment=19289#post-id-19289it is wonderful thank you. The thing that I still do not understand is how to revert the result to sage. In example I have a "data" variable in a data.mat file and I can do: matlab.eval("load('/tmp/data.mat')") ; x = matlab("data") ; but then I can't convert it to sage variable. I wrote x.sage(), but I get a "NotImplementedError: Unable to parse output: ??? Undefined function or variable 'sage10'"Fri, 03 Aug 2012 03:23:09 +0200https://ask.sagemath.org/question/9169/math-structures-converters/?comment=19289#post-id-19289