Signals¶
-
class
nengo_dl.signals.TensorSignal(indices, key, dtype, shape, minibatch_size, constant, label='TensorSignal')[source]¶ Represents a tensor as an indexed view into a base array.
Parameters: - indices : tuple or list or
ndarrayof int Indices along the first axis of the base array corresponding to the data for this signal
- key : object
Key mapping to the base array that contains the data for this signal
- dtype :
dtype dtype of the values represented by this signal
- shape : tuple of int
View shape of this signal (may differ from shape of base array)
- minibatch_size : int
If not None then this signal contains a minibatch dimension with the given size
- constant : callable
A function that returns a TensorFlow constant (will be provided by
signals.SignalDict.get_tensor_signal())- label : str, optional
Name for this signal, used to make debugging easier
-
__getitem__(indices)[source]¶ Create a new TensorSignal representing a subset (slice or advanced indexing) of the indices of this TensorSignal.
Parameters: - indices : slice or list of int
The desired subset of the indices in this TensorSignal
Returns: - :class:`.signals.TensorSignal`
A new TensorSignal representing the subset of this TensorSignal
-
reshape(shape)[source]¶ Create a new TensorSignal representing a reshaped view of the same data in this TensorSignal (size of data must remain unchanged).
Parameters: - shape : tuple of int
New shape for the signal (one dimension can be -1 to indicate an inferred dimension size, as in numpy)
Returns: - :class:`.signals.TensorSignal`
New TensorSignal representing the same data as this signal but with the given shape
-
broadcast(axis, length)[source]¶ Add a new dimension by broadcasting this signal along
axisfor the given length.Parameters: - axis : 0 or -1
Where to insert the new dimension (currently only supports either the beginning or end of the array)
- length : int
The number of times to duplicate signal along the broadcast dimension
Returns: - :class:`.signals.TensorSignal`
TensorSignal with new broadcasted shape
-
full_shape¶ Shape including the minibatch dimension.
-
minibatched¶ Whether or not this TensorSignal contains a minibatch dimension.
- indices : tuple or list or
-
class
nengo_dl.signals.SignalDict(dtype, minibatch_size)[source]¶ Handles the mapping from
Signaltotf.Tensor.Takes care of gather/scatter logic to read/write signals within the base arrays.
Parameters: - dtype :
tf.DType Floating point precision used in signals
- minibatch_size : int
Number of items in each minibatch
-
scatter(dst, val, mode='update')[source]¶ Updates the base data corresponding to
dst.Parameters: - dst :
TensorSignal Signal indicating the data to be modified in base array
- val :
tf.Tensor Update data (same shape as
dst, i.e. a dense array <= the size of the base array)- mode : “update” or “inc”
Overwrite/add the data at
dstwithval
- dst :
-
gather(src, force_copy=False)[source]¶ Fetches the data corresponding to
srcfrom the base array.Parameters: - src :
TensorSignal Signal indicating the data to be read from base array
- force_copy : bool, optional
If True, always perform a gather, not a slice (this forces a copy). Note that setting
force_copy=Falsedoes not guarantee that a copy won’t be performed.
Returns: - ``tf.Tensor``
Tensor object corresponding to a dense subset of data from the base array
- src :
-
mark_gather(src)[source]¶ Marks
srcas being gathered, but doesn’t actually perform a gather. Used to indicate that some computation relies onsrc.Parameters: - src :
TensorSignal Signal indicating the data being read
- src :
-
combine(sigs, label='Combine')[source]¶ Combines several TensorSignals into one by concatenating along the first axis.
Parameters: - sigs : list of
TensorSignalorSignal Signals to be combined
- label : str, optional
Name for combined signal (to help with debugging)
Returns: - :class:`.TensorSignal`
New TensorSignal representing the concatenation of the data in
sigs
- sigs : list of
-
get_tensor_signal(indices, key, dtype, shape, minibatched, signal=None, label='TensorSignal')[source]¶ Creates a new
TensorSignalwith the given properties.This should be used rather than instantiating a new TensorSignal directly, as it handles some extra book-keeping (e.g., using the custom
constant()function).Parameters: - indices : tuple or list or
ndarrayof int Indices along the first axis of the base array corresponding to the data for this signal
- key : object
Key mapping to the base array that contains the data for this signal
- dtype :
dtype dtype of the values represented by this signal
- shape : tuple of int
View shape of this signal (may differ from shape of base array)
- minibatched : bool
Whether or not this signal contains a minibatch dimension
- signal :
Signal, optional If not None, associate the new
TensorSignalwith the givenSignalin thesig_map- label : str, optional
Name for this signal, used to make debugging easier
Returns: - :class:`.TensorSignal`
A new
TensorSignalwith the given properties
- indices : tuple or list or
-
constant(value, dtype=None, cutoff=33554432)[source]¶ Returns a constant Tensor containing the given value.
The returned Tensor may be underpinned by a
tf.constantop, or atf.Variablethat will be initialized to the constant value. We use the latter in order to avoid storing large constant values in the TensorFlow GraphDef, which has a hard-coded limit of 2GB at the moment.Parameters: - value :
ndarray Array containing the value of the constant
- dtype :
tf.DType, optional The type for the constant (if
None, the dtype ofvaluewill be used)- cutoff : int, optional
The size of constant (in bytes) for which we will switch from
tf.constanttotf.Variable
Returns: - ``tf.Tensor``
A tensor representing the given value
- value :
-
op_constant(ops, op_sizes, attr, dtype, ndims=2)[source]¶ Creates a tensor representing the constant parameters of an op group.
Parameters: - ops : list of object
The operators for some merged group of ops
- op_sizes : list of int
The number of constant elements in each op
- attr : str
The attribute of the op that describes the constant parameter
- dtype :
tf.DType Numeric type of the parameter
- ndims : int
Empty dimensions will be added to the end of the returned tensor for all ndims > 1 (in the case that it is not a scalar).
Returns: - ``tf.Tensor``
Tensor containing the values of
attrfor the given ops. This will be a scalar if all the ops have the same parameter value, or an array giving the parameter value for each element in each op.
- dtype :