def check_domain(self, p, flattened=False):
    "Check the validity of a parameter.\n\n        :class:`.Variable` instances can represent any real scalars (but not arrays).\n\n        Args:\n            p (Number, array, Variable): parameter to check\n            flattened (bool): True means p is an element of a flattened parameter\n                sequence (affects the handling of 'A' parameters)\n        Raises:\n            TypeError: parameter is not an element of the expected domain\n            ValueError: parameter is an element of an unknown domain\n        Returns:\n            Number, array, Variable: p\n        "
    if (isinstance(p, np.ndarray) and (p.ndim == 0)):
        p = p.item()
    if isinstance(p, Variable):
        if (self.par_domain == 'A'):
            raise TypeError('{}: Array parameter expected, got a Variable, which can only represent real scalars.'.format(self.name))
        return p
    if (self.par_domain == 'A'):
        if flattened:
            if isinstance(p, np.ndarray):
                raise TypeError('{}: Flattened array parameter expected, got {}.'.format(self.name, type(p)))
        elif (not isinstance(p, np.ndarray)):
            raise TypeError('{}: Array parameter expected, got {}.'.format(self.name, type(p)))
    elif (self.par_domain in ('R', 'N')):
        if (not isinstance(p, numbers.Real)):
            raise TypeError('{}: Real scalar parameter expected, got {}.'.format(self.name, type(p)))
        if (self.par_domain == 'N'):
            if (not isinstance(p, numbers.Integral)):
                raise TypeError('{}: Natural number parameter expected, got {}.'.format(self.name, type(p)))
            if (p < 0):
                raise TypeError('{}: Natural number parameter expected, got {}.'.format(self.name, p))
    elif (self.par_domain == 'L'):
        if (not isinstance(p, list)):
            raise TypeError('{}: List parameter expected, got {}.'.format(self.name, type(p)))
        if (not all((isinstance(elem, np.ndarray) for elem in p))):
            raise TypeError('List elements must be Numpy arrays.')
    else:
        raise ValueError("{}: Unknown parameter domain '{}'.".format(self.name, self.par_domain))
    return p
Check the validity of a parameter.

:class:`.Variable` instances can represent any real scalars (but not arrays).

Args:
    p (Number, array, Variable): parameter to check
    flattened (bool): True means p is an element of a flattened parameter
        sequence (affects the handling of 'A' parameters)
Raises:
    TypeError: parameter is not an element of the expected domain
    ValueError: parameter is an element of an unknown domain
Returns:
    Number, array, Variable: p
def check_domain(self, p, flattened=False):
    "Check the validity of a parameter.\n\n        :class:`.Variable` instances can represent any real scalars (but not arrays).\n\n        Args:\n            p (Number, array, Variable): parameter to check\n            flattened (bool): True means p is an element of a flattened parameter\n                sequence (affects the handling of 'A' parameters)\n        Raises:\n            TypeError: parameter is not an element of the expected domain\n            ValueError: parameter is an element of an unknown domain\n        Returns:\n            Number, array, Variable: p\n        "
    if (isinstance(p, np.ndarray) and (p.ndim == 0)):
        p = p.item()
    if isinstance(p, Variable):
        if (self.par_domain == 'A'):
            raise TypeError('{}: Array parameter expected, got a Variable, which can only represent real scalars.'.format(self.name))
        return p
    if (self.par_domain == 'A'):
        if flattened:
            if isinstance(p, np.ndarray):
                raise TypeError('{}: Flattened array parameter expected, got {}.'.format(self.name, type(p)))
        elif (not isinstance(p, np.ndarray)):
            raise TypeError('{}: Array parameter expected, got {}.'.format(self.name, type(p)))
    elif (self.par_domain in ('R', 'N')):
        if (not isinstance(p, numbers.Real)):
            raise TypeError('{}: Real scalar parameter expected, got {}.'.format(self.name, type(p)))
        if (self.par_domain == 'N'):
            if (not isinstance(p, numbers.Integral)):
                raise TypeError('{}: Natural number parameter expected, got {}.'.format(self.name, type(p)))
            if (p < 0):
                raise TypeError('{}: Natural number parameter expected, got {}.'.format(self.name, p))
    elif (self.par_domain == 'L'):
        if (not isinstance(p, list)):
            raise TypeError('{}: List parameter expected, got {}.'.format(self.name, type(p)))
        if (not all((isinstance(elem, np.ndarray) for elem in p))):
            raise TypeError('List elements must be Numpy arrays.')
    else:
        raise ValueError("{}: Unknown parameter domain '{}'.".format(self.name, self.par_domain))
    return p