Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: spatial: serialize concurrent calls to QHull #20619

Merged
merged 7 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions scipy/interpolate/tests/test_interpnd.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import os
import sys

import numpy as np
from numpy.testing import (assert_equal, assert_allclose, assert_almost_equal,
suppress_warnings)
from pytest import raises as assert_raises
import pytest

from scipy._lib._testutils import check_free_memory
import scipy.interpolate.interpnd as interpnd
import scipy.spatial._qhull as qhull

import pickle
import threading

_IS_32BIT = (sys.maxsize < 2**32)


def data_file(basename):
Expand Down Expand Up @@ -166,6 +171,49 @@ def test_pickle(self):

assert_almost_equal(ip(0.5, 0.5), ip2(0.5, 0.5))

@pytest.mark.slow
@pytest.mark.skipif(_IS_32BIT, reason='it fails on 32-bit')
def test_threading(self):
rgommers marked this conversation as resolved.
Show resolved Hide resolved
# This test was taken from issue 8856
# https://github.com/scipy/scipy/issues/8856
check_free_memory(10000)

r_ticks = np.arange(0, 4200, 10)
phi_ticks = np.arange(0, 4200, 10)
r_grid, phi_grid = np.meshgrid(r_ticks, phi_ticks)

def do_interp(interpolator, slice_rows, slice_cols):
grid_x, grid_y = np.mgrid[slice_rows, slice_cols]
res = interpolator((grid_x, grid_y))
return res

points = np.vstack((r_grid.ravel(), phi_grid.ravel())).T
values = (r_grid * phi_grid).ravel()
interpolator = interpnd.LinearNDInterpolator(points, values)

worker_thread_1 = threading.Thread(
target=do_interp,
args=(interpolator, slice(0, 2100), slice(0, 2100)))
worker_thread_2 = threading.Thread(
target=do_interp,
args=(interpolator, slice(2100, 4200), slice(0, 2100)))
worker_thread_3 = threading.Thread(
target=do_interp,
args=(interpolator, slice(0, 2100), slice(2100, 4200)))
worker_thread_4 = threading.Thread(
target=do_interp,
args=(interpolator, slice(2100, 4200), slice(2100, 4200)))

worker_thread_1.start()
worker_thread_2.start()
worker_thread_3.start()
worker_thread_4.start()

worker_thread_1.join()
worker_thread_2.join()
worker_thread_3.join()
worker_thread_4.join()


class TestEstimateGradients2DGlobal:
def test_smoketest(self):
Expand Down