theano/sandbox/rng_mrg.py
def _check_size(size):
    """
    Canonicalise inputs to get valid output sizes for Theano tensors.

    Parameters
    ----------
    size : int_vector_like
        Some variable that could serve as the shape for a Theano tensor.
        This can be an int, a tuple of ints, a list of ints
        or a Theano Variable with similar properties.

    Returns
    -------
    size_var : int_vector
        A one-dimensional Theano variable encapsulating the given size.

    Raises
    ------
    ValueError
        If this method can not build a valid size from the input.
    """
    # non-tuple checks and scalar-to-tuple transform
    if isinstance(size, theano.Variable):
        if size.ndim == 1:
            return size
        elif size.ndim == 0:
            return tensor.stack([size], ndim=1)
        else:
            raise ValueError("Theano variable must have 1 dimension to be a valid size.", size)
    elif isinstance(size, (np.integer, integer_types)):
        return tensor.constant([size], ndim=1)
    elif not isinstance(size, (tuple, list)):
        raise ValueError("Size must be a int, tuple, list or Theano variable.", size)

    # check entries of list or tuple
    for i in size:
        if isinstance(i, theano.Variable):
            if i.ndim != 0:
                raise ValueError("Non-scalar Theano variable in size", size, i)
        elif isinstance(i, (np.integer, integer_types)):
            if i <= 0:
                raise ValueError("Non-positive dimensions not allowed in size.", size, i)
        else:
            raise ValueError("Only Theano variables and integers are allowed in a size-tuple.", size, i)

    return tensor.as_tensor_variable(size, ndim=1)

    Canonicalise inputs to get valid output sizes for Theano tensors.

    Parameters
    ----------
    size : int_vector_like
        Some variable that could serve as the shape for a Theano tensor.
        This can be an int, a tuple of ints, a list of ints
        or a Theano Variable with similar properties.

    Returns
    -------
    size_var : int_vector
        A one-dimensional Theano variable encapsulating the given size.

    Raises
    ------
    ValueError
        If this method can not build a valid size from the input.
    
Canonicalise inputs to get valid output sizes for Theano tensors.
Parameters

size : int_vector_like
Some variable that could serve as the shape for a Theano tensor.
This can be an int, a tuple of ints, a list of ints
or a Theano Variable with similar properties.

Returns

size_var : int_vector
A one-dimensional Theano variable encapsulating the given size.

Raises

ValueError
If this method can not build a valid size from the input.
Canonicalise inputs to get valid output sizes for Theano tensors . Parameters size : int_vector_like Some variable that could serve as the shape for a Theano tensor . This can be an int a tuple of ints a list of ints or a Theano Variable with similar properties . Returns size_var : int_vector A one - dimensional Theano variable encapsulating the given size . Raises ValueError If this method can not build a valid size from the input .
def _check_size(size):
    if isinstance(size, theano.Variable):
        if size.ndim == 1:
            return size
        elif size.ndim == 0:
            return tensor.stack([size], ndim=1)
        else:
            raise ValueError("Theano variable must have 1 dimension to be a valid size.", size)
    elif isinstance(size, (np.integer, integer_types)):
        return tensor.constant([size], ndim=1)
    elif not isinstance(size, (tuple, list)):
        raise ValueError("Size must be a int, tuple, list or Theano variable.", size)
    for i in size:
        if isinstance(i, theano.Variable):
            if i.ndim != 0:
                raise ValueError("Non-scalar Theano variable in size", size, i)
        elif isinstance(i, (np.integer, integer_types)):
            if i <= 0:
                raise ValueError("Non-positive dimensions not allowed in size.", size, i)
        else:
            raise ValueError("Only Theano variables and integers are allowed in a size-tuple.", size, i)
    return tensor.as_tensor_variable(size, ndim=1)
def _check_size ( size ) : if isinstance ( size , theano . Variable ) : if size . ndim == 1 : return size elif size . ndim == 0 : return tensor . stack ( [ size ] , ndim = 1 ) else : raise ValueError ( "Theano variable must have 1 dimension to be a valid size." , size ) elif isinstance ( size , ( np . integer , integer_types ) ) : return tensor . constant ( [ size ] , ndim = 1 ) elif not isinstance ( size , ( tuple , list ) ) : raise ValueError ( "Size must be a int, tuple, list or Theano variable." , size ) for i in size : if isinstance ( i , theano . Variable ) : if i . ndim != 0 : raise ValueError ( "Non-scalar Theano variable in size" , size , i ) elif isinstance ( i , ( np . integer , integer_types ) ) : if i <= 0 : raise ValueError ( "Non-positive dimensions not allowed in size." , size , i ) else : raise ValueError ( "Only Theano variables and integers are allowed in a size-tuple." , size , i ) return tensor . as_tensor_variable ( size , ndim = 1 )
Canonicalise inputs to get valid output sizes for Theano tensors.
Canonicalise inputs to get valid output sizes for Theano tensors .
"""
    Canonicalise inputs to get valid output sizes for Theano tensors.

    Parameters
    ----------
    size : int_vector_like
        Some variable that could serve as the shape for a Theano tensor.
        This can be an int, a tuple of ints, a list of ints
        or a Theano Variable with similar properties.

    Returns
    -------
    size_var : int_vector
        A one-dimensional Theano variable encapsulating the given size.

    Raises
    ------
    ValueError
        If this method can not build a valid size from the input.
    """ # non-tuple checks and scalar-to-tuple transform # check entries of list or tuple
size