From 45824f5f367b46a48ff403612c6a8f64c0f48605 Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Wed, 7 Aug 2024 11:11:50 +0300 Subject: [PATCH 1/2] port away from deprecated actx.zeros --- test/test_fmm.py | 2 +- test/test_tree.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/test_fmm.py b/test/test_fmm.py index dccd0d02..1ec072db 100644 --- a/test/test_fmm.py +++ b/test/test_fmm.py @@ -267,7 +267,7 @@ def test_fmm_completeness(actx_factory, dims, nsources_req, ntargets_req, raise ValueError("unsupported value of 'filter_kind'") else: wrangler = ConstantOneExpansionWrangler(tree_indep, host_trav) - flags = 1 + actx.zeros(ntargets or nsources, dtype=np.int8) + flags = 1 + actx.np.zeros(ntargets or nsources, dtype=np.int8) if ntargets is None and not filter_kind: # This check only works for targets == sources. diff --git a/test/test_tree.py b/test/test_tree.py index a51fa4cc..69743dbd 100644 --- a/test/test_tree.py +++ b/test/test_tree.py @@ -462,7 +462,7 @@ def test_extent_tree(actx_factory, dims, extent_norm, visualize=False): targets = make_normal_particle_array(actx.queue, ntargets, dims, dtype, seed=19) - refine_weights = actx.zeros(nsources + ntargets, np.int32) + refine_weights = actx.np.zeros(nsources + ntargets, np.int32) refine_weights[:nsources] = 1 rng = np.random.default_rng(13) @@ -693,7 +693,7 @@ def test_leaves_to_balls_query(actx_factory, dims, visualize=False): nballs = 10**4 ball_centers = make_normal_particle_array(actx.queue, nballs, dims, dtype) - ball_radii = 0.1 + actx.zeros(nballs, dtype) + ball_radii = 0.1 + actx.np.zeros(nballs, dtype) from boxtree.area_query import LeavesToBallsLookupBuilder lblb = LeavesToBallsLookupBuilder(actx.context) @@ -797,7 +797,7 @@ def test_area_query(actx_factory, dims, visualize=False): nballs = 10**4 ball_centers = make_normal_particle_array(actx.queue, nballs, dims, dtype) - ball_radii = 0.1 + actx.zeros(nballs, dtype) + ball_radii = 0.1 + actx.np.zeros(nballs, dtype) run_area_query_test(actx, tree, ball_centers, ball_radii) @@ -838,7 +838,7 @@ def test_area_query_balls_outside_bbox(actx_factory, dims, visualize=False): actx.from_numpy( rng.uniform(bbox_min - 1, bbox_max + 1, nballs).astype(dtype)) for i in range(dims)]) - ball_radii = 0.1 + actx.zeros(nballs, dtype) + ball_radii = 0.1 + actx.np.zeros(nballs, dtype) run_area_query_test(actx, tree, ball_centers, ball_radii) @@ -867,7 +867,7 @@ def test_area_query_elwise(actx_factory, dims, visualize=False): nballs = 10**4 ball_centers = make_normal_particle_array(actx.queue, nballs, dims, dtype) - ball_radii = 0.1 + actx.zeros(nballs, dtype) + ball_radii = 0.1 + actx.np.zeros(nballs, dtype) from boxtree.area_query import AreaQueryElementwiseTemplate, PeerListFinder @@ -1017,7 +1017,7 @@ def test_space_invader_query(actx_factory, dims, dtype, visualize=False): nballs = 10**4 ball_centers = make_normal_particle_array(actx.queue, nballs, dims, dtype) - ball_radii = 0.1 + actx.zeros(nballs, dtype) + ball_radii = 0.1 + actx.np.zeros(nballs, dtype) from boxtree.area_query import LeavesToBallsLookupBuilder, SpaceInvaderQueryBuilder @@ -1088,7 +1088,7 @@ def test_same_tree_with_zero_weight_particles(actx_factory, dims): sources = actx.from_numpy(sources) targets = actx.from_numpy(targets) - refine_weights = actx.empty(nsources + ntargets, np.int32) + refine_weights = actx.np.zeros(nsources + ntargets, np.int32) refine_weights[:nsources] = 1 refine_weights[nsources:] = 0 @@ -1122,7 +1122,7 @@ def test_max_levels_error(actx_factory): from boxtree import TreeBuilder tb = TreeBuilder(actx.context) - sources = [actx.zeros(11, np.float64) for i in range(2)] + sources = [actx.np.zeros(11, np.float64) for i in range(2)] from boxtree.tree_build import MaxLevelsExceeded with pytest.raises(MaxLevelsExceeded): _tree, _ = tb(actx.queue, sources, max_particles_in_box=10, debug=True) From d4faf6339ba67e42365fcfac1a3e8c1dcf7d2837 Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Fri, 9 Aug 2024 14:41:36 +0300 Subject: [PATCH 2/2] fix issues with ruff 0.5.7 --- boxtree/tree_of_boxes.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/boxtree/tree_of_boxes.py b/boxtree/tree_of_boxes.py index ad1eeaaf..44980a3b 100644 --- a/boxtree/tree_of_boxes.py +++ b/boxtree/tree_of_boxes.py @@ -86,12 +86,15 @@ def _resized_array(arr: np.ndarray, new_size: int) -> np.ndarray: old_size = arr.shape[-1] prefix = (slice(None), ) * (arr.ndim - 1) if old_size >= new_size: - return arr[(*prefix, slice(new_size))].copy() + key = (*prefix, slice(new_size)) + return arr[key].copy() else: new_shape = list(arr.shape) new_shape[-1] = new_size new_arr = np.zeros(new_shape, arr.dtype) - new_arr[(*prefix, slice(old_size))] = arr + + key = (*prefix, slice(old_size)) + new_arr[key] = arr return new_arr