Skip to content

Commit 9f95d21

Browse files
committed
adding multithreading test
1 parent b8a60a6 commit 9f95d21

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

quaddtype/numpy_quaddtype/src/scalar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ QuadPrecision_as_integer_ratio(QuadPrecisionObject *self, PyObject *Py_UNUSED(ig
494494
exponent -= FLOAT128_PRECISION;
495495
```
496496
This should work but give non-simplified, huge integers (although they also come down to same representation)
497-
We can also do gcd to find simplified values, but it'll add more O(log(N)) {which in theory seem better}
497+
We can also do gcd to find simplified values, but it'll add more O(log(N))
498498
For the sake of simplicity and fixed 128-bit nature, we will loop till 113 only
499499
*/
500500

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import concurrent.futures
2+
import threading
3+
4+
import pytest
5+
6+
import numpy as np
7+
from numpy._core import _rational_tests
8+
from numpy._core.tests.test_stringdtype import random_unicode_string_list
9+
from numpy.testing import IS_64BIT, IS_WASM
10+
from numpy.testing._private.utils import run_threaded
11+
12+
if IS_WASM:
13+
pytest.skip(allow_module_level=True, reason="no threading support in wasm")
14+
15+
pytestmark = pytest.mark.thread_unsafe(
16+
reason="tests in this module are already explicitly multi-threaded"
17+
)
18+
19+
from numpy_quaddtype import *
20+
21+
22+
def test_as_integer_ratio_reconstruction():
23+
"""Multi-threaded test that as_integer_ratio() can reconstruct the original value."""
24+
values = ["3.14", "0.1", "1.414213562373095", "2.718281828459045",
25+
"-1.23456789", "1000.001", "0.0001", "1e20", "1.23e15", "1e-30", pi]
26+
27+
def test(barrier):
28+
barrier.wait() # All threads start simultaneously
29+
for val in values:
30+
quad_val = QuadPrecision(val)
31+
num, denom = quad_val.as_integer_ratio()
32+
# todo: can remove str converstion after merging PR #213
33+
reconstructed = QuadPrecision(str(num)) / QuadPrecision(str(denom))
34+
assert reconstructed == quad_val
35+
36+
run_threaded(test, pass_barrier=True, max_workers=64, outer_iterations=100)

0 commit comments

Comments
 (0)