ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 14 May 2015 08:29:52 +0200How to define a smart class using cython?https://ask.sagemath.org/question/7749/how-to-define-a-smart-class-using-cython/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(8*27*13)). 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
Tue, 02 Nov 2010 02:08:45 +0100https://ask.sagemath.org/question/7749/how-to-define-a-smart-class-using-cython/Comment by vdelecroix for <p>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(8<em>27</em>13)). Thus [(prime,exponent), (prime,exponent), ...].</p>
<p>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</p>
https://ask.sagemath.org/question/7749/how-to-define-a-smart-class-using-cython/?comment=23122#post-id-23122It 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.Sun, 29 Jun 2014 16:58:09 +0200https://ask.sagemath.org/question/7749/how-to-define-a-smart-class-using-cython/?comment=23122#post-id-23122Comment by Mitesh Patel for <p>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(8<em>27</em>13)). Thus [(prime,exponent), (prime,exponent), ...].</p>
<p>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</p>
https://ask.sagemath.org/question/7749/how-to-define-a-smart-class-using-cython/?comment=22523#post-id-22523Could you give some more information, e.g., examples, about your problem and what your class should do?Wed, 03 Nov 2010 05:58:16 +0100https://ask.sagemath.org/question/7749/how-to-define-a-smart-class-using-cython/?comment=22523#post-id-22523Answer by nbruin for <p>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(8<em>27</em>13)). Thus [(prime,exponent), (prime,exponent), ...].</p>
<p>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</p>
https://ask.sagemath.org/question/7749/how-to-define-a-smart-class-using-cython/?answer=26824#post-id-26824I 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.
Thu, 14 May 2015 08:29:52 +0200https://ask.sagemath.org/question/7749/how-to-define-a-smart-class-using-cython/?answer=26824#post-id-26824