From 93db56127d0b98db21edad2f9de9cb916e8d7b64 Mon Sep 17 00:00:00 2001 From: Natalie Beams Date: Fri, 15 Apr 2016 15:35:03 -0500 Subject: [PATCH 1/2] Add data type as option for scipy operator creation --- pytential/symbolic/execution.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pytential/symbolic/execution.py b/pytential/symbolic/execution.py index ca6652a7..4b42d727 100644 --- a/pytential/symbolic/execution.py +++ b/pytential/symbolic/execution.py @@ -160,11 +160,12 @@ class MatVecOp: """ def __init__(self, - bound_expr, queue, arg_name, total_dofs, + bound_expr, queue, arg_name, dtype, total_dofs, starts_and_ends, extra_args): self.bound_expr = bound_expr self.queue = queue self.arg_name = arg_name + self.dtype = dtype self.total_dofs = total_dofs self.starts_and_ends = starts_and_ends self.extra_args = extra_args @@ -173,8 +174,6 @@ class MatVecOp: def shape(self): return (self.total_dofs, self.total_dofs) - dtype = np.dtype(np.complex128) # FIXME - def matvec(self, x): if isinstance(x, np.ndarray): x = cl.array.to_device(self.queue, x) @@ -196,7 +195,7 @@ class MatVecOp: if do_split: # re-join what was split joined_result = cl.array.empty(self.queue, self.total_dofs, - np.complex128) # FIXME + self.dtype) for res_i, (start, end) in zip(result, self.starts_and_ends): joined_result[start:end] = res_i result = joined_result @@ -253,7 +252,7 @@ class BoundExpression: return discr - def scipy_op(self, queue, arg_name, domains=None, **extra_args): + def scipy_op(self, queue, arg_name, dtype, domains=None, **extra_args): """ :arg domains: a list of discretization identifiers or *None* values indicating the domains on which each component of the @@ -290,7 +289,7 @@ class BoundExpression: # for linear system solving, in which case the assumption # has to be true. return MatVecOp(self, queue, - arg_name, total_dofs, starts_and_ends, extra_args) + arg_name, dtype, total_dofs, starts_and_ends, extra_args) def __call__(self, queue, **args): exec_mapper = EvaluationMapper(self, queue, args) -- GitLab From 25bbf65d020a58563a42f5625c7dea1b41817afa Mon Sep 17 00:00:00 2001 From: Natalie Beams Date: Tue, 28 Jun 2016 17:03:02 -0500 Subject: [PATCH 2/2] update symbolic mappers --- pytential/symbolic/mappers.py | 67 ++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/pytential/symbolic/mappers.py b/pytential/symbolic/mappers.py index 8dc2e73b..b92368c7 100644 --- a/pytential/symbolic/mappers.py +++ b/pytential/symbolic/mappers.py @@ -1,4 +1,4 @@ -from __future__ import division, absolute_import +from __future__ import division, absolute_import, print_function __copyright__ = "Copyright (C) 2010-2013 Andreas Kloeckner" @@ -38,7 +38,7 @@ from pymbolic.mapper.dependency import ( DependencyMapper as DependencyMapperBase) from pymbolic.mapper.coefficient import ( CoefficientCollector as CoefficientCollectorBase) -from pymbolic.geometric_algebra import MultiVector +from pymbolic.geometric_algebra import MultiVector, componentwise from pymbolic.geometric_algebra.mapper import ( CombineMapper as CombineMapperBase, IdentityMapper as IdentityMapperBase, @@ -181,34 +181,41 @@ class EvaluationMapper(EvaluationMapperBase): map_ones = map_variable def map_node_sum(self, expr): - return type(expr)(self.rec(expr.operand)) + return componentwise(type(expr), self.rec(expr.operand)) def map_node_coordinate_component(self, expr): return expr def map_num_reference_derivative(self, expr): - return type(expr)(expr.ref_axes, self.rec(expr.operand), expr.where) + return componentwise( + lambda subexpr: type(expr)( + expr.ref_axes, self.rec(subexpr), expr.where), + expr.operand) def map_int_g(self, expr): - return type(expr)( - expr.kernel, - self.rec(expr.density), - expr.qbx_forced_limit, expr.source, expr.target, - kernel_arguments=dict( - (name, self.rec(arg_expr)) - for name, arg_expr in expr.kernel_arguments.items() - )) + return componentwise( + lambda subexpr: type(expr)( + expr.kernel, + self.rec(subexpr), + expr.qbx_forced_limit, expr.source, expr.target, + kernel_arguments=dict( + (name, self.rec(arg_expr)) + for name, arg_expr in expr.kernel_arguments.items() + )), + expr.density) def map_int_g_ds(self, expr): - return type(expr)( - self.rec(expr.dsource), - expr.kernel, - self.rec(expr.density), - expr.qbx_forced_limit, expr.source, expr.target, - kernel_arguments=dict( - (name, self.rec(arg_expr)) - for name, arg_expr in expr.kernel_arguments.items() - )) + return componentwise( + lambda subexpr: type(expr)( + self.rec(expr.dsource), + expr.kernel, + self.rec(subexpr), + expr.qbx_forced_limit, expr.source, expr.target, + kernel_arguments=dict( + (name, self.rec(arg_expr)) + for name, arg_expr in expr.kernel_arguments.items() + )), + expr.density) def map_common_subexpression(self, expr): return prim.cse( @@ -439,14 +446,16 @@ class Dimensionalizer(DimensionalizerBase, EvaluationMapper): def map_int_g(self, expr): from sumpy.kernel import KernelDimensionSetter - return type(expr)( - KernelDimensionSetter(self.ambient_dim)(expr.kernel), - self.rec(expr.density), - expr.qbx_forced_limit, expr.source, expr.target, - kernel_arguments=dict( - (name, self.rec(arg_expr)) - for name, arg_expr in expr.kernel_arguments.items() - )) + return componentwise( + lambda subexpr: type(expr)( + KernelDimensionSetter(self.ambient_dim)(expr.kernel), + self.rec(subexpr), + expr.qbx_forced_limit, expr.source, expr.target, + kernel_arguments=dict( + (name, self.rec(arg_expr)) + for name, arg_expr in expr.kernel_arguments.items() + )), + expr.density) def map_int_g_ds(self, expr): dsource = self.rec(expr.dsource) -- GitLab