Skip to content

Instantly share code, notes, and snippets.

@rlamy
rlamy / numpy_hang.py
Created October 31, 2019 15:25
numpy hang in GIL
import numpy as np
def random_slice(rng, n):
start = rng.randint(0, n + 1, dtype=np.intp)
def main():
rng = np.random.RandomState(1234)
t1 = np.arange(2)
for i in range(5000000):
s1 = [random_slice(rng, 7) for _ in range(2)]
(pypy-std) ronan@Berder:~/devel/pypy$ python revdb.py log.rdb
RevDB: /home/ronan/.virtualenvs/revdb/bin/python -m pytest pypy/module/cpyext/test/test_arraymodule.py -k test_subclass
File "<builtin>/app_main.py", line 824 in setup_bootstrap_path:
(1)$ c
(83000000...)bad callback index 4ad6
Traceback (most recent call last):
File "/home/ronan/.virtualenvs/pypy-std/site-packages/_revdb/interact.py", line 110, in run_command
runner(argument)
File "/home/ronan/.virtualenvs/pypy-std/site-packages/_revdb/interact.py", line 366, in command_continue
(Pdb) result.keys()
[<C object Array of void at 0x5602cd0>, <C object Array of void at 0x51647b0>, <C object Array of void at 0x451ca40>, <C object Array of void at 0x9123b80>, <C object Struct PyHeapTypeObject { c_ht_type, c_as_number, c_as_mapping, c_as_sequence, c_as_buffer, c_ht_name, c_ht_slots } at 0x4eef230>, <C object Array of void at 0x79c4070>, <C object Array of void at 0x5cfa430>, <C object Array of void at 0x18fe360>, <C object Array of void at 0x2781ef0>]
(Pdb) result.keys()[4]
<C object Struct PyHeapTypeObject { c_ht_type, c_as_number, c_as_mapping, c_as_sequence, c_as_buffer, c_ht_name, c_ht_slots } at 0x4eef230>
(Pdb) u
> /home/ronan/devel/pypy/pypy/module/cpyext/test/test_cpyext.py(87)cleanup()
-> leakfinder.stop_tracking_allocations(check=True)
(Pdb) import pypy
(Pdb) pypy.space = self.space
(Pdb) d
@rlamy
rlamy / test_bytearray.py
Created July 15, 2017 16:42
bytearray.extend() bench
import time
import random
import sys
def as_bytearray(l):
res = bytearray()
for i in l:
res.append(i)
return res
import time
from sympy import Piecewise, Eq, symbols
x, y, a, b = symbols('x, y, a, b')
eq = Eq(x, y)
N = 50
for _ in range(N):
start = time.time()
diff --git a/sympy/physics/vector/tests/test_frame.py b/sympy/physics/vector/tests/test_frame.py
index b1a55d2..3c3af2c 100644
--- a/sympy/physics/vector/tests/test_frame.py
+++ b/sympy/physics/vector/tests/test_frame.py
@@ -7,6 +7,13 @@
A = ReferenceFrame('A')
+def test_simple_caching():
+ A1 = ReferenceFrame('A')
@rlamy
rlamy / gist:4170308
Created November 29, 2012 16:50
Strings with embedded LaTeX in IPython
from string import Formatter
from sympy import latex
class LatexFormatter(Formatter):
def convert_field(self, value, conversion):
if conversion == 'L':
try:
return value._repr_latex()
except AttributeError:
return latex(value)
else: