ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 23 Aug 2012 04:09:14 -0500more complicated data types to/from sage from/to C functionshttp://ask.sagemath.org/question/9242/more-complicated-data-types-tofrom-sage-fromto-c-functions/Hi.
Its easy to pass simple format data like double, int between sage and C programs.
int add_one(int i)
{
return i+1;
}
than
cdef extern from "file":
int add_one(int n)
but what if i want to pass list, tuples etc ( simple int * doesnt work ;) )
Does anybody know how to do that, or if thher is samoe manual (in this what i found are only simple examples )
Thank You in advance
Luke
Wed, 15 Aug 2012 23:10:07 -0500http://ask.sagemath.org/question/9242/more-complicated-data-types-tofrom-sage-fromto-c-functions/Answer by Volker Braun for <p>Hi.
Its easy to pass simple format data like double, int between sage and C programs.</p>
<pre><code>int add_one(int i)
{
return i+1;
}
</code></pre>
<p>than</p>
<pre><code>cdef extern from "file":
int add_one(int n)
</code></pre>
<p>but what if i want to pass list, tuples etc ( simple int * doesnt work ;) )
Does anybody know how to do that, or if thher is samoe manual (in this what i found are only simple examples )
Thank You in advance
Luke</p>
http://ask.sagemath.org/question/9242/more-complicated-data-types-tofrom-sage-fromto-c-functions/?answer=13934#post-id-13934For homogeneous arrays I would use STL vectors. There is an example for how to access STL vectors from Cython shipped with Sage, see `sage/tests/stl_vector.pyx`.
For more complicated data structures mixing all kinds of types just encapsulate it into a Cython class. Thu, 16 Aug 2012 11:09:46 -0500http://ask.sagemath.org/question/9242/more-complicated-data-types-tofrom-sage-fromto-c-functions/?answer=13934#post-id-13934Answer by Volker Braun for <p>Hi.
Its easy to pass simple format data like double, int between sage and C programs.</p>
<pre><code>int add_one(int i)
{
return i+1;
}
</code></pre>
<p>than</p>
<pre><code>cdef extern from "file":
int add_one(int n)
</code></pre>
<p>but what if i want to pass list, tuples etc ( simple int * doesnt work ;) )
Does anybody know how to do that, or if thher is samoe manual (in this what i found are only simple examples )
Thank You in advance
Luke</p>
http://ask.sagemath.org/question/9242/more-complicated-data-types-tofrom-sage-fromto-c-functions/?answer=13956#post-id-13956The Sage library contains many C++ library interfaces, for example `sage/libs/ppl.pyx`. Basically, write your C++ class and a Cython class that holds an instance of the C++ class as `thisptr`. Then add Cython wrappers for the C++ methods. Now you have a C++ class that can be accessed from the Python command line...Thu, 23 Aug 2012 04:09:14 -0500http://ask.sagemath.org/question/9242/more-complicated-data-types-tofrom-sage-fromto-c-functions/?answer=13956#post-id-13956Answer by blurrpp for <p>Hi.
Its easy to pass simple format data like double, int between sage and C programs.</p>
<pre><code>int add_one(int i)
{
return i+1;
}
</code></pre>
<p>than</p>
<pre><code>cdef extern from "file":
int add_one(int n)
</code></pre>
<p>but what if i want to pass list, tuples etc ( simple int * doesnt work ;) )
Does anybody know how to do that, or if thher is samoe manual (in this what i found are only simple examples )
Thank You in advance
Luke</p>
http://ask.sagemath.org/question/9242/more-complicated-data-types-tofrom-sage-fromto-c-functions/?answer=13954#post-id-13954hi, thank you. Do you have some examples of using more complicated datas in c/cpp programs with sage ?(and how to say sage to compile programs like cpp no c using " attach "foo.pyx" " )Tue, 21 Aug 2012 11:35:16 -0500http://ask.sagemath.org/question/9242/more-complicated-data-types-tofrom-sage-fromto-c-functions/?answer=13954#post-id-13954