Ask Your Question
0

How to define a smart class using cython?

asked 14 years ago

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

Preview: (hide)

Comments

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

Mitesh Patel gravatar imageMitesh Patel ( 14 years ago )

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 ( 10 years ago )

1 Answer

Sort by » oldest newest most voted
0

answered 9 years ago

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.

Preview: (hide)
link

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: 14 years ago

Seen: 754 times

Last updated: May 14 '15