From 9c834c5ee49b53aab77bdb0574bed5c2e7e53df2 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sat, 17 Jun 2017 21:46:25 -0500 Subject: [PATCH 1/2] Target association: Fix enum duplication (closes #44 on gitlab). --- pytential/qbx/target_assoc.py | 42 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/pytential/qbx/target_assoc.py b/pytential/qbx/target_assoc.py index 22b2351b..e866ea45 100644 --- a/pytential/qbx/target_assoc.py +++ b/pytential/qbx/target_assoc.py @@ -35,6 +35,7 @@ import pyopencl.array # noqa from boxtree.tools import DeviceDataRecord from boxtree.area_query import AreaQueryElementwiseTemplate from boxtree.tools import InlineBinarySearch +from cgen import Enum from pytential.qbx.utils import ( QBX_TREE_C_PREAMBLE, QBX_TREE_MAKO_DEFS) @@ -85,34 +86,21 @@ logger = logging.getLogger(__name__) # {{{ kernels -TARGET_ASSOC_DEFINES = r""" -enum TargetStatus -{ - UNMARKED, - MARKED_QBX_CENTER_PENDING, - MARKED_QBX_CENTER_FOUND -}; - -enum TargetFlag -{ - INTERIOR_OR_EXTERIOR_VOLUME_TARGET = 0, - INTERIOR_SURFACE_TARGET = -1, - EXTERIOR_SURFACE_TARGET = +1, - INTERIOR_VOLUME_TARGET = -2, - EXTERIOR_VOLUME_TARGET = +2 -}; -""" - +class target_status_enum(Enum): # noqa + c_name = "TargetStatus" + dtype = np.int32 + c_value_prefix = "" -class target_status_enum(object): # noqa - # NOTE: Must match "enum TargetStatus" above UNMARKED = 0 MARKED_QBX_CENTER_PENDING = 1 MARKED_QBX_CENTER_FOUND = 2 -class target_flag_enum(object): # noqa - # NOTE: Must match "enum TargetFlag" above +class target_flag_enum(Enum): # noqa + c_name = "TargetFlag" + dtype = np.int32 + c_value_prefix = "" + INTERIOR_OR_EXTERIOR_VOLUME_TARGET = 0 INTERIOR_SURFACE_TARGET = -1 EXTERIOR_SURFACE_TARGET = +1 @@ -120,6 +108,16 @@ class target_flag_enum(object): # noqa EXTERIOR_VOLUME_TARGET = +2 +def _generate_enum_code(enum): + return "\n".join(list(enum.generate())) + + +TARGET_ASSOC_DEFINES = "".join([ + _generate_enum_code(target_status_enum), + _generate_enum_code(target_flag_enum), +]) + + QBX_TARGET_MARKER = AreaQueryElementwiseTemplate( extra_args=r""" /* input */ -- GitLab From 5ca2ba235c5a16527af205f5fd27a5834ed73a95 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sat, 17 Jun 2017 21:56:21 -0500 Subject: [PATCH 2/2] Remove an unnecessary call to list(). --- pytential/qbx/target_assoc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytential/qbx/target_assoc.py b/pytential/qbx/target_assoc.py index e866ea45..5e1bcb1e 100644 --- a/pytential/qbx/target_assoc.py +++ b/pytential/qbx/target_assoc.py @@ -109,7 +109,7 @@ class target_flag_enum(Enum): # noqa def _generate_enum_code(enum): - return "\n".join(list(enum.generate())) + return "\n".join(enum.generate()) TARGET_ASSOC_DEFINES = "".join([ -- GitLab