[sage-support] Re: performance of applying a map to an integer vector

2013-11-20 Thread Nils Bruin
On Wednesday, November 20, 2013 11:13:32 AM UTC-8, Felix Breuer wrote: > > I don't think NumPy will help, as NumPy works with machine precision > throughout, as far as I was able to figure out. > I think you can put arbitrary fixed length types in there, which would include multiprecision intege

[sage-support] Re: performance of applying a map to an integer vector

2013-11-20 Thread Felix Breuer
Hi Nils, excellent point! Adding a special case for gcd = 1 help a *lot* on many instances. I'll definitely take the plunge and convert the code to lists or tuples instead of vectors. (The convenience of writing things like "alpha * v + w" is certainly not worth the performance penalty.) I do

[sage-support] Re: performance of applying a map to an integer vector

2013-11-20 Thread Felix Breuer
Hi Maarten, a couple of other questions regarding Cython, based on the blog post you linked: * Why are MPIR integer operations slower (according to the post) than Python's own big integer operations? What additional functionality does MPIR provide that incurs this performance penalty? * Most

[sage-support] Re: performance of applying a map to an integer vector

2013-11-20 Thread Nils Bruin
On Wednesday, November 20, 2013 10:54:29 AM UTC-8, Nils Bruin wrote: > return [c div g for c in v] > Sorry, that's spelled [c // g for c in v] Incidentally, a typical vector of 20 integers has gcd 1 for its coefficients. If that happens a lot in your data, you should shortcut on gcd==1 t

[sage-support] Re: performance of applying a map to an integer vector

2013-11-20 Thread Nils Bruin
On Wednesday, November 20, 2013 2:02:59 AM UTC-8, Felix Breuer wrote: > > Hi all! > > I have a large collection (~50,000) of integer vectors in low dimension > (~20). For each of these vectors, I want to divide all entries by their > gcd. In other words if > > def prim_v(v): > d = abs(gcd(v))

[sage-support] Re: performance of applying a map to an integer vector

2013-11-20 Thread Felix Breuer
Hi Simon, hi Maarten, thank you for your answers! @Simon: Yes, I figured that calling vector(...) would impose these kinds of overhead. This is why I am using apply_map in the code, in the hope of saving some of this work. Thanks to your suggestion, I tried specifying the base ring in the c

[sage-support] Re: performance of applying a map to an integer vector

2013-11-20 Thread Maarten Derickx
It seems like your code is mostly doing easy integer operations in tight for loops (although in your case the for loop is hidden in v.apply_map). If you care about performance in such cases, then you should not use python, but cython. Because everything you do in python has a small overhead, and

[sage-support] Re: performance of applying a map to an integer vector

2013-11-20 Thread Simon King
Hi Felix, On 2013-11-20, Felix Breuer wrote: > If I am reading this correctly, this means that most of the time (~10 > seconds) is not spent doing the actual computation (using foo and bar) but > simply creating vectors and read/writing values to/from vectors (in > apply_map). (Do something li

[sage-support] performance of applying a map to an integer vector

2013-11-20 Thread Felix Breuer
Hi all! I have a large collection (~50,000) of integer vectors in low dimension (~20). For each of these vectors, I want to divide all entries by their gcd. In other words if def prim_v(v): d = abs(gcd(v)) return v.apply_map(lambda vi: vi.divide_knowing_divisible_by(d)) then I want to