Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@pytools.test.mark_test.opencl
def test_tree(ctx_getter, do_plot=False):
ctx = ctx_getter()
queue = cl.CommandQueue(ctx)
#for dims in [2, 3]:
for dims in [2]:
nparticles = 10000
dtype = np.float64
from pyopencl.clrandom import RanluxGenerator
rng = RanluxGenerator(queue, seed=15)
from pytools.obj_array import make_obj_array
particles = make_obj_array([
rng.normal(queue, nparticles, dtype=dtype)
for i in range(dims)])
if do_plot:
pt.plot(particles[0].get(), particles[1].get(), "x")
from sumpy.tree import TreeBuilder
tb = TreeBuilder(ctx)
queue.finish()
print "building..."
tree = tb(queue, particles, max_particles_in_box=30)
print "%d boxes, testing..." % tree.nboxes
starts = tree.box_starts.get()
pcounts = tree.box_particle_counts.get()
def output_zeros(self):
from pytools.obj_array import make_obj_array
return make_obj_array([
cl.array.zeros(
self.queue,
self.tree.ntargets,
dtype=self.dtype)
for k in self.code.out_kernels])
from six.moves import range
ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)
dims = 2
nparticles = 500
# -----------------------------------------------------------------------------
# generate some random particle positions
# -----------------------------------------------------------------------------
from pyopencl.clrandom import RanluxGenerator
rng = RanluxGenerator(queue, seed=15)
from pytools.obj_array import make_obj_array
particles = make_obj_array([
rng.normal(queue, nparticles, dtype=np.float64)
for i in range(dims)])
# -----------------------------------------------------------------------------
# build tree and traversals (lists)
# -----------------------------------------------------------------------------
from boxtree import TreeBuilder
tb = TreeBuilder(ctx)
tree, _ = tb(queue, particles, max_particles_in_box=5)
from boxtree.traversal import FMMTraversalBuilder
tg = FMMTraversalBuilder(ctx)
trav, _ = tg(queue, tree)
# ENDEXAMPLE
def dnabla(self, ambient_dim):
from pymbolic.geometric_algebra import MultiVector
from pytools.obj_array import make_obj_array
return MultiVector(make_obj_array(
[NablaComponent(axis, self.my_id)
for axis in range(ambient_dim)]))
def src_derivative_dir(self):
self.arguments["src_derivative_dir"] = \
lp.GlobalArg("src_derivative_dir",
self.geometry_dtype, shape=("ntargets", self.dim),
order="C")
from pytools.obj_array import make_obj_array
return make_obj_array([
parse("src_derivative_dir[itgt, %d]" % i)
for i in range(self.dim)])
def u(self, q):
return make_obj_array([
rho_u_i/self.rho(q)
for rho_u_i in self.rho_u(q)])
def normal(self):
self.arguments["normal"] = \
lp.GlobalArg("normal", self.geometry_dtype,
shape=("ntargets", self.dim), order="C")
from pytools.obj_array import make_obj_array
return make_obj_array([
parse("normal[itgt, %d]" % i)
for i in range(self.dim)])
logger.debug("tree build: start")
# {{{ combine sources and targets into one array, if necessary
prep_events = []
if targets is None:
# Targets weren't specified. Sources are also targets. Let's
# call them "srcntgts".
from pytools.obj_array import is_obj_array, make_obj_array
if is_obj_array(particles):
srcntgts = particles
else:
srcntgts = make_obj_array([
p.with_queue(queue).copy() for p in particles
])
assert source_radii is None
assert target_radii is None
srcntgt_radii = None
else:
# Here, we mash sources and targets into one array to give us one
# big array of "srcntgts". In this case, a "srcntgt" is either a
# source or a target, but not really both, as above. How will we be
# able to tell which it was? Easy: We'll compare its 'user' id with
# nsources. If it's >=, it's a target, otherwise it's a source.
target_coord_dtype = single_valued(tgt_i.dtype for tgt_i in targets)
def stream_rhs(self, f_bar):
return make_obj_array([
self.get_advection_op(f_bar_alpha, e_alpha)
for e_alpha, f_bar_alpha in
zip(self.method.direction_vectors, f_bar)])