Modified:
/trunk/mpmath/calculus/approximation.py
/trunk/mpmath/calculus/differentiation.py
/trunk/mpmath/calculus/extrapolation.py
/trunk/mpmath/calculus/polynomials.py
/trunk/mpmath/ctx_iv.py
/trunk/mpmath/ctx_mp.py
/trunk/mpmath/ctx_mp_python.py
/trunk/mpmath/functions/hypergeometric.py
/trunk/mpmath/functions/qfunctions.py
/trunk/mpmath/libmp/libintmath.py
/trunk/mpmath/libmp/libmpi.py
/trunk/mpmath/math2.py
/trunk/mpmath/matrices/matrices.py
/trunk/mpmath/rational.py
/trunk/mpmath/tests/test_basic_ops.py
/trunk/mpmath/tests/test_bitwise.py
/trunk/mpmath/tests/test_convert.py
/trunk/mpmath/tests/test_functions.py
/trunk/mpmath/tests/test_linalg.py
/trunk/mpmath/tests/test_matrices.py
/trunk/mpmath/tests/test_visualization.py
/trunk/mpmath/visualization.py
=======================================
--- /trunk/mpmath/calculus/approximation.py Sat Jan 8 14:54:03 2011
+++ /trunk/mpmath/calculus/approximation.py Sat Jan 8 15:52:03 2011
@@ -120,8 +120,7 @@
d[0] = -c[0]/2
h = ctx.mpf(0.5)
T = chebT(ctx, ctx.mpf(2)/(b-a), ctx.mpf(-1)*(b+a)/(b-a))
- for k in range(N):
- Tk = T.next()
+ for (k, Tk) in zip(range(N), T):
for i in range(len(Tk)):
d[i] += c[k]*Tk[i]
d = d[::-1]
=======================================
--- /trunk/mpmath/calculus/differentiation.py Sat Jan 8 14:54:03 2011
+++ /trunk/mpmath/calculus/differentiation.py Sat Jan 8 15:52:03 2011
@@ -172,7 +172,7 @@
except TypeError:
pass
if partial:
- x = map(ctx.convert, x)
+ x = [ctx.convert(_) for _ in x]
return _partial_diff(ctx, f, x, orders, options)
method = options.get('method', 'step')
if n == 0 and method != 'quad' and not options.get('singular'):
=======================================
--- /trunk/mpmath/calculus/extrapolation.py Sat Jan 8 14:54:03 2011
+++ /trunk/mpmath/calculus/extrapolation.py Sat Jan 8 15:52:03 2011
@@ -6,6 +6,11 @@
from ..libmp.backend import xrange
from .calculus import defun
+try:
+ next = next
+except NameError:
+ next = lambda _: _.next()
+
@defun
def richardson(ctx, seq):
r"""
@@ -490,7 +495,7 @@
# Get new batch of terms
try:
- step = steps.next()
+ step = next(steps)
except StopIteration:
pass
if verbose:
=======================================
--- /trunk/mpmath/calculus/polynomials.py Sat Jan 8 14:54:03 2011
+++ /trunk/mpmath/calculus/polynomials.py Sat Jan 8 15:52:03 2011
@@ -150,7 +150,7 @@
# Must be monic
lead = ctx.convert(coeffs[0])
if lead == 1:
- coeffs = map(ctx.convert, coeffs)
+ coeffs = [ctx.convert(c) for c in coeffs]
else:
coeffs = [c/lead for c in coeffs]
f = lambda x: ctx.polyval(coeffs, x)
=======================================
--- /trunk/mpmath/ctx_iv.py Sat Jan 8 15:11:04 2011
+++ /trunk/mpmath/ctx_iv.py Sat Jan 8 15:52:03 2011
@@ -258,7 +258,8 @@
ivmpf.__div__, ivmpf.__rdiv__, ivmpc.__div__, ivmpc.__rdiv__ =
_binary_op(mpi_div, mpci_div)
ivmpf.__pow__, ivmpf.__rpow__, ivmpc.__pow__, ivmpc.__rpow__ =
_binary_op(mpi_pow, mpci_pow)
-
+ivmpf.__truediv__ = ivmpf.__div__; ivmpf.__rtruediv__ = ivmpf.__rdiv__
+ivmpc.__truediv__ = ivmpc.__div__; ivmpc.__rtruediv__ = ivmpc.__rdiv__
class ivmpf_constant(ivmpf):
def __new__(cls, f):
=======================================
--- /trunk/mpmath/ctx_mp.py Sat Jan 8 15:11:04 2011
+++ /trunk/mpmath/ctx_mp.py Sat Jan 8 15:52:03 2011
@@ -1215,8 +1215,8 @@
a = int(a)
prec = ctx._prec
xs, ys = libmp.mpc_zetasum(s._mpc_, a, n, derivatives, reflect,
prec)
- xs = map(ctx.make_mpc, xs)
- ys = map(ctx.make_mpc, ys)
+ xs = [ctx.make_mpc(x) for x in xs]
+ ys = [ctx.make_mpc(y) for y in ys]
return xs, ys
class PrecisionManager:
=======================================
--- /trunk/mpmath/ctx_mp_python.py Sat Jan 8 15:11:04 2011
+++ /trunk/mpmath/ctx_mp_python.py Sat Jan 8 15:52:03 2011
@@ -144,6 +144,8 @@
def __complex__(s): return complex(float(s))
def __nonzero__(s): return s._mpf_ != fzero
+ __bool__ = __nonzero__
+
def __abs__(s):
cls, new, (prec, rounding) = s._ctxdata
v = new(cls)
@@ -226,6 +228,8 @@
def to_fixed(self, prec):
return to_fixed(self._mpf_, prec)
+ def __round__(self, *args):
+ return round(float(self), *args)
mpf_binary_op = """
def %NAME%(self, other):
@@ -420,6 +424,8 @@
def __nonzero__(s):
return mpc_is_nonzero(s._mpc_)
+ __bool__ = __nonzero__
+
def __hash__(s):
return mpc_hash(s._mpc_)
=======================================
--- /trunk/mpmath/functions/hypergeometric.py Sat Jan 8 14:54:03 2011
+++ /trunk/mpmath/functions/hypergeometric.py Sat Jan 8 15:52:03 2011
@@ -199,8 +199,8 @@
z = ctx.convert(z)
p = len(a_s)
q = len(b_s)
- a_s = map(ctx._convert_param, a_s)
- b_s = map(ctx._convert_param, b_s)
+ a_s = [ctx._convert_param(a) for a in a_s]
+ b_s = [ctx._convert_param(b) for b in b_s]
# Reduce degree by eliminating common parameters
if kwargs.get('eliminate', True):
i = 0
@@ -1006,8 +1006,8 @@
q = m + len(bq)
a = an+ap
b = bm+bq
- a = map(ctx.convert, a)
- b = map(ctx.convert, b)
+ a = [ctx.convert(_) for _ in a]
+ b = [ctx.convert(_) for _ in b]
z = ctx.convert(z)
if series is None:
if p < q: series = 1
@@ -1252,7 +1252,7 @@
args = list(args)
except TypeError:
args = [args]
- return map(ctx.convert, args)
+ return [ctx.convert(arg) for arg in args]
a_s = dict(a)
b_s = dict(b)
a_m = parse(a, 'm')
=======================================
--- /trunk/mpmath/functions/qfunctions.py Sat Jan 8 14:15:29 2011
+++ /trunk/mpmath/functions/qfunctions.py Sat Jan 8 15:52:03 2011
@@ -245,8 +245,8 @@
#a_s = [ctx._convert_param(a)[0] for a in a_s]
#b_s = [ctx._convert_param(b)[0] for b in b_s]
#q = ctx._convert_param(q)[0]
- a_s = map(ctx.convert, a_s)
- b_s = map(ctx.convert, b_s)
+ a_s = [ctx.convert(a) for a in a_s]
+ b_s = [ctx.convert(b) for b in b_s]
q = ctx.convert(q)
z = ctx.convert(z)
r = len(a_s)
=======================================
--- /trunk/mpmath/libmp/libintmath.py Sat Jan 8 14:54:03 2011
+++ /trunk/mpmath/libmp/libintmath.py Sat Jan 8 15:52:03 2011
@@ -377,7 +377,7 @@
def list_primes(n):
n = n + 1
- sieve = range(n)
+ sieve = list(xrange(n))
sieve[:2] = [0, 0]
for i in xrange(2, int(n**0.5)+1):
if sieve[i]:
@@ -389,7 +389,7 @@
# Note: it is *VERY* important for performance that we convert
# the list to Python ints.
def list_primes(n):
- return map(int, sage.primes(n+1))
+ return [int(_) for _ in sage.primes(n+1)]
small_odd_primes = (3,5,7,11,13,17,19,23,29,31,37,41,43,47)
small_odd_primes_set = set(small_odd_primes)
@@ -521,7 +521,7 @@
return f
MAX = MAX_EULER_CACHE
n = m
- a = map(MPZ, [0,0,1,0,0,0])
+ a = [MPZ(_) for _ in [0,0,1,0,0,0]]
for n in range(1, m+1):
for j in range(n+1, -1, -2):
a[j+1] = (j-1)*a[j] + (j+1)*a[j+2]
=======================================
--- /trunk/mpmath/libmp/libmpi.py Sat Jan 8 14:15:29 2011
+++ /trunk/mpmath/libmp/libmpi.py Sat Jan 8 15:52:03 2011
@@ -3,6 +3,8 @@
"""
+from .backend import xrange
+
from .libmpf import (
ComplexResult,
round_down, round_up, round_floor, round_ceiling, round_nearest,
=======================================
--- /trunk/mpmath/math2.py Wed Jul 28 13:09:06 2010
+++ /trunk/mpmath/math2.py Sat Jan 8 15:52:03 2011
@@ -273,7 +273,12 @@
re = z
im = 0.0
refloor = floor(re)
- imsign = cmp(im, 0)
+ if im == 0.0:
+ imsign = 0
+ elif im < 0.0:
+ imsign = -1
+ else:
+ imsign = 1
return (-pi*1j)*abs(refloor)*(1-abs(imsign)) + logpi - \
log(sinpi(z-refloor)) - loggamma(z) + 1j*pi*refloor*imsign
if x == 1.0 or x == 2.0:
=======================================
--- /trunk/mpmath/matrices/matrices.py Sat Jan 8 14:54:03 2011
+++ /trunk/mpmath/matrices/matrices.py Sat Jan 8 15:52:03 2011
@@ -450,8 +450,8 @@
#Rows
if isinstance(key[0],slice):
#Check bounds
- if (key[0].start >= 0 or key[0].start is None) and \
- (key[0].stop <= self.__rows+1 or key[0].stop is None):
+ if (key[0].start is None or key[0].start >= 0) and \
+ (key[0].stop is None or key[0].stop <= self.__rows+1):
# Generate indices
rows = xrange(*key[0].indices(self.__rows))
else:
@@ -463,8 +463,8 @@
# Columns
if isinstance(key[1],slice):
# Check bounds
- if (key[1].start >= 0 or key[1].start is None) and \
- (key[1].stop <= self.__cols+1 or key[1].stop is None):
+ if (key[1].start is None or key[1].start >= 0) and \
+ (key[1].stop is None or key[1].stop <= self.__cols+1):
# Generate indices
columns = xrange(*key[1].indices(self.__cols))
else:
@@ -514,8 +514,8 @@
# Rows
if isinstance(key[0],slice):
# Check bounds
- if (key[0].start >= 0 or key[0].start is None) and \
- (key[0].stop <= self.__rows+1 or key[0].stop is None):
+ if (key[0].start is None or key[0].start >= 0) and \
+ (key[0].stop is None or key[0].stop <= self.__rows+1):
# generate row indices
rows = xrange(*key[0].indices(self.__rows))
else:
@@ -526,8 +526,8 @@
# Columns
if isinstance(key[1],slice):
# Check bounds
- if (key[1].start >= 0 or key[1].start is None) and \
- (key[1].stop <= self.__cols+1 or key[1].stop is None):
+ if (key[1].start is None or key[1].start >= 0) and \
+ (key[1].stop is None or key[1].stop <= self.__cols+1):
# Generate column indices
columns = xrange(*key[1].indices(self.__cols))
else:
@@ -682,7 +682,7 @@
return self.__rows
def __setrows(self, value):
- for key in self.__data.copy().iterkeys():
+ for key in self.__data.copy():
if key[0] >= value:
del self.__data[key]
self.__rows = value
@@ -693,7 +693,7 @@
return self.__cols
def __setcols(self, value):
- for key in self.__data.copy().iterkeys():
+ for key in self.__data.copy():
if key[1] >= value:
del self.__data[key]
self.__cols = value
=======================================
--- /trunk/mpmath/rational.py Sat Jan 8 14:15:29 2011
+++ /trunk/mpmath/rational.py Sat Jan 8 15:52:03 2011
@@ -47,6 +47,8 @@
def __nonzero__(s):
return bool(s._mpq_[0])
+ __bool__ = __nonzero__
+
def __hash__(s):
a, b = s._mpq_
if b == 1:
=======================================
--- /trunk/mpmath/tests/test_basic_ops.py Thu Jul 29 06:12:00 2010
+++ /trunk/mpmath/tests/test_basic_ops.py Sat Jan 8 15:52:03 2011
@@ -3,6 +3,11 @@
from mpmath.libmp import *
import random
+try:
+ long = long
+except NameError:
+ long = int
+
def test_type_compare():
assert mpf(2) == mpc(2,0)
assert mpf(0) == mpc(0)
@@ -159,7 +164,7 @@
def test_arithmetic_functions():
import operator
ops = [(operator.add, fadd), (operator.sub, fsub), (operator.mul,
fmul),
- (operator.div, fdiv)]
+ (operator.truediv, fdiv)]
a = mpf(0.27)
b = mpf(1.13)
c = mpc(0.51+2.16j)
@@ -390,8 +395,8 @@
assert isnormal(mpq((0,1))) == False
assert isint(3) == True
assert isint(0) == True
- assert isint(3L) == True
- assert isint(0L) == True
+ assert isint(long(3)) == True
+ assert isint(long(0)) == True
assert isint(mpf(3)) == True
assert isint(mpf(0)) == True
assert isint(mpf(-3)) == True
=======================================
--- /trunk/mpmath/tests/test_bitwise.py Wed Jul 28 13:09:06 2010
+++ /trunk/mpmath/tests/test_bitwise.py Sat Jan 8 15:52:03 2011
@@ -76,7 +76,7 @@
def test_rounding_bugs():
# 1 less than power-of-two cases
assert from_man_exp(72057594037927935, -56, 53, round_up) == (0, 1, 0,
1)
- assert from_man_exp(73786976294838205979l, -65, 53, round_nearest) ==
(0, 1, 1, 1)
+ assert from_man_exp(73786976294838205979, -65, 53, round_nearest) ==
(0, 1, 1, 1)
assert from_man_exp(31, 0, 4, round_up) == (0, 1, 5, 1)
assert from_man_exp(-31, 0, 4, round_floor) == (1, 1, 5, 1)
assert from_man_exp(255, 0, 7, round_up) == (0, 1, 8, 1)
=======================================
--- /trunk/mpmath/tests/test_convert.py Sat Jan 8 14:54:03 2011
+++ /trunk/mpmath/tests/test_convert.py Sat Jan 8 15:52:03 2011
@@ -45,8 +45,12 @@
def test_unicode():
mp.dps = 15
- assert mpf(u'2.76') == 2.76
- assert mpf(u'inf') == inf
+ try:
+ unicode = unicode
+ except NameError:
+ unicode = str
+ assert mpf(unicode('2.76')) == 2.76
+ assert mpf(unicode('inf')) == inf
def test_str_format():
assert to_str(from_float(0.1),15,strip_zeros=False)
== '0.100000000000000'
=======================================
--- /trunk/mpmath/tests/test_functions.py Sat Jan 8 14:54:03 2011
+++ /trunk/mpmath/tests/test_functions.py Sat Jan 8 15:52:03 2011
@@ -144,10 +144,10 @@
assert exp(0) == 1
assert exp(10000).ae(mpf('8.8068182256629215873e4342'))
assert exp(-10000).ae(mpf('1.1354838653147360985e-4343'))
- a = exp(mpf((1, 8198646019315405L, -53, 53)))
+ a = exp(mpf((1, 8198646019315405, -53, 53)))
assert(a.bc == bitcount(a.man))
mp.prec = 67
- a = exp(mpf((1, 1781864658064754565L, -60, 61)))
+ a = exp(mpf((1, 1781864658064754565, -60, 61)))
assert(a.bc == bitcount(a.man))
mp.prec = 53
assert exp(ln2 * 10).ae(1024)
@@ -199,7 +199,7 @@
assert isnan(log(mpc(1,nan)).imag)
def test_trig_hyperb_basic():
- for x in (range(100) + range(-100,0)):
+ for x in (list(range(100)) + list(range(-100,0))):
t = x / 4.1
assert cos(mpf(t)).ae(math.cos(t))
assert sin(mpf(t)).ae(math.sin(t))
@@ -380,8 +380,8 @@
assert (atanh(-1e-10)*10**10).ae(-1)
def test_complex_functions():
- for x in (range(10) + range(-10,0)):
- for y in (range(10) + range(-10,0)):
+ for x in (list(range(10)) + list(range(-10,0))):
+ for y in (list(range(10)) + list(range(-10,0))):
z = complex(x, y)/4.3 + 0.01j
assert exp(mpc(z)).ae(cmath.exp(z))
assert log(mpc(z)).ae(cmath.log(z))
=======================================
--- /trunk/mpmath/tests/test_linalg.py Sat Jan 8 14:54:03 2011
+++ /trunk/mpmath/tests/test_linalg.py Sat Jan 8 15:52:03 2011
@@ -115,7 +115,7 @@
# similiar to Hilbert matrix
A = []
for i in range(1, 13):
- A.append([1. / (i + j - 1) for j in xrange(1, n + 1)])
+ A.append([1. / (i + j - 1) for j in range(1, n + 1)])
return matrix(A)
residuals = []
=======================================
--- /trunk/mpmath/tests/test_matrices.py Sat Jan 8 14:54:03 2011
+++ /trunk/mpmath/tests/test_matrices.py Sat Jan 8 15:52:03 2011
@@ -9,7 +9,7 @@
A2 = matrix(3, 2)
assert not A2._matrix__data
A3 = matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
- assert list(A3) == range(1, 10)
+ assert list(A3) == list(range(1, 10))
A3[1,1] = 0
assert not (1, 1) in A3._matrix__data
A4 = matrix([[1, 2, 3], [4, 5, 6]])
@@ -176,7 +176,7 @@
assert x == matrix([[0], [1], [2], [3], [4]])
assert x[3] == 3
assert len(x._matrix__data) == 4
- assert list(x) == range(5)
+ assert list(x) == list(range(5))
x[0] = -10
x[4] = 0
assert x[0] == -10
=======================================
--- /trunk/mpmath/tests/test_visualization.py Sat Jan 8 14:38:25 2011
+++ /trunk/mpmath/tests/test_visualization.py Sat Jan 8 15:52:03 2011
@@ -11,7 +11,7 @@
import matplotlib
version = matplotlib.__version__.split("-")[0]
version = version.split(".")[:2]
- if map(int, version) < [0,99]:
+ if [int(_) for _ in version] < [0,99]:
raise ImportError
import pylab
except ImportError:
=======================================
--- /trunk/mpmath/visualization.py Sat Jan 8 14:54:03 2011
+++ /trunk/mpmath/visualization.py Sat Jan 8 15:52:03 2011
@@ -96,9 +96,9 @@
axes.plot(x, z, ':'+c, linewidth=3)
else:
axes.plot(x, y, c, linewidth=3)
- axes.set_xlim(map(float, xlim))
+ axes.set_xlim([float(_) for _ in xlim])
if ylim:
- axes.set_ylim(map(float, ylim))
+ axes.set_ylim([float(_) for _ in ylim])
axes.set_xlabel('x')
axes.set_ylabel('f(x)')
axes.grid(True)
@@ -175,7 +175,7 @@
w[n,m] = v
if verbose:
print(n, "of", N)
- rea, reb, ima, imb = map(float, [rea, reb, ima, imb])
+ rea, reb, ima, imb = [float(_) for _ in [rea, reb, ima, imb]]
axes.imshow(w, extent=(rea, reb, ima, imb), origin='lower')
axes.set_xlabel('Re(z)')
axes.set_ylabel('Im(z)')