Ticket #13199: trac_13199-flint_partition-review-ts.patch
File trac_13199-flint_partition-review-ts.patch, 7.0 KB (added by , 9 years ago) |
---|
-
module_list.py
# HG changeset patch # User Travis Scrimshaw <tscrim@ucdavis.edu> # Date 1370869772 25200 # Node ID d486f2c76e67364a840b4d7f6edce3b0417a3b61 # Parent 7bfd4b54e0b6e0df6baf122e541b562195344ba9 #13199: review patch. diff --git a/module_list.py b/module_list.py
a b ext_modules = [ 635 635 Extension('sage.libs.flint.arith', 636 636 sources = ["sage/libs/flint/arith.pyx"], 637 637 libraries = ["csage", "flint", "gmp", "gmpxx", "m", "stdc++"], 638 include_dirs = [SAGE_INC + 'flint/'],639 638 extra_compile_args = ["-std=c99", "-D_XPG6"], 640 639 depends = flint_depends), 641 640 -
sage/combinat/partition.py
diff --git a/sage/combinat/partition.py b/sage/combinat/partition.py
a b class Partitions_n(Partitions): 4522 4522 4523 4523 INPUT: 4524 4524 4525 - ``algorithm`` - (default: ``' bober'``)4526 4527 - ``' bober'`` -- Use Jonathan Bober's implementation (*very* fast).4528 - ``' flint'`` -- use FLINT.4525 - ``algorithm`` - (default: ``'flint'``) 4526 4527 - ``'flint'`` -- use FLINT (currently the fastest) 4528 - ``'bober'`` -- Use Jonathan Bober's implementation (*very* fast) 4529 4529 - ``'gap'`` -- use GAP (VERY *slow*) 4530 4530 - ``'pari'`` -- use PARI. Speed seems the same as GAP until 4531 4531 `n` is in the thousands, in which case PARI is faster. … … class Partitions_n(Partitions): 4592 4592 4593 4593 - :wikipedia:`Partition\_(number\_theory)` 4594 4594 """ 4595 if algorithm == ' bober':4595 if algorithm == 'flint': 4596 4596 return cached_number_of_partitions(self.n) 4597 4597 4598 elif algorithm == ' flint':4599 return flint_number_of_partitions(self.n)4598 elif algorithm == 'bober': 4599 return bober_number_of_partitions(self.n) 4600 4600 4601 4601 elif algorithm == 'gap': 4602 4602 return ZZ(gap.eval("NrPartitions(%s)" % (ZZ(self.n)))) … … def number_of_partitions(n, k=None, algo 5944 5944 The options of :meth:`number_of_partitions()` are being deprecated 5945 5945 :trac:`13072` in favour of :meth:`Partitions_n.cardinality()` so that 5946 5946 :meth:`number_of_partitions()` can become a stripped down version of 5947 the fastest algorithm available (currently this is due to Bober, but an 5948 faster implementation using FLINT will soon be merged into sage). 5947 the fastest algorithm available (currently this is using FLINT). 5949 5948 5950 5949 INPUT: 5951 5950 … … def number_of_partitions(n, k=None, algo 5960 5959 [Will be deprecated except in Partition().cardinality() ] 5961 5960 5962 5961 - ``'default'`` -- If ``k`` is not ``None``, then use Gap (very slow). 5963 If ``k`` is ``None``, use Jonathan Bober's highly optimized 5964 implementation. 5962 If ``k`` is ``None``, use FLINT. 5963 5964 - ``'flint'`` -- use FLINT 5965 5965 5966 5966 - ``'bober'`` -- use Jonathan Bober's implementation 5967 5967 … … def number_of_partitions(n, k=None, algo 6103 6103 if k is not None: 6104 6104 raise ValueError("only the GAP algorithm works if k is specified.") 6105 6105 6106 if algorithm == ' bober':6106 if algorithm == 'flint': 6107 6107 return cached_number_of_partitions(n) 6108 6108 6109 elif algorithm == ' flint':6110 return flint_number_of_partitions(n)6109 elif algorithm == 'bober': 6110 return bober_number_of_partitions(n) 6111 6111 6112 6112 elif algorithm == 'pari': 6113 6113 deprecation(13072,"sage.combinat.number_of_partitions is deprecated. Use Partitions().cardinality(algorithm='pari')") … … def number_of_partitions(n, k=None, algo 6129 6129 from sage.misc.superseded import deprecated_function_alias 6130 6130 _numpart = deprecated_function_alias(13072, sage.combinat.partitions.number_of_partitions) 6131 6131 6132 # Rather than caching an under used function I have cached the default 6133 # number_of_partitions functions which is currently that implemented by Bober, 6134 # although this will soon need to be replaced by the FLINT implementation. 6132 # Rather than caching an under-used function I have cached the default 6133 # number_of_partitions functions which is currently using FLINT. 6135 6134 # AM :trac:`13072` 6136 cached_number_of_partitions = cached_function( bober_number_of_partitions )6135 cached_number_of_partitions = cached_function( flint_number_of_partitions ) 6137 6136 6138 6137 def cyclic_permutations_of_partition(partition): 6139 6138 """ -
sage/libs/flint/arith.pyx
diff --git a/sage/libs/flint/arith.pyx b/sage/libs/flint/arith.pyx
a b 1 """ 2 FLINT Arithmetic Functions 3 """ 4 ########################################################################### 5 # Copyright (C) 2013 Fredrik Johansson <fredrik.johansson@gmail.com> 6 # 7 # Distributed under the terms of the GNU General Public License (GPL) 8 # http://www.gnu.org/licenses/ 9 ########################################################################### 10 1 11 include "../../ext/interrupt.pxi" 2 12 include "fmpz.pxi" 3 13 … … from sage.rings.integer cimport Integer 9 19 10 20 def number_of_partitions(unsigned long n): 11 21 """ 12 Returns the number of partitions of the integer n.22 Returns the number of partitions of the integer ``n``. 13 23 14 24 EXAMPLES:: 15 25 16 26 sage: from sage.libs.flint.arith import number_of_partitions 27 sage: number_of_partitions(3) 28 3 17 29 sage: number_of_partitions(10) 18 30 42 31 sage: number_of_partitions(40) 32 37338 33 sage: number_of_partitions(100) 34 190569292 35 sage: number_of_partitions(100000) 36 27493510569775696512677516320986352688173429315980054758203125984302147328114964173055050741660736621590157844774296248940493063070200461792764493033510116079342457190155718943509725312466108452006369558934464248716828789832182345009262853831404597021307130674510624419227311238999702284408609370935531629697851569569892196108480158600569421098519 37 38 TESTS:: 39 40 sage: n = 500 + randint(0,500) 41 sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 42 True 43 sage: n = 1500 + randint(0,1500) 44 sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 45 True 46 sage: n = 1000000 + randint(0,1000000) 47 sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 48 True 49 sage: n = 1000000 + randint(0,1000000) 50 sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 51 True 52 sage: n = 1000000 + randint(0,1000000) 53 sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 54 True 55 sage: n = 1000000 + randint(0,1000000) 56 sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 57 True 58 sage: n = 1000000 + randint(0,1000000) 59 sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 60 True 61 sage: n = 1000000 + randint(0,1000000) 62 sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 63 True 64 sage: n = 100000000 + randint(0,100000000) 65 sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 # long time 66 True 19 67 """ 20 68 cdef fmpz_t ans_fmpz 21 69 cdef Integer ans