Ask Your Question

more complicated data types to/from sage from/to C functions

asked 2012-08-15 23:10:07 -0600

blurrpp gravatar image

updated 2012-08-16 04:56:55 -0600

benjaminfjones gravatar image

Hi. Its easy to pass simple format data like double, int between sage and C programs.

int add_one(int i)
   return i+1;


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

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted

answered 2012-08-16 11:09:46 -0600

Volker Braun gravatar image

For 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.

edit flag offensive delete link more

answered 2012-08-23 04:09:14 -0600

Volker Braun gravatar image

The 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...

edit flag offensive delete link more

answered 2012-08-21 11:35:16 -0600

blurrpp gravatar image

hi, 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" " )

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-08-15 23:10:07 -0600

Seen: 230 times

Last updated: Aug 23 '12