Exemple #1
0
def shared(value, name=None, strict=False, allow_downcast=None, **kwargs):
    """Return a SharedVariable Variable, initialized with a copy or
    reference of `value`.

    This function iterates over
    :ref:`constructor functions <shared_constructor>`
    to find a suitable SharedVariable subclass.
    The suitable one is the first constructor that accept the given value.

    This function is meant as a convenient default.  If you want to use a
    specific shared variable constructor, consider calling it directly.

    ``theano.shared`` is a shortcut to this function.

    :note: By passing kwargs, you effectively limit the set of
        potential constructors to those that can accept those kwargs.

    :note: Some shared variable have ``borrow`` as extra kwargs.
           `See <http://deeplearning.net/software/theano/tutorial/aliasing.html#borrowing-when-creating-shared-variables>`_ for detail.

    :note: Some shared variable have ``broadcastable`` as extra kwargs.
        As shared variable shapes can change, all dimensions default
        to not being broadcastable, even if ``value`` has a shape of 1
        along some dimension. This parameter allows you to create
        for example a `row` or `column` 2d tensor.

    .. attribute:: constructors

        A list of shared variable constructors that will be tried in reverse
        order.

    """

    try:
        if isinstance(value, Variable):
            raise TypeError(
                " Shared variable constructor needs numeric values and not symbolic variables."
            )

        for ctor in reversed(shared.constructors):
            try:
                var = ctor(value,
                           name=name,
                           strict=strict,
                           allow_downcast=allow_downcast,
                           **kwargs)
                utils.add_tag_trace(var)
                return var
            except TypeError:
                continue
            # This may happen when kwargs were supplied
            # if kwargs were given, the generic_constructor won't be callable.
            #
            # This was done on purpose, the rationale being that if kwargs
            # were supplied, the user didn't want them to be ignored.

    except MemoryError, e:
        e.args = e.args + ('you might consider'
                           ' using \'theano.shared(..., borrow=True)\'', )
        raise
Exemple #2
0
def shared(value, name=None, strict=False, allow_downcast=None, **kwargs):
    """Return a SharedVariable Variable, initialized with a copy or
    reference of `value`.

    This function iterates over
    :ref:`constructor functions <shared_constructor>`
    to find a suitable SharedVariable subclass.
    The suitable one is the first constructor that accept the given value.

    This function is meant as a convenient default.  If you want to use a
    specific shared variable constructor, consider calling it directly.

    ``theano.shared`` is a shortcut to this function.

    :note: By passing kwargs, you effectively limit the set of
        potential constructors to those that can accept those kwargs.

    :note: Some shared variable have ``borrow`` as extra kwargs.
           `See <http://deeplearning.net/software/theano/tutorial/aliasing.html#borrowing-when-creating-shared-variables>`_ for detail.

    :note: Some shared variable have ``broadcastable`` as extra kwargs.
        As shared variable shapes can change, all dimensions default
        to not being broadcastable, even if ``value`` has a shape of 1
        along some dimension. This parameter allows you to create
        for example a `row` or `column` 2d tensor.

    .. attribute:: constructors

        A list of shared variable constructors that will be tried in reverse
        order.

    """

    try:
        if isinstance(value, Variable):
            raise TypeError(" Shared variable constructor needs numeric values and not symbolic variables.")

        for ctor in reversed(shared.constructors):
            try:
                var = ctor(value, name=name, strict=strict,
                           allow_downcast=allow_downcast, **kwargs)
                utils.add_tag_trace(var)
                return var
            except TypeError:
                continue
            # This may happen when kwargs were supplied
            # if kwargs were given, the generic_constructor won't be callable.
            #
            # This was done on purpose, the rationale being that if kwargs
            # were supplied, the user didn't want them to be ignored.

    except MemoryError, e:
        e.args = e.args + ('you might consider'
                           ' using \'theano.shared(..., borrow=True)\'',)
        raise
Exemple #3
0
    def __call__(self, name=None):
        """Return a new `Variable` instance of Type `self`.

        :Parameters:
         - `name`: None or str
            A pretty string for printing and debugging.

        """
        return utils.add_tag_trace(self.make_variable(name))
Exemple #4
0
    def __call__(self, name = None):
        """Return a new `Variable` instance of Type `self`.

        :Parameters:
         - `name`: None or str
            A pretty string for printing and debugging.

        """
        return utils.add_tag_trace(self.make_variable(name))
Exemple #5
0
def shared(value, name=None, strict=False, allow_downcast=None, **kwargs):
    """Return a SharedVariable Variable, initialized with a copy or
    reference of `value`.

    This function iterates over constructor functions (see
    `shared_constructor`) to find a suitable SharedVariable subclass.

    :note: By passing kwargs, you effectively limit the set of
    potential constructors to those that can accept those kwargs.

    :note: Some shared variable have 'borrow' as extra kwargs.
           `See <http://deeplearning.net/software/theano/tutorial/aliasing.html#borrowing-when-creating-shared-variables>`_ for detail.

    """

    try:
        if isinstance(value, Variable):
            raise TypeError(
                " Shared variable constructor needs numeric values and not symbolic variables."
            )

        for ctor in reversed(shared.constructors):
            try:
                var = ctor(value,
                           name=name,
                           strict=strict,
                           allow_downcast=allow_downcast,
                           **kwargs)
                utils.add_tag_trace(var)
                return var
            except TypeError:
                continue
            # This may happen when kwargs were supplied
            # if kwargs were given, the generic_constructor won't be callable.
            #
            # This was done on purpose, the rationale being that if kwargs
            # were supplied, the user didn't want them to be ignored.

    except MemoryError, e:
        e.args = e.args + ('you might consider'
                           ' using \'theano.shared(..., borrow=True)\'', )
        raise
Exemple #6
0
def shared(value, name=None, strict=False, allow_downcast=None, **kwargs):
    """Return a SharedVariable Variable, initialized with a copy or
    reference of `value`.

    This function iterates over constructor functions (see
    `shared_constructor`) to find a suitable SharedVariable subclass.

    :note: By passing kwargs, you effectively limit the set of
    potential constructors to those that can accept those kwargs.

    :note: Some shared variable have 'borrow' as extra kwargs.
           `See <http://deeplearning.net/software/theano/tutorial/aliasing.html#borrowing-when-creating-shared-variables>`_ for detail.

    """

    try:
        if isinstance(value, Variable):
            raise TypeError(" Shared variable constructor needs numeric values and not symbolic variables.")

        for ctor in reversed(shared.constructors):
            try:
                var = ctor(value, name=name, strict=strict,
                           allow_downcast=allow_downcast, **kwargs)
                utils.add_tag_trace(var)
                return var
            except TypeError:
                continue
            # This may happen when kwargs were supplied
            # if kwargs were given, the generic_constructor won't be callable.
            #
            # This was done on purpose, the rationale being that if kwargs
            # were supplied, the user didn't want them to be ignored.

    except MemoryError, e:
        e.args = e.args + ('you might consider'
                           ' using \'theano.shared(..., borrow=True)\'',)
        raise
Exemple #7
0
 def __init__(self, type, data, name=None):
     Variable.__init__(self, type, None, None, name)
     self.data = type.filter(data)
     utils.add_tag_trace(self)
Exemple #8
0
 def __init__(self, type, data, name=None):
     super().__init__(type, None, None, name)
     self.data = type.filter(data)
     add_tag_trace(self)
Exemple #9
0
 def __init__(self, type, data, name=None):
     Variable.__init__(self, type, None, None, name)
     self.data = type.filter(data)
     utils.add_tag_trace(self)