shared - defines theano.shared

  • class theano.compile.sharedvalue.SharedVariable[source]
  • Variable with Storage that is shared between functions that it appears in.These variables are meant to be created by registered shared constructors(see shared_constructor()).

The user-friendly constructor is shared()

  • getvalue(_self, borrow=False, return_internal_type=False)[source]
  • Parameters:
    • borrow (bool) – True to permit returning of an object aliased to internal memory.
    • return_internal_type (bool) – True to permit the returning of an arbitrary type object usedinternally to store the shared variable.

By default, return a copy of the data. If borrow=True (andreturn_internal_type=False), maybe it will return a copy.For tensor, it will always return a ndarray by default, so ifthe data is on the GPU, it will return a copy, but if the datais on the CPU, it will return the original data. If you doborrow=True and return_internal_type=True, it willalways return the original data, not a copy, but this can be aGPU object.

  • setvalue(_self, new_value, borrow=False)[source]
  • Parameters:
    • new_value (A compatible type for this shared variable.) – The new value.
    • borrow (bool) – True to use the new_value directly, potentially creating problemsrelated to aliased memory.

The new value will be seen by all functions using this SharedVariable.

  • init(self, name, type, value, strict, container=None)[source]
  • Parameters:
    • name (None or str) – The name for this variable.
    • type – The Type for this Variable.
    • value – A value to associate with this variable (a new container will be created).
    • strict – True -> assignments to self.value will not be castedor copied, so they must have the correct type or an exception will beraised.
    • container – The container to use for this variable. This shouldinstead of the value parameter. Using both is an error.
  • container[source]
  • A container to use for this SharedVariable when it is an implicit function parameter.

Type:class:Container

  • theano.compile.sharedvalue.shared(value, name=None, strict=False, allow_downcast=None, **kwargs)[source]
  • Return a SharedVariable Variable, initialized with a copy orreference of value.

This function iterates over constructor functions to find asuitable SharedVariable subclass. The suitable one is the firstconstructor that accept the given value. See the documentation ofshared_constructor() for the definition of a constructorfunction.

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

theano.shared is a shortcut to this function.

  • theano.compile.sharedvalue.constructors[source]
  • A list of shared variable constructors that will be tried in reverseorder.

Notes

By passing kwargs, you effectively limit the set of potential constructorsto those that can accept those kwargs.

Some shared variable have borrow as extra kwargs.See for details.

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

  • theano.compile.sharedvalue.sharedconstructor(_ctor)[source]
  • Append ctor to the list of shared constructors (see shared()).

Each registered constructor ctor will be called like this:

  1. ctor(value, name=name, strict=strict, **kwargs)

If it do not support given value, it must raise a TypeError.