Beispiel #1
0
def _do_binary_operation(op, self, rhs, lhs_vars, inplace, reverse):
    """
        Perform the given binary operation

        :param op: A string containing the Mantid algorithm name
        :param self: The object that was the self argument when object.__op__(other) was called
        :param rhs: The object that was the other argument when object.__op__(other) was called
        :param lhs_vars: A tuple containing details of the lhs of the assignment, i.e a = b + c, lhs_vars = (1, 'a')
        :param inplace: True if the operation should be performed inplace
        :param reverse: True if the reverse operator was called, i.e. 3 + a calls __radd__

    """
    global _workspace_op_tmps
    #
    if lhs_vars[0] > 0:
        # Assume the first and clear the temporaries as this
        # must be the final assignment
        if inplace:
            output_name = self.name()
        else:
            output_name = lhs_vars[1][0]
        clear_tmps = True
    else:
        # Give it a temporary name and keep track of it
        clear_tmps = False
        output_name = _workspace_op_prefix + str(len(_workspace_op_tmps))

    # Do the operation
    resultws = performBinaryOp(self, rhs, op, output_name, inplace, reverse)

    # Do we need to clean up
    if clear_tmps:
        ads = AnalysisDataServiceImpl.Instance()
        for name in _workspace_op_tmps:
            if name in ads and output_name != name:
                del ads[name]
        _workspace_op_tmps = []
    else:
        if type(resultws) == WorkspaceGroup:
            # Ensure the members are removed aswell
            members = resultws.getNames()
            for member in members:
                _workspace_op_tmps.append(member)
        else:
            _workspace_op_tmps.append(output_name)

    return resultws  # For self-assignment this will be set to the same workspace
Beispiel #2
0
def _do_binary_operation(op, self, rhs, lhs_vars, inplace, reverse):
    """
        Perform the given binary operation

        :param op: A string containing the Mantid algorithm name
        :param self: The object that was the self argument when object.__op__(other) was called
        :param rhs: The object that was the other argument when object.__op__(other) was called
        :param lhs_vars: A tuple containing details of the lhs of the assignment, i.e a = b + c, lhs_vars = (1, 'a')
        :param inplace: True if the operation should be performed inplace
        :param reverse: True if the reverse operator was called, i.e. 3 + a calls __radd__

    """
    global _workspace_op_tmps
    #
    if lhs_vars[0] > 0:
        # Assume the first and clear the temporaries as this
        # must be the final assignment
        if inplace:
            output_name = self.name()
        else:
            output_name = lhs_vars[1][0]
        clear_tmps = True
    else:
        # Give it a temporary name and keep track of it
        clear_tmps = False
        output_name = _workspace_op_prefix + str(len(_workspace_op_tmps))

    # Do the operation
    resultws = performBinaryOp(self, rhs, op, output_name, inplace, reverse)

    # Do we need to clean up
    if clear_tmps:
        ads = AnalysisDataServiceImpl.Instance()
        for name in _workspace_op_tmps:
            if name in ads and output_name != name:
                del ads[name]
        _workspace_op_tmps = []
    else:
        if type(resultws) == WorkspaceGroup:
            # Ensure the members are removed aswell
            members = resultws.getNames()
            for member in members:
                _workspace_op_tmps.append(member)
        else:
            _workspace_op_tmps.append(output_name)

    return resultws  # For self-assignment this will be set to the same workspace