Ask Your Question
0

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

asked 2012-08-16 06:10:07 +0200

blurrpp gravatar image

updated 2012-08-16 11:56:55 +0200

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;
}

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

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2012-08-21 18:35:16 +0200

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
0

answered 2012-08-23 11:09:14 +0200

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
0

answered 2012-08-16 18:09:46 +0200

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

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2012-08-16 06:10:07 +0200

Seen: 516 times

Last updated: Aug 23 '12