diff -Nru pytools-2011.3/debian/changelog pytools-2011.5/debian/changelog --- pytools-2011.3/debian/changelog 2011-05-05 18:26:25.000000000 +0000 +++ pytools-2011.5/debian/changelog 2011-11-25 13:35:28.000000000 +0000 @@ -1,3 +1,12 @@ +pytools (2011.5-1) unstable; urgency=low + + * New upstream version, adds workaround for Python bug + http://bugs.python.org/issue3905 + * Refresh patches to apply and unapply cleanly. + * Add debian/clean to remove generated files from pytools.egg-info/* + + -- Tomasz Rybak Fri, 25 Nov 2011 12:29:02 +0100 + pytools (2011.3-1) unstable; urgency=low * New upstream release diff -Nru pytools-2011.3/debian/clean pytools-2011.5/debian/clean --- pytools-2011.3/debian/clean 1970-01-01 00:00:00.000000000 +0000 +++ pytools-2011.5/debian/clean 2011-11-25 13:35:28.000000000 +0000 @@ -0,0 +1 @@ +pytools.egg-info/* diff -Nru pytools-2011.3/debian/control pytools-2011.5/debian/control --- pytools-2011.3/debian/control 2011-05-04 13:35:26.000000000 +0000 +++ pytools-2011.5/debian/control 2011-11-25 13:35:28.000000000 +0000 @@ -9,7 +9,7 @@ python-matplotlib, python-decorator Standards-Version: 3.9.2 -X-Python-Version: >= 2.6 +X-Python-Version: >= 2.5 Homepage: http://mathema.tician.de/software/pytools Vcs-Git: git://git.debian.org/git/collab-maint/python-pytools.git Vcs-Browser: http://git.debian.org/?p=collab-maint/python-pytools.git diff -Nru pytools-2011.3/debian/patches/remove-decorator.patch pytools-2011.5/debian/patches/remove-decorator.patch --- pytools-2011.3/debian/patches/remove-decorator.patch 2011-05-04 13:35:26.000000000 +0000 +++ pytools-2011.5/debian/patches/remove-decorator.patch 2011-11-25 13:35:28.000000000 +0000 @@ -4,33 +4,11 @@ and require unpackaged python modules. Forwarded: not-needed Author: Tomasz Rybak -Last-Update: 2011-04-28 -Index: pytools-2011.3/pytools.egg-info/SOURCES.txt +Last-Update: 2011-11-22 +Index: pytools-2011.5/pytools/__init__.py =================================================================== ---- pytools-2011.3.orig/pytools.egg-info/SOURCES.txt 2011-04-28 17:46:28.000000000 +0200 -+++ pytools-2011.3/pytools.egg-info/SOURCES.txt 2011-04-28 17:47:29.000000000 +0200 -@@ -1,6 +1,5 @@ - MANIFEST.in - README --distribute_setup.py - setup.py - pytools/__init__.py - pytools/arithmetic_container.py -@@ -8,10 +7,8 @@ - pytools/convergence.py - pytools/datatable.py - pytools/debug.py --pytools/decorator.py - pytools/diskdict.py - pytools/lex.py --pytools/log.py - pytools/mpi.py - pytools/mpiwrap.py - pytools/obj_array.py -Index: pytools-2011.3/pytools/__init__.py -=================================================================== ---- pytools-2011.3.orig/pytools/__init__.py 2011-04-28 17:48:07.000000000 +0200 -+++ pytools-2011.3/pytools/__init__.py 2011-04-28 17:48:24.000000000 +0200 +--- pytools-2011.5.orig/pytools/__init__.py 2011-10-02 18:45:54.000000000 +0200 ++++ pytools-2011.5/pytools/__init__.py 2011-11-22 17:51:49.000000000 +0100 @@ -4,7 +4,7 @@ import operator import types diff -Nru pytools-2011.3/debian/patches/replace-setuptools.patch pytools-2011.5/debian/patches/replace-setuptools.patch --- pytools-2011.3/debian/patches/replace-setuptools.patch 2011-05-04 13:35:26.000000000 +0000 +++ pytools-2011.5/debian/patches/replace-setuptools.patch 2011-11-25 13:35:28.000000000 +0000 @@ -1,12 +1,18 @@ Description: Disable downloading of distribute archive as python-setuptools - contains necessary files. + contains all necessary files. Forwarded: not-needed Author: Tomasz Rybak -Last-Update: 2011-04-28 -Index: pytools-2011.3/setup.py +Last-Update: 2011-11-25 +Index: pytools-2011.5/MANIFEST.in =================================================================== ---- pytools-2011.3.orig/setup.py 2011-04-28 17:50:29.000000000 +0200 -+++ pytools-2011.3/setup.py 2011-04-28 17:50:54.000000000 +0200 +--- pytools-2011.5.orig/MANIFEST.in 2009-10-15 20:13:17.000000000 +0200 ++++ /dev/null 1970-01-01 00:00:00.000000000 +0000 +@@ -1 +0,0 @@ +-include distribute_setup.py +Index: pytools-2011.5/setup.py +=================================================================== +--- pytools-2011.5.orig/setup.py 2011-11-18 10:55:31.000000000 +0100 ++++ pytools-2011.5/setup.py 2011-11-22 18:15:58.000000000 +0100 @@ -1,9 +1,6 @@ #!/usr/bin/env python # -*- coding: latin1 -*- @@ -17,9 +23,3 @@ from setuptools import setup try: -Index: pytools-2011.3/MANIFEST.in -=================================================================== ---- pytools-2011.3.orig/MANIFEST.in 2011-04-28 17:50:35.000000000 +0200 -+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 -@@ -1 +0,0 @@ --include distribute_setup.py diff -Nru pytools-2011.3/debian/README.Debian pytools-2011.5/debian/README.Debian --- pytools-2011.3/debian/README.Debian 2011-05-04 13:35:26.000000000 +0000 +++ pytools-2011.5/debian/README.Debian 2011-11-25 13:35:28.000000000 +0000 @@ -4,9 +4,6 @@ I removed following files from this package: * pytools/decorator.py (newer version in package python-decorator) * pytools/log.py (requires pymbolic) - * pytools/grid.py (requires pylinear) - * bin/logtool (conflicts with logtool package, requires pytools.log) - * bin/runalyzer-gather (requires pytools.log) PyCUDA requires following packages: * from __init__.py @@ -18,5 +15,13 @@ * pytools.prefork * pytools.diskdict +PyOpenCL requires following packages: + * from __init__.py + * memoize_method + * Record + * single_valued + * all + * any + If required modules are packaged I will enable removed files. diff -Nru pytools-2011.3/PKG-INFO pytools-2011.5/PKG-INFO --- pytools-2011.3/PKG-INFO 2011-04-05 15:48:21.000000000 +0000 +++ pytools-2011.5/PKG-INFO 2011-11-18 09:56:05.000000000 +0000 @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: pytools -Version: 2011.3 +Version: 2011.5 Summary: A collection of tools for Python Home-page: http://pypi.python.org/pypi/pytools Author: Andreas Kloeckner diff -Nru pytools-2011.3/pytools/__init__.py pytools-2011.5/pytools/__init__.py --- pytools-2011.3/pytools/__init__.py 2011-03-20 18:15:06.000000000 +0000 +++ pytools-2011.5/pytools/__init__.py 2011-10-02 16:45:54.000000000 +0000 @@ -637,7 +637,8 @@ result = {} for key, value in the_dict.iteritems(): if value in result: - raise RuntimeError, "non-reversible mapping" + raise RuntimeError( + "non-reversible mapping, duplicate key '%s'" % value) result[value] = key return result @@ -649,7 +650,7 @@ def div_ceil(nr, dr): - return (nr + dr -1) // dr + return -(-nr // dr) @@ -729,7 +730,7 @@ -def argmin2(iterable): +def argmin2(iterable, return_value=False): it = iter(iterable) try: current_argmin, current_min = it.next() @@ -740,12 +741,16 @@ if item < current_min: current_argmin = arg current_min = item - return current_argmin + + if return_value: + return current_argmin, current_min + else: + return current_argmin -def argmax2(iterable): +def argmax2(iterable, return_value=False): it = iter(iterable) try: current_argmax, current_max = it.next() @@ -756,7 +761,11 @@ if item > current_max: current_argmax = arg current_max = item - return current_argmax + + if return_value: + return current_argmax, current_max + else: + return current_argmax # }}} @@ -1066,6 +1075,68 @@ # }}} +# {{{ graph algorithms + +def a_star(initial_state, goal_state, neighbor_map, + estimate_remaining_cost=None, + get_step_cost=lambda x, y: 1): + """ + With the default cost and heuristic, this amounts to Dijkstra's algorithm. + """ + + from heapq import heappop, heappush + + if estimate_remaining_cost is None: + def estimate_remaining_cost(x): + if x != goal_state: + return 1 + else: + return 0 + + class AStarNode(object): + __slots__ = ["state", "parent", "path_cost"] + def __init__(self, state, parent, path_cost): + self.state = state + self.parent = parent + self.path_cost = path_cost + + inf = float("inf") + init_remcost = estimate_remaining_cost(initial_state) + assert init_remcost != inf + + queue = [(init_remcost, AStarNode(initial_state, parent=None, path_cost=0))] + visited_states = set() + + while len(queue): + _, top = heappop(queue) + visited_states.add(top.state) + + if top.state == goal_state: + result = [] + it = top + while it is not None: + result.append(it.state) + it = it.parent + return result[::-1] + + for state in neighbor_map[top.state]: + if state in visited_states: + continue + + remaining_cost = estimate_remaining_cost(state) + if remaining_cost == inf: + continue + step_cost = get_step_cost(top, state) + + estimated_path_cost = top.path_cost+step_cost+remaining_cost + heappush(queue, + (estimated_path_cost, + AStarNode(state, top, path_cost=top.path_cost + step_cost))) + + raise RuntimeError("no solution") + +# }}} + # {{{ formatting -------------------------------------------------------------- # {{{ table formatting -------------------------------------------------------- class Table: @@ -1290,6 +1361,37 @@ except TypeError: return val.__class__.__name__ + + + +def invoke_editor(s, filename="edit.txt", descr="the file"): + from tempfile import mkdtemp + tempdir = mkdtemp() + + from os.path import join + full_name = join(tempdir, filename) + + outf = open(full_name, "w") + outf.write(str(s)) + outf.close() + + import os + if "EDITOR" in os.environ: + from subprocess import Popen + p = Popen([os.environ["EDITOR"], full_name]) + os.waitpid(p.pid, 0)[1] + else: + print "(Set the EDITOR environment variable to be " \ + "dropped directly into an editor next time.)" + raw_input("Edit %s at %s now, then hit [Enter]:" + % (descr, full_name)) + + inf = open(full_name, "r") + result = inf.read() + inf.close() + + return result + # }}} # {{{ progress bars ----------------------------------------------------------- diff -Nru pytools-2011.3/pytools/obj_array.py pytools-2011.5/pytools/obj_array.py --- pytools-2011.3/pytools/obj_array.py 2011-04-05 14:45:38.000000000 +0000 +++ pytools-2011.5/pytools/obj_array.py 2011-08-10 23:11:05.000000000 +0000 @@ -129,10 +129,10 @@ def with_object_array_or_scalar(f, field, obj_array_only=False): if obj_array_only: - if isinstance(field, numpy.ndarray) and numpy.dtype == object: - ls = field.shape - else: - ls = () + if is_obj_array(field): + ls = field.shape + else: + ls = () else: ls = log_shape(field) if ls != (): @@ -162,3 +162,9 @@ def oarray_real_copy(ary): return with_object_array_or_scalar(lambda x: x.real.copy(), ary) + + + + +def oarray_imag_copy(ary): + return with_object_array_or_scalar(lambda x: x.imag.copy(), ary) diff -Nru pytools-2011.3/pytools/prefork.py pytools-2011.5/pytools/prefork.py --- pytools-2011.3/pytools/prefork.py 2010-04-11 15:56:06.000000000 +0000 +++ pytools-2011.5/pytools/prefork.py 2011-11-18 09:54:22.000000000 +0000 @@ -30,7 +30,7 @@ def call_capture_stdout(cmdline, cwd=None): from subprocess import Popen, PIPE try: - return Popen(cmdline, cwd=cwd, stdout=PIPE).communicate()[0] + return Popen(cmdline, cwd=cwd, stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate()[0] except OSError, e: raise ExecError("error invoking '%s': %s" % ( " ".join(cmdline), e)) @@ -42,7 +42,7 @@ """ from subprocess import Popen, PIPE try: - popen = Popen(cmdline, cwd=cwd, stdout=PIPE, stderr=PIPE) + popen = Popen(cmdline, cwd=cwd, stdin=PIPE, stdout=PIPE, stderr=PIPE) stdout_data, stderr_data = popen.communicate() if error_on_nonzero and popen.returncode: raise ExecError("status %d invoking '%s': %s" diff -Nru pytools-2011.3/pytools.egg-info/PKG-INFO pytools-2011.5/pytools.egg-info/PKG-INFO --- pytools-2011.3/pytools.egg-info/PKG-INFO 2011-04-05 15:48:21.000000000 +0000 +++ pytools-2011.5/pytools.egg-info/PKG-INFO 2011-11-18 09:56:05.000000000 +0000 @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: pytools -Version: 2011.3 +Version: 2011.5 Summary: A collection of tools for Python Home-page: http://pypi.python.org/pypi/pytools Author: Andreas Kloeckner diff -Nru pytools-2011.3/setup.py pytools-2011.5/setup.py --- pytools-2011.3/setup.py 2011-04-05 15:48:03.000000000 +0000 +++ pytools-2011.5/setup.py 2011-11-18 09:55:31.000000000 +0000 @@ -13,7 +13,7 @@ from distutils.command.build_py import build_py setup(name="pytools", - version="2011.3", + version="2011.5", description="A collection of tools for Python", long_description=""" Pytools is a big bag of things that are "missing" from the Python standard