Ask Your Question
0

How to define a smart class using cython?

asked 2010-11-02 02:08:45 +0100

roland gravatar image

Hi, I managed to rewrite my problem so I only have to represent numbers in the following way: [(2,3),(3,3),(13,1)] like in list(factor(82713)). Thus [(prime,exponent), (prime,exponent), ...].

With such a representation multiplying is easy, and I can skip to factor numbers (again). What I'm looking for is a fast cython approach with a class where I can define a function for multiplying, but also where I'm able to store and retrieve a large set of numbers efficiently (within the program). I looked for examples in the Cython Tutorial et cetera, but I could not find an approach which helped me. Maybe someone is willing and able to share his/her expertise? Thanks in advance! Roland

edit retag flag offensive close merge delete

Comments

Could you give some more information, e.g., examples, about your problem and what your class should do?

Mitesh Patel gravatar imageMitesh Patel ( 2010-11-03 05:58:16 +0100 )edit

It is always better to start with a Python class. Once you are sure about your data structure you can switch to cython and this is easy. Once you are in cython it becomes much harder to rewrite your class.

vdelecroix gravatar imagevdelecroix ( 2014-06-29 16:58:09 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-05-14 08:29:52 +0100

nbruin gravatar image

I think this class is already implemented in sage:

sage: a,b
(2 * 3, 3 * 5)
sage: a*b
2 * 3^2 * 5
sage: a=factor(6); a
2 * 3
sage: b=factor(15); b
3 * 5
sage: a*b
2 * 3^2 * 5
sage: type(a*b)
<class 'sage.structure.factorization.Factorization'>
sage: type(a)
<class 'sage.structure.factorization_integer.IntegerFactorization'>

A good start would be to compare your code with what is implemented in sage already. It might give some hints.

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

1 follower

Stats

Asked: 2010-11-02 02:08:45 +0100

Seen: 728 times

Last updated: May 14 '15