def test_kernelfunctor_str(): '''Check the str method of the KernelFunctor class.''' symbol = DataTypeSymbol("hello", StructureType()) arg = Reference(Symbol("dummy")) klr = KernelFunctor.create(symbol, [arg]) assert klr.__str__() == "KernelFunctor[name='hello']"
def test_kernelfunctor_node_str(): '''Check the node_str method of the KernelFunctor class.''' symbol = DataTypeSymbol("hello", StructureType()) arg = Reference(Symbol("dummy")) klr = KernelFunctor.create(symbol, [arg]) coloredtext = colored("KernelFunctor", KernelFunctor._colour) assert klr.node_str() == coloredtext + "[name='hello']"
def test_kernelfunctor_create_invalid_args1(): '''Check that the create method of KernelFunctor raises the expected exception if the provided 'arguments' argument is not a list. ''' symbol = DataTypeSymbol("hello", StructureType()) with pytest.raises(GenerationError) as info: _ = KernelFunctor.create(symbol, "Not a list") assert ("KernelFunctor create() arguments argument should be a list " "but found 'str'." in str(info.value))
def test_kernelfunctor_create_invalid_symbol(): '''Check that the create method of KernelFunctor raises the expected exception if the provided symbol argument is not the correct type. ''' symbol = Symbol("hello") with pytest.raises(GenerationError) as info: _ = KernelFunctor.create(symbol, []) assert ("KernelFunctor create() symbol argument should be a DataTypeSymbol" " but found 'Symbol'." in str(info.value))
def test_kernelfunctor_invalid_args2(): '''Check that the create method of KernelFunctor raises the expected exception if its supplied list of children are not the expected type (tests _validate_child method and _children_valid_format variable) ''' symbol = DataTypeSymbol("hello", StructureType()) with pytest.raises(GenerationError) as info: _ = KernelFunctor.create(symbol, ["hello"]) assert ("Item 'str' can't be child 0 of 'KernelFunctor'. The valid " "format is: '[DataNode]*'." in str(info.value))
def test_kernelfunctor_create(cls): '''Check that the create method of KernelFunctor works as expected. ''' symbol = DataTypeSymbol("hello", StructureType()) klr = cls.create(symbol, []) # pylint: disable=unidiomatic-typecheck assert type(klr) is cls assert klr._symbol == symbol assert len(klr.children) == 0 arg = Reference(Symbol("dummy")) klr = KernelFunctor.create(symbol, [arg]) assert len(klr.children) == 1 assert klr.children[0] == arg assert arg.parent == klr
def apply(self, call, index, options=None): ''' Apply the transformation to the supplied node. :param call: a PSyIR call node capturing an invoke call in \ generic PSyIR. :type call: :py:class:`psyclone.psyir.nodes.Call` :param int index: the position of this invoke call relative to \ other invokes in the algorithm layer. :param options: a dictionary with options for transformations. :type options: dictionary of string:values or None ''' self.validate(call, options=options) kernel_calls = [] for call_arg in call.children: arg_info = [] if isinstance(call_arg, ArrayReference): # Structure constructor mis-parsed as an array # reference. type_symbol = call_arg.symbol args = call_arg.pop_all_children() arg_info.append((type_symbol, args)) else: # CodeBlock containing a structure constructor for fp2_node in call_arg._fp2_nodes: type_symbol = self._get_symbol(call, fp2_node) args = self._parse_args(call_arg, fp2_node) arg_info.append((type_symbol, args)) for (type_symbol, args) in arg_info: self._specialise_symbol(type_symbol) kernel_calls.append(KernelFunctor.create(type_symbol, args)) invoke_call = AlgorithmInvokeCall.create(call.routine, kernel_calls, index) call.replace_with(invoke_call)