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

Port away from deprecated actx.zeros #91

Merged
merged 2 commits into from
Aug 10, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions boxtree/tree_of_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion test/test_fmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions test/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down