Ticket #13199: trac_13199-flint_partition-review-ts.patch

File trac_13199-flint_partition-review-ts.patch, 7.0 KB (added by tscrim, 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 = [ 
    635635    Extension('sage.libs.flint.arith',
    636636              sources = ["sage/libs/flint/arith.pyx"],
    637637              libraries = ["csage", "flint", "gmp", "gmpxx", "m", "stdc++"],
    638               include_dirs = [SAGE_INC + 'flint/'],
    639638              extra_compile_args = ["-std=c99", "-D_XPG6"],
    640639              depends = flint_depends),
    641640   
  • sage/combinat/partition.py

    diff --git a/sage/combinat/partition.py b/sage/combinat/partition.py
    a b class Partitions_n(Partitions): 
    45224522
    45234523        INPUT:
    45244524
    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)
    45294529          - ``'gap'`` -- use GAP (VERY *slow*)
    45304530          - ``'pari'`` -- use PARI. Speed seems the same as GAP until
    45314531            `n` is in the thousands, in which case PARI is faster.
    class Partitions_n(Partitions): 
    45924592
    45934593        - :wikipedia:`Partition\_(number\_theory)`
    45944594        """
    4595         if algorithm == 'bober':
     4595        if algorithm == 'flint':
    45964596            return cached_number_of_partitions(self.n)
    45974597
    4598         elif algorithm == 'flint':
    4599             return flint_number_of_partitions(self.n)
     4598        elif algorithm == 'bober':
     4599            return bober_number_of_partitions(self.n)
    46004600
    46014601        elif algorithm == 'gap':
    46024602            return ZZ(gap.eval("NrPartitions(%s)" % (ZZ(self.n))))
    def number_of_partitions(n, k=None, algo 
    59445944    The options of :meth:`number_of_partitions()` are being deprecated
    59455945    :trac:`13072` in favour of :meth:`Partitions_n.cardinality()` so that
    59465946    :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).
    59495948
    59505949    INPUT:
    59515950
    def number_of_partitions(n, k=None, algo 
    59605959       [Will be deprecated except in Partition().cardinality() ]
    59615960
    59625961       -  ``'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
    59655965
    59665966       -  ``'bober'`` -- use Jonathan Bober's implementation
    59675967
    def number_of_partitions(n, k=None, algo 
    61036103    if k is not None:
    61046104        raise ValueError("only the GAP algorithm works if k is specified.")
    61056105
    6106     if algorithm == 'bober':
     6106    if algorithm == 'flint':
    61076107        return cached_number_of_partitions(n)
    61086108
    6109     elif algorithm == 'flint':
    6110         return flint_number_of_partitions(n)
     6109    elif algorithm == 'bober':
     6110        return bober_number_of_partitions(n)
    61116111
    61126112    elif algorithm == 'pari':
    61136113        deprecation(13072,"sage.combinat.number_of_partitions is deprecated. Use  Partitions().cardinality(algorithm='pari')")
    def number_of_partitions(n, k=None, algo 
    61296129from sage.misc.superseded import deprecated_function_alias
    61306130_numpart = deprecated_function_alias(13072, sage.combinat.partitions.number_of_partitions)
    61316131
    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.
    61356134# AM :trac:`13072`
    6136 cached_number_of_partitions = cached_function( bober_number_of_partitions )
     6135cached_number_of_partitions = cached_function( flint_number_of_partitions )
    61376136
    61386137def cyclic_permutations_of_partition(partition):
    61396138    """
  • sage/libs/flint/arith.pyx

    diff --git a/sage/libs/flint/arith.pyx b/sage/libs/flint/arith.pyx
    a b  
     1"""
     2FLINT 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
    111include "../../ext/interrupt.pxi"
    212include "fmpz.pxi"
    313
    from sage.rings.integer cimport Integer 
    919
    1020def number_of_partitions(unsigned long n):
    1121    """
    12     Returns the number of partitions of the integer n.
     22    Returns the number of partitions of the integer ``n``.
    1323
    1424    EXAMPLES::
    1525
    1626        sage: from sage.libs.flint.arith import number_of_partitions
     27        sage: number_of_partitions(3)
     28        3
    1729        sage: number_of_partitions(10)
    1830        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
    1967    """
    2068    cdef fmpz_t ans_fmpz
    2169    cdef Integer ans