Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Commit

Permalink
Adapt hedge to current pymbolic
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Nov 24, 2014
1 parent 72c2f76 commit 95ea5bb
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 18 deletions.
3 changes: 3 additions & 0 deletions hedge/__init__.py
Expand Up @@ -22,6 +22,9 @@
THE SOFTWARE.
"""

import pymbolic
pymbolic.disable_subscript_by_getitem()

# make sure numpy-to-C++ converters are available
import pyublas

Expand Down
10 changes: 5 additions & 5 deletions hedge/backends/cuda/vector_expr.py
Expand Up @@ -39,9 +39,9 @@
class CompiledVectorExpression(CompiledVectorExpressionBase):
elementwise_mod = pycuda.elementwise

def __init__(self, vec_expr_info_list, result_dtype_getter,
def __init__(self, vec_expr_info_list, result_dtype_getter,
stream=None, allocator=drv.mem_alloc):
CompiledVectorExpressionBase.__init__(self,
CompiledVectorExpressionBase.__init__(self,
vec_expr_info_list, result_dtype_getter)

self.stream = stream
Expand All @@ -52,9 +52,9 @@ def make_kernel_internal(self, args, instructions):
return get_elwise_kernel(args, instructions, name="vector_expression")

def __call__(self, evaluate_subexpr, stats_callback=None):
vectors = [evaluate_subexpr(vec_expr)
vectors = [evaluate_subexpr(vec_expr)
for vec_expr in self.vector_deps]
scalars = [evaluate_subexpr(scal_expr)
scalars = [evaluate_subexpr(scal_expr)
for scal_expr in self.scalar_deps]

from pytools import single_valued
Expand Down Expand Up @@ -92,7 +92,7 @@ def __call__(self, evaluate_subexpr, stats_callback=None):
from pymbolic import parse
expr = parse("2*x+3*y+4*z")
print expr
cexpr = CompiledVectorExpression(expr,
cexpr = CompiledVectorExpression(expr,
lambda expr: (True, test_dtype),
test_dtype)

Expand Down
2 changes: 1 addition & 1 deletion hedge/backends/jit/flux.py
Expand Up @@ -53,7 +53,7 @@ def map_field_component(self, expr):
return 0
else:
from pymbolic import var
return var(arg_name+"_it")[var(where+"_idx")]
return var(arg_name+"_it").index(var(where+"_idx"))

def map_scalar_parameter(self, expr):
from pymbolic import var
Expand Down
4 changes: 2 additions & 2 deletions hedge/backends/vector_expr.py
Expand Up @@ -164,11 +164,11 @@ def is_vector_pred(dep):

var_i = var("i")
subst_map = dict(
list(zip(self.vector_deps, [var(vecname)[var_i]
list(zip(self.vector_deps, [var(vecname).index(var_i)
for vecname in self.vector_dep_names]))
+list(zip(self.scalar_deps,
[var(scaname) for scaname in self.scalar_dep_names]))
+[(var(vei.name), var(vei.name)[var_i])
+[(var(vei.name), var(vei.name).index(var_i))
for vei in vec_expr_info_list
if not vei.do_not_return])

Expand Down
8 changes: 0 additions & 8 deletions hedge/flux/__init__.py
Expand Up @@ -26,7 +26,6 @@
import numpy
import pymbolic.primitives
import pymbolic.mapper.collector
import pymbolic.mapper.expander
import pymbolic.mapper.flattener
import pymbolic.mapper.substitutor
import pymbolic.mapper.constant_folder
Expand Down Expand Up @@ -384,13 +383,6 @@ def is_constant(self, expr):
return not bool(FluxAllDependencyMapper()(expr))


class FluxExpandMapper(pymbolic.mapper.expander.ExpandMapper,
FluxIdentityMapperMixin):
def __init__(self):
pymbolic.mapper.expander.ExpandMapper.__init__(self,
FluxNormalizationMapper())


class FluxFlipper(FluxIdentityMapper):
def map_field_component(self, expr):
return expr.__class__(expr.index, not expr.is_interior)
Expand Down
2 changes: 1 addition & 1 deletion hedge/tools/mathematics.py
Expand Up @@ -110,7 +110,7 @@ def subset_indices(subset):
for k, k_real in enumerate(subset_indices(op2_subset)):
lc = levi_civita((i, j_real, k_real))
if lc != 0:
this_expr += lc*op1[j]*op2[k]
this_expr += lc*op1.index(j)*op2.index(k)
this_component.append((lc, j, k))
self.functions.append(pymbolic.compile(this_expr,
variables=[op1, op2]))
Expand Down
2 changes: 1 addition & 1 deletion test/test_jit_discretization.py
Expand Up @@ -965,7 +965,7 @@ def laplace(expression, variables):
pymbolic.diff(expression, var), var)
for var in variables)

rhs = laplace(truesol, [v_x[0], v_x[1]])
rhs = laplace(truesol, [v_x.index(0), v_x.index(1)])
rhs_c = pymbolic.compile(rhs, variables=["x", "el"])

from hedge.mesh import TAG_ALL, TAG_NONE
Expand Down

0 comments on commit 95ea5bb

Please sign in to comment.