Skip to content

Commit 1ac8a77

Browse files
committed
Regular update after distribution
1 parent 371d192 commit 1ac8a77

8 files changed

Lines changed: 211 additions & 20 deletions

File tree

AUTHORS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ This list is sorted by the number of commits per contributor in _descending_ ord
44

55
Avatar|Contributor|Contributions
66
:-:|---|:-:
7-
<img class='float-left rounded-1' src='https://avatars1.githubusercontent.com/u/15666417?v=4' width='36' height='36' alt='@JarryShaw'>|[@JarryShaw](https://github.com/JarryShaw)|16
7+
<img class='float-left rounded-1' src='https://avatars1.githubusercontent.com/u/15666417?v=4' width='36' height='36' alt='@JarryShaw'>|[@JarryShaw](https://github.com/JarryShaw)|19
88
<img class='float-left rounded-1' src='https://avatars0.githubusercontent.com/u/15073518?v=4' width='36' height='36' alt='@gousaiyang'>|[@gousaiyang](https://github.com/gousaiyang)|7
99

1010
---
1111

12-
Auto-generated by [gaocegege/maintainer](https://github.com/gaocegege/maintainer) on 2019-07-10.
12+
Auto-generated by [gaocegege/maintainer](https://github.com/gaocegege/maintainer) on 2019-07-14.

CHANGELOG.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Change Log
22

3+
## [v0.7.3](https://github.com/JarryShaw/f2format/tree/v0.7.3) (2019-07-10)
4+
[Full Changelog](https://github.com/JarryShaw/f2format/compare/v0.7.2...v0.7.3)
5+
36
## [v0.7.2](https://github.com/JarryShaw/f2format/tree/v0.7.2) (2019-06-24)
47
[Full Changelog](https://github.com/JarryShaw/f2format/compare/v0.7.1...v0.7.2)
58

@@ -76,13 +79,13 @@
7679
[Full Changelog](https://github.com/JarryShaw/f2format/compare/v0.3.0...v)
7780

7881
## [v0.3.0](https://github.com/JarryShaw/f2format/tree/v0.3.0) (2018-11-28)
79-
[Full Changelog](https://github.com/JarryShaw/f2format/compare/v0.2.3...v0.3.0)
80-
81-
## [v0.2.3](https://github.com/JarryShaw/f2format/tree/v0.2.3) (2018-11-27)
82-
[Full Changelog](https://github.com/JarryShaw/f2format/compare/v0.2.4...v0.2.3)
82+
[Full Changelog](https://github.com/JarryShaw/f2format/compare/v0.2.4...v0.3.0)
8383

8484
## [v0.2.4](https://github.com/JarryShaw/f2format/tree/v0.2.4) (2018-11-27)
85-
[Full Changelog](https://github.com/JarryShaw/f2format/compare/v0.2.3.post1...v0.2.4)
85+
[Full Changelog](https://github.com/JarryShaw/f2format/compare/v0.2.3...v0.2.4)
86+
87+
## [v0.2.3](https://github.com/JarryShaw/f2format/tree/v0.2.3) (2018-11-27)
88+
[Full Changelog](https://github.com/JarryShaw/f2format/compare/v0.2.3.post1...v0.2.3)
8689

8790
## [v0.2.3.post1](https://github.com/JarryShaw/f2format/tree/v0.2.3.post1) (2018-11-27)
8891

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ you can use one of some generic reasons like "Improve documentation.",
6464

6565
---
6666

67-
Auto-generated by [gaocegege/maintainer](https://github.com/gaocegege/maintainer) on 2019-07-10.
67+
Auto-generated by [gaocegege/maintainer](https://github.com/gaocegege/maintainer) on 2019-07-14.

vendor/pypy/pypy/module/_vmprof/test/test__vmprof.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,17 @@ def test_is_enabled(self):
111111
@py.test.mark.xfail(sys.platform.startswith('freebsd'), reason = "not implemented")
112112
def test_get_profile_path(self):
113113
import _vmprof
114-
tmpfile = open(self.tmpfilename, 'wb')
115-
assert _vmprof.get_profile_path() is None
116-
_vmprof.enable(tmpfile.fileno(), 0.01, 0, 0, 0, 0)
117-
path = _vmprof.get_profile_path()
114+
with open(self.tmpfilename, "wb") as tmpfile:
115+
assert _vmprof.get_profile_path() is None
116+
_vmprof.enable(tmpfile.fileno(), 0.01, 0, 0, 0, 0)
117+
path = _vmprof.get_profile_path()
118+
_vmprof.disable()
119+
118120
if path != tmpfile.name:
119121
with open(path, "rb") as fd1:
120-
assert fd1.read() == tmpfile.read()
121-
_vmprof.disable()
122+
with open(self.tmpfilename, "rb") as fd2:
123+
assert fd1.read() == fd2.read()
124+
122125
assert _vmprof.get_profile_path() is None
123126

124127
def test_stop_sampling(self):

vendor/pypy/pypy/module/posix/test/test_posix2.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,15 +372,24 @@ def test_listdir_unicode(self):
372372
result = posix.listdir(unicode_dir)
373373
typed_result = [(type(x), x) for x in result]
374374
assert (unicode, u'somefile') in typed_result
375+
file_system_encoding = sys.getfilesystemencoding()
375376
try:
376-
u = "caf\xe9".decode(sys.getfilesystemencoding())
377+
u = "caf\xe9".decode(file_system_encoding)
377378
except UnicodeDecodeError:
378379
# Could not decode, listdir returned the byte string
379380
if sys.platform != 'darwin':
380381
assert (str, "caf\xe9") in typed_result
381382
else:
382-
# darwin 'normalized' it
383-
assert (unicode, 'caf%E9') in typed_result
383+
# if the test is being run in an utf-8 encoded macOS
384+
# the posix.listdir function is returning the name of
385+
# the file properly.
386+
# This test should be run in multiple macOS platforms to
387+
# be sure that is working as expected.
388+
if file_system_encoding == 'UTF-8':
389+
assert (unicode, 'cafxe9') in typed_result
390+
else:
391+
# darwin 'normalized' it
392+
assert (unicode, 'caf%E9') in typed_result
384393
else:
385394
assert (unicode, u) in typed_result
386395

vendor/pypy/rpython/rlib/rbigint.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,12 @@ def bit_length(self):
14231423
bits = ovfcheck((i-1) * SHIFT) + msd_bits
14241424
return bits
14251425

1426+
def gcd(self, other):
1427+
""" Compute the (always positive) greatest common divisor of self and
1428+
other """
1429+
return gcd_lehmer(self.abs(), other.abs())
1430+
1431+
14261432
def __repr__(self):
14271433
return "<rbigint digits=%s, sign=%s, size=%d, len=%d, %s>" % (self._digits,
14281434
self.sign, self.numdigits(), len(self._digits),
@@ -2960,3 +2966,91 @@ def parse_string_from_binary_base(parser):
29602966
z.setdigit(pdigit, accum)
29612967
z._normalize()
29622968
return z
2969+
2970+
2971+
def gcd_binary(a, b):
2972+
""" Compute the greatest common divisor of non-negative integers a and b
2973+
using the binary GCD algorithm. Raises ValueError on negative input. """
2974+
if a < 0 or b < 0:
2975+
raise ValueError
2976+
2977+
if a == 0:
2978+
return b
2979+
2980+
if b == 0:
2981+
return a
2982+
2983+
shift = 0
2984+
while (a | b) & 1 == 0:
2985+
a >>= 1
2986+
b >>= 1
2987+
shift += 1
2988+
2989+
while a & 1 == 0:
2990+
a >>= 1
2991+
2992+
while b & 1 == 0:
2993+
b >>= 1
2994+
2995+
while a != b:
2996+
a, b = abs(a - b), min(a, b)
2997+
while a & 1 == 0:
2998+
a >>= 1
2999+
3000+
return a << shift
3001+
3002+
def lehmer_xgcd(a, b):
3003+
s_old, s_new = 1, 0
3004+
t_old, t_new = 0, 1
3005+
while b >> (SHIFT >> 1):
3006+
q, r = a // b, a % b
3007+
3008+
a, b = b, r
3009+
s_old, s_new = s_new, s_old - q * s_new
3010+
t_old, t_new = t_new, t_old - q * t_new
3011+
3012+
return s_old, t_old, s_new, t_new
3013+
3014+
def gcd_lehmer(a, b):
3015+
if a.lt(b):
3016+
a, b = b, a
3017+
3018+
while b.size > 1:
3019+
a_ms = a.digit(abs(a.size-1))
3020+
3021+
x = 0
3022+
while a_ms & (0xFF << SHIFT-8) == 0:
3023+
a_ms <<= 8
3024+
x += 8
3025+
3026+
while a_ms & (1 << SHIFT-1) == 0:
3027+
a_ms <<= 1
3028+
x += 1
3029+
3030+
a_ms |= a.digit(abs(a.size-2)) >> SHIFT-x
3031+
3032+
if a.size == b.size:
3033+
b_ms = (b.digit(abs(b.size-1)) << x) | (b.digit(abs(b.size-2)) >> SHIFT-x)
3034+
elif a.size == b.size+1:
3035+
b_ms = b.digit(abs(b.size-1)) >> SHIFT-x
3036+
else:
3037+
b_ms = 0
3038+
3039+
if b_ms >> (SHIFT+1 >> 1) == 0:
3040+
a, b = b, a.mod(b)
3041+
continue
3042+
3043+
s_old, t_old, s_new, t_new = lehmer_xgcd(a_ms, b_ms)
3044+
3045+
n_a = a.int_mul(s_new).add(b.int_mul(t_new)).abs()
3046+
b = a.int_mul(s_old).add(b.int_mul(t_old)).abs()
3047+
a = n_a
3048+
3049+
if a.lt(b):
3050+
a, b = b, a
3051+
3052+
if not b.tobool():
3053+
return a
3054+
3055+
a = a.mod(b)
3056+
return rbigint.fromint(gcd_binary(b.toint(), a.toint()))

vendor/pypy/rpython/rlib/test/test_rbigint.py

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
from rpython.rlib import rbigint as lobj
1212
from rpython.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong, intmask
1313
from rpython.rlib.rbigint import (rbigint, SHIFT, MASK, KARATSUBA_CUTOFF,
14-
_store_digit, _mask_digit, InvalidEndiannessError, InvalidSignednessError)
14+
_store_digit, _mask_digit, InvalidEndiannessError, InvalidSignednessError,
15+
gcd_lehmer, lehmer_xgcd, gcd_binary)
1516
from rpython.rlib.rfloat import NAN
1617
from rpython.rtyper.test.test_llinterp import interpret
1718
from rpython.translator.c.test.test_standalone import StandaloneTests
1819

19-
from hypothesis import given, strategies, example
20+
from hypothesis import given, strategies, example, settings
2021

2122
longs = strategies.builds(
2223
long, strategies.integers())
@@ -836,6 +837,27 @@ def test_frombytes_tobytes_hypothesis(self, s, big, signed):
836837
t = bigint.tobytes(len(s), byteorder=byteorder, signed=signed)
837838
assert s == t
838839

840+
def test_gcd(self):
841+
assert gcd_binary(2*3*7**2, 2**2*7) == 2*7
842+
pytest.raises(ValueError, gcd_binary, 2*3*7**2, -2**2*7)
843+
assert gcd_binary(1234, 5678) == 2
844+
assert gcd_binary(13, 13**6) == 13
845+
assert gcd_binary(12, 0) == 12
846+
assert gcd_binary(0, 0) == 0
847+
assert pytest.raises(ValueError, gcd_binary, -10, 0)
848+
assert pytest.raises(ValueError, gcd_binary, 10, -10)
849+
850+
x = rbigint.fromlong(9969216677189303386214405760200)
851+
y = rbigint.fromlong(16130531424904581415797907386349)
852+
g = x.gcd(y)
853+
assert g == rbigint.fromlong(1)
854+
855+
for x in gen_signs([12843440367927679363613699686751681643652809878241019930204617606850071260822269719878805]):
856+
x = rbigint.fromlong(x)
857+
for y in gen_signs([12372280584571061381380725743231391746505148712246738812788540537514927882776203827701778968535]):
858+
y = rbigint.fromlong(y)
859+
g = x.gcd(y)
860+
assert g.tolong() == 18218089570126697993340888567155155527541105
839861

840862

841863
class TestInternalFunctions(object):
@@ -1255,3 +1277,52 @@ def test_int_comparison(self, x, y):
12551277
assert lx.lt(ly) == (x < y)
12561278
assert lx.eq(ly) == (x == y)
12571279
assert lx.le(ly) == (x <= y)
1280+
1281+
@given(ints, ints, ints)
1282+
def test_gcd_binary(self, x, y, z):
1283+
x, y, z = abs(x), abs(y), abs(z)
1284+
1285+
def test(a, b, res):
1286+
g = gcd_binary(a, b)
1287+
1288+
assert g == res
1289+
1290+
a, b = x, y
1291+
while b:
1292+
a, b = b, a % b
1293+
1294+
gcd_x_y = a
1295+
1296+
test(x, y, gcd_x_y)
1297+
test(x, 0, x)
1298+
test(0, x, x)
1299+
test(x * z, y * z, gcd_x_y * z)
1300+
test(x * z, z, z)
1301+
test(z, y * z, z)
1302+
1303+
@given(biglongs, biglongs, biglongs)
1304+
@example(112233445566778899112233445566778899112233445566778899,
1305+
13579246801357924680135792468013579246801,
1306+
99887766554433221113)
1307+
@settings(max_examples=10)
1308+
def test_gcd(self, x, y, z):
1309+
print(x, y, z)
1310+
x, y, z = abs(x), abs(y), abs(z)
1311+
1312+
def test(a, b, res):
1313+
g = rbigint.fromlong(a).gcd(rbigint.fromlong(b)).tolong()
1314+
1315+
assert g == res
1316+
1317+
a, b = x, y
1318+
while b:
1319+
a, b = b, a % b
1320+
1321+
gcd_x_y = a
1322+
1323+
test(x, y, gcd_x_y)
1324+
test(x * z, y * z, gcd_x_y * z)
1325+
test(x * z, z, z)
1326+
test(z, y * z, z)
1327+
test(x, 0, x)
1328+
test(0, x, x)

vendor/pypy/rpython/translator/goal/targetbigintbenchmark.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,19 @@ def entry_point(argv):
251251
sumTime += _time
252252
print "v = v + v", _time
253253

254+
x = rbigint.fromstr("13579246801357924680135792468013579246801")
255+
y = rbigint.fromstr("112233445566778899112233445566778899112233445566778899")
256+
t = time()
257+
for i in range(5000):
258+
x.gcd(y)
259+
x = x.int_mul(2).int_add(1)
260+
_time = time() - t
261+
print "gcd", _time
262+
263+
sumTime += _time
264+
254265
print "Sum: ", sumTime
255-
266+
256267
return 0
257268

258269
# _____ Define and setup target ___

0 commit comments

Comments
 (0)