From afbe7f6bc6dea428853cf0318919f030104651dc Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Wed, 30 Mar 2016 17:38:02 -0500 Subject: [PATCH] Add InstructionBase.assignee_name --- loopy/kernel/data.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/loopy/kernel/data.py b/loopy/kernel/data.py index a2ef8fd83..0e0638491 100644 --- a/loopy/kernel/data.py +++ b/loopy/kernel/data.py @@ -502,6 +502,7 @@ class InstructionBase(Record): .. automethod:: __init__ .. automethod:: assignees_and_indices + .. automethod:: assignee_name .. automethod:: with_transformed_expressions .. automethod:: write_dependency_names .. automethod:: dependency_names @@ -616,6 +617,24 @@ class InstructionBase(Record): # }}} + @property + def assignee_name(self): + """A convenience wrapper around :meth:`assignees_and_indices` + that returns the the name of the variable being assigned. + If more than one variable is being modified in the instruction, + :raise:`ValueError` is raised. + """ + + aai = self.assignees_and_indices() + + if len(aai) != 1: + raise ValueError("expected exactly one assignment in instruction " + "on which assignee_name is being called, found %d" + % len(aai)) + + (name, _), = aai + return name + @memoize_method def write_dependency_names(self): """Return a set of dependencies of the left hand side of the -- GitLab