Esempio n. 1
0
    def _check_inputs(self, operators, weights):
        """Check inputs.

        This method cheks that the input operators and weights are correctly
        formatted.

        Parameters
        ----------
        operators : list, tuple or numpy.ndarray
            List of linear operator class instances
        weights : list, tuple or numpy.ndarray
            List of weights for combining the linear adjoint operator results

        Returns
        -------
        tuple
            Operators and weights

        Raises
        ------
        ValueError
            If the number of weights does not match the number of operators
        TypeError
            If the individual weight values are not floats

        """
        operators = self._check_type(operators)

        for operator in operators:

            if not hasattr(operator, 'op'):
                raise ValueError('Operators must contain "op" method.')

            if not hasattr(operator, 'adj_op'):
                raise ValueError('Operators must contain "adj_op" method.')

            operator.op = check_callable(operator.op)
            operator.cost = check_callable(operator.adj_op)

        if not isinstance(weights, type(None)):
            weights = self._check_type(weights)

            if weights.size != operators.size:
                raise ValueError(
                    'The number of weights must match the number of ' +
                    'operators.', )

            if not np.issubdtype(weights.dtype, np.floating):
                raise TypeError('The weights must be a list of float values.')

        return operators, weights
Esempio n. 2
0
    def _check_operators(self, operators):
        """Check operators.

        This method cheks that the input operators and weights are correctly
        formatted.

        Parameters
        ----------
        operators : list, tuple or numpy.ndarray
            List of linear operator class instances

        Returns
        -------
        numpy.ndarray
            Operators

        Raises
        ------
        TypeError
            For invalid input type
        ValueError
            For empty list
        ValueError
            For missing op method
        ValueError
            For missing cost method

        """
        if not isinstance(operators, (list, tuple, np.ndarray)):
            raise TypeError(
                'Invalid input type, operators must be a list, tuple or '
                + 'numpy array.',
            )

        operators = np.array(operators)

        if not operators.size:
            raise ValueError('Operator list is empty.')

        for operator in operators:
            if not hasattr(operator, 'op'):
                raise ValueError('Operators must contain "op" method.')
            if not hasattr(operator, 'cost'):
                raise ValueError('Operators must contain "cost" method.')
            operator.op = check_callable(operator.op)
            operator.cost = check_callable(operator.cost)

        return operators
Esempio n. 3
0
    def _check_operators(self):
        """Check Operators

        This method checks if the input operators have a "cost" method

        Raises
        ------
        ValueError
            For invalid operators type
        ValueError
            For operators without "cost" method

        """

        if not isinstance(self._operators, (list, tuple, np.ndarray)):
            raise TypeError(('Input operators must be provided as a list, '
                             'not {}').format(type(self._operators)))

        for op in self._operators:
            if not hasattr(op, 'cost'):
                raise ValueError('Operators must contain "cost" method.')
            op.cost = check_callable(op.cost)
Esempio n. 4
0
    def cost(self, method):

        self._cost = check_callable(method)
Esempio n. 5
0
    def get_grad(self, method):

        self._get_grad = check_callable(method)
Esempio n. 6
0
    def trans_op(self, operator):

        self._trans_op = check_callable(operator)
Esempio n. 7
0
    def op(self, operator):

        self._op = check_callable(operator)