Signals

class nengo_dl.signals.TensorSignal(indices, key, dtype, shape, minibatch_size, label='TensorSignal')[source]

Represents a tensor as an indexed view into a base array.

Parameters:
indices : tuple or list or ndarray of 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

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 axis for 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

load_indices(constant=None)[source]

Loads the indices for this signal into TensorFlow.

If the indices form a contiguous slice then also loads the start/stop/step of that slice.

Parameters:
constant : callable, optional

A function that returns a TensorFlow constant (this is mainly used with SignalDict.constant())

full_shape

Shape including the minibatch dimension.

minibatched

Whether or not this TensorSignal contains a minibatch dimension.

class nengo_dl.signals.SignalDict(sig_map, dtype, minibatch_size)[source]

Handles the mapping from Signal to tf.Tensor.

Takes care of gather/scatter logic to read/write signals within the base arrays.

Parameters:
sig_map : dict of {Signal: TensorSignal}

Mapping from nengo signals to nengo_dl signals

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 dst with val

gather(src, force_copy=False)[source]

Fetches the data corresponding to src from 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=False does 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

mark_gather(src)[source]

Marks src as being gathered, but doesn’t actually perform a gather. Used to indicate that some computation relies on src.

Parameters:
src : TensorSignal

Signal indicating the data being read

combine(sigs, load_indices=True, label='Combine')[source]

Combines several TensorSignals into one by concatenating along the first axis.

Parameters:
sigs : list of TensorSignal or Signal

Signals to be combined

load_indices : bool, optional

If True, load the indices for the new signal into TensorFlow right away (otherwise they will need to be manually loaded later)

label : str, optional

Name for combined signal (to help with debugging)

Returns:
:class:`.TensorSignal`

New TensorSignal representing the concatenation of the data in sigs

constant(value, dtype=None, cutoff=33554432)[source]

Returns a constant Tensor containing the given value.

The returned Tensor may be underpinned by a tf.constant op, or a tf.Variable that 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 of value will be used)

cutoff : int, optional

The size of constant (in bytes) for which we will switch from tf.constant to tf.Variable

Returns:
``tf.Tensor``

A tensor representing the given 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 attr for 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.