コード例 #1
0
ファイル: testTwoTerms.py プロジェクト: unhyperbolic/SnapRepr
from csvUtilities.readCensusTable import readCensusTable
import globalsettings
import mpmath
from linearCombinations import binarySearch, filterRepresentativeMfds, twoTerms
from linearCombinations.formatLinearCombination import formatLinearCombination

mpmath.mp.dps = 70
globalsettings.setSetting("maximalError", mpmath.mpf("0.1") ** 50)
globalsettings.setSetting("maximalErrorDigits", 50)

testCensusTablePath = globalsettings.getSetting("testCensusTablePath")
censusTableFile = testCensusTablePath + "/exampleCensusTable.csv"
censusTable = readCensusTable(censusTableFile, sortKey="Volume")

representatives = filterRepresentativeMfds.filterRepresentativeMfds(censusTable.listOfDicts)


def checkBinarySearchResult(vol, resultNames):

    if isinstance(vol, str):
        vol = mpmath.mpf(vol)

    rows = binarySearch.matchingRows(censusTable.listOfDicts, "Volume", vol)
    names = [row["Name"] for row in rows]

    assert set(resultNames) == set(names), Exception("Expected: %s\nGot %s" % (resultNames, names))


def testBinarySearch():

    checkBinarySearchResult(
コード例 #2
0
    import algebra.polynomial
    import algebra.magma
    import globalsettings
    import utilities.basicAlgorithms
    import algebra.mpmathFunctions
except ImportError as e:
    print e
    print
    print "This program was called as       :", sys.argv[0]
    print "Absolute path to this program is :", abs_path
    print "Base path is                     :", base_path
    sys.exit(1)

testPath = base_path + "/tests"
testTriangulationsPath = testPath + "/triangulations"
testCensusTablePath = testPath + "/CensusTable"

globalsettings.setSetting("testPath", testPath)
globalsettings.setSetting("testTriangulationsPath", testTriangulationsPath)
globalsettings.setSetting("testCensusTablePath", testCensusTablePath)

doctest.testmod(manifold.triangulation)
doctest.testmod(manifold.slN)
doctest.testmod(algebra.polynomial)
doctest.testmod(algebra.magma)
doctest.testmod(utilities.basicAlgorithms)
doctest.testmod(algebra.mpmathFunctions)

import linearCombinations.testTwoTerms
linearCombinations.testTwoTerms.testAll()
コード例 #3
0
def main():
    parser = create_parser()
    # Parse command line options
    options, args = parser.parse_args()

    globalsettings.setSetting("maximalError",
                              mpmath.mpf("0.1") ** options.maximalError)
    globalsettings.setSetting("maximalErrorDigits",
                              options.maximalError)

    mpmath.mp.dps = options.maximalError + options.extraDigits
    pari.set_pari_precision(options.maximalError + options.extraDigits)

    # Exit writing the header for the CSV file
    if options.print_csv_header:
        output = StringIO.StringIO()
        csv_writer = csv.DictWriter(output, fieldnames = readCensusTable.header)
        csv_writer.writerow(dict(zip(readCensusTable.header,
                                     readCensusTable.header)))
        print output.getvalue()[:-1]
        sys.exit(0)

    # Exit with usage information
    if not len(args)==1:
        parser.print_help()
        sys.exit(1)

    # Read input file
    input_file = open(args[0], 'r').read()
    first_line = ''.join(input_file.split('\n')[0:1])

    # Branch depending on whether input file is a triangulation

    if "% triangulation" in first_line.lower():
        # Triangulation
        write_magma_files(options, triangulation_filename = args[0])

    elif "MAGMA=INPUT=FROM=SNAPREPR" in input_file:

        print "This file is supposed to be processed with MAGMA"
        print "Run:"
        print "      magma_out %s" % args[0]
        print "Then:"
        print "      slN_representations.py %s_out" % args[0]

    elif "MAGMA=OUTPUT=FOR=SNAPREPR" in input_file:
        # magma breaks long lines putting a \ at the break
        # we replace those line breaks
        magma_out = ''.join([x.strip() for x in input_file.split('\\\n')])

        if True or "MAGMA=OUTPUT=STAGE2=FOR=SNAPREPR" in input_file:

            process_magma_output_headers_stage2(options, magma_out, 
                                                magma_filename = args[0])
            
        else:
            process_magma_output_headers(options, magma_out,
                                         magma_filename = args[0])
    else:

        sys.stderr.write("Could not recognize a SnapPea triangulation file or a MAGMA output file ????\n\n")
        
        # XXX:needs to be fixed!

        print '"-","%s","-","-","-","-","-","-","-","-","-","-","-","FILE NOT RECOGNIZED","-","-","-"' % args[0]