ngraph package

ngraph module namespace, exposing factory functions for all ops and other classes.

Submodules

ngraph.exceptions module

ngraph exceptions hierarchy. All exceptions are descendants of NgraphError.

exception ngraph.exceptions.NgraphError[source]

Bases: exceptions.Exception

Base class for Ngraph exceptions.

exception ngraph.exceptions.NgraphTypeError[source]

Bases: ngraph.exceptions.NgraphError, exceptions.TypeError

Type mismatch error.

exception ngraph.exceptions.UserInputError[source]

Bases: ngraph.exceptions.NgraphError

User provided unexpected input.

ngraph.ops module

Factory functions for all ngraph ops.

ngraph.ops.absolute(node, name=None)[source]

Return node which applies f(x) = abs(x) to the input node element-wise.

Parameters:
  • node – One of: input node, array or scalar.
  • name – Optional new name for output node.
Returns:

New node with Abs operation applied on it.

ngraph.ops.acos(node, name=None)[source]

Apply inverse cosine function on the input node element-wise.

Parameters:
  • node – One of: input node, array or scalar.
  • name – Optional new name for output node.
Returns:

New node with arccos operation applied on it.

ngraph.ops.add(left_node, right_node, name=None)[source]

Return node which applies f(x) = A+B to the input nodes element-wise.

ngraph.ops.argmax(data, axis=0)[source]

Return a node which performs ArgMax index reduction operation.

Parameters:
  • data – Input data.
  • axis – Reduction Axis.
Returns:

The new node which performs ArgMax

ngraph.ops.argmin(data, axis=0)[source]

Return a node which performs ArgMin index reduction operation.

Parameters:
  • data – Input data.
  • axis – Reduction Axis.
Returns:

The new node which performs ArgMin

ngraph.ops.asin(node, name=None)[source]

Apply inverse sine function on the input node element-wise.

Parameters:
  • node – One of: input node, array or scalar.
  • name – Optional new name for output node.
Returns:

New node with arcsin operation applied on it.

ngraph.ops.atan(node, name=None)[source]

Apply inverse tangent function on the input node element-wise.

Parameters:
  • node – One of: input node, array or scalar.
  • name – Optional new name for output node.
Returns:

New node with arctan operation applied on it.

ngraph.ops.avg_pool(data_batch, window_shape, window_strides=None, padding_below=None, padding_above=None, include_padding=False, name=None)[source]

Return average pooling node.

Parameters:
  • data_batch – The input node providing data.
  • window_shape – The pooling window shape.
  • window_strides – The window movement strides.
  • padding_below – The input data optional padding below filled with zeros.
  • padding_above – The input data optional padding below filled with zeros.
  • include_padding – Whether or not to include zero padding in average computations.
  • name – Optional name for the new output node.
Returns:

New node with AvgPool operation applied on its data.

ngraph.ops.batch_norm(eps, gamma, beta, data, mean=None, variance=None, name=None)[source]

Return batch normalization node.

ngraph.ops.broadcast(node, new_shape, broadcast_axes, name=None)[source]

Create a node which broadcasts the input node’s values along specified axes to a desired shape.

Parameters:
  • node – The node with input tensor data.
  • new_shape – The new shape we want to broadcast tensor to.
  • broadcast_axes – The axis positions (0-based) in the result that are being broadcast.
  • name – Optional new name for output node.
Returns:

New node with broadcast shape.

ngraph.ops.broadcast_to(node, new_shape, axis=None, name=None)[source]

Create a node which broadcasts the input node’s values to a desired shape.

broadcast_to will attempt to automatically determine which axes need broadcasting.

The optional axis parameter specifies the starting axis position (0-based) in the output shape from which the current shape of the tensor matches the desired new shape.

e.g. current_shape: [4, 5], new_shape: [2, 3, 4, 5, 6], axis: 2

By using the axis parameter you can control which output axis to broadcast along.

Example:

>>> input_node = ng.constant([1, 2, 3])
>>> current_shape = [3]
>>> new_shape = [3, 3]
>>> ng.broadcast_to(input_node, new_shape, axis=1)
array([[1, 2, 3],
       [1, 2, 3],
       [1, 2, 3]])
>>> ng.broadcast_to(input_node, new_shape, axis=0)
array([[1, 1, 1],
       [2, 2, 2],
       [3, 3, 3]])

If the axis parameter is not specified, broadcast_to will attempt to match shapes, assuming the current shape matches the rightmost positions of the desired new shape. This behaviour is similar to NumPy’s broadcasting.

i.e. default axis = len(new_shape) - len(current_shape)

Parameters:
  • node – The node with input tensor data.
  • new_shape – The new shape we want to broadcast tensor to.
  • axis – The axis along which we perform broadcasting.
  • name – Optional new name for output node.
Returns:

New node with broadcast shape.

ngraph.ops.ceiling(node, name=None)[source]

Return node which applies ceiling to the input node element-wise.

Parameters:
  • node – The node providing data to ceiling operation.
  • name – Optional name for output node.
Returns:

The node performing element-wise ceiling.

ngraph.ops.concat(nodes, axis, name=None)[source]

Concatenate input nodes into single new node along specified axis.

Parameters:
  • nodes – The nodes we want concatenate into single new node.
  • axis – The axis along which we want to concatenate input nodes.
  • name – The optional new name for output node.
Returns:

Return new node that is a concatenation of input nodes.

ngraph.ops.constant(value, dtype=None, name=None)[source]

Create a Constant node from provided value.

Parameters:
  • value – One of: array of values or scalar to initialize node with.
  • dtype – The data type of provided data.
  • name – Optional name for output node.
Returns:

The Constant node initialized with provided data.

ngraph.ops.convert(node, new_type, name=None)[source]

Return node which casts input node values to specified type.

ngraph.ops.convolution(data_batch, filter_weights, filter_strides=None, filter_dilation_strides=None, padding_below=None, padding_above=None, data_dilation_strides=None, name=None)[source]

Return node performing batched convolution operation.

Parameters:
  • data_batch – The node providing data batch tensor.
  • filter_weights – The node providing filters tensor.
  • filter_strides – The kernel window movement strides.
  • filter_dilation_strides – The filters dilation strides.
  • padding_below – The number of zero padding elements to add on each axis below 0 coordinate.
  • padding_above – The number of zero padding elements to add on each axis above max coordinate.
  • data_dilation_strides – The data batch dilation strides.
  • name – The optional new name for output node.
Returns:

New node performing batched convolution operation.

ngraph.ops.convolution_backprop_data(data_batch_shape, filters, output_delta, window_movement_strides_forward=None, window_dilation_strides_forward=None, padding_below_forward=None, padding_above_forward=None, data_dilation_strides_forward=None, name=None)[source]

Return node performing a batched-convolution data batch-backprop operation.

Parameters:
  • data_batch_shape – The shape of the data batch from forward-prop.
  • filters – The node producing the filters from forward-prop.
  • output_delta – The node producing output delta.
  • window_movement_strides_forward – The window movement strides from forward-prop.
  • window_dilation_strides_forward – The window dilation strides from forward-prop.
  • padding_below_forward – The padding-below sizes from forward-prop.
  • padding_above_forward – The padding-above sizes from forward-prop.
  • data_dilation_strides_forward – The data dilation strides from forward-prop.
ngraph.ops.cos(node, name=None)[source]

Apply cosine function on the input node element-wise.

Parameters:
  • node – One of: input node, array or scalar.
  • name – Optional new name for output node.
Returns:

New node with cos operation applied on it.

ngraph.ops.cosh(node, name=None)[source]

Apply hyperbolic cosine function on the input node element-wise.

Parameters:
  • node – One of: input node, array or scalar.
  • name – Optional new name for output node.
Returns:

New node with cosh operation applied on it.

ngraph.ops.divide(left_node, right_node, name=None)[source]

Return node which applies f(x) = A/B to the input nodes element-wise.

Parameters:
  • left_node – The node providing dividend data.
  • right_node – The node providing divisor data.
  • name – Optional name for output node.
Returns:

The node performing element-wise division.

ngraph.ops.dot(left_node, right_node, reduction_axes_count=None, name=None)[source]

Return node which performs generalized dot product of two input nodes.

This operation is capable of performing scalar-tensor, matrix-vector product and matrix multiplication.

Parameters:
  • left_node – The node providing left hand side data.
  • right_node – The node providing right hand side data.
  • reduction_axes_count – The number of axes to reduce during dot-product.
  • name – The optional name for output node.
Returns:

The new node performing dot-product on input two nodes.

ngraph.ops.equal(left_node, right_node, name=None)[source]

Return node which checks if input nodes are equal element-wise.

Parameters:
  • left_node – The first input node for equal operation.
  • right_node – The second input node for equal operation.
  • name – The optional name for output new node.
Returns:

The node performing element-wise equality check.

ngraph.ops.exp(node, name=None)[source]

Return node which applies exp to the input node element-wise.

Parameters:
  • node – The node providing data for operation.
  • name – The optional name for new output node.
Returns:

The new node performing natural exponential operation.

ngraph.ops.floor(node, name=None)[source]

Return node which applies floor to the input node element-wise.

Parameters:
  • node – The input node providing data.
  • name – The optional name for new output node.
Returns:

The node performing element-wise floor operation.

ngraph.ops.get_output_element(data, index)[source]

Return the n-th element of the input tuple.

ngraph.ops.greater(left_node, right_node, name=None)[source]

Return node which checks if left input node is greater than the right node element-wise.

Parameters:
  • left_node – The first input node providing data.
  • right_node – The second input node providing data.
  • name – The optional new name for output node.
Returns:

The node performing element-wise check whether left_node is greater than right_node.

ngraph.ops.greater_eq(left_node, right_node, name=None)[source]

Return node which checks if left node is greater or equal to the right node element-wise.

Parameters:
  • left_node – The first input node providing data.
  • right_node – The second input node providing data.
  • name – The optional new name for output node.
Returns:

The node performing element-wise check whether left_node is greater than or equal right_node.

ngraph.ops.less(left_node, right_node, name=None)[source]

Return node which checks if left input node is less than the right node element-wise.

Parameters:
  • left_node – The first input node providing data.
  • right_node – The second input node providing data.
  • name – The optional new name for output node.
Returns:

The node performing element-wise check whether left_node is less than the right_node.

ngraph.ops.less_eq(left_node, right_node, name=None)[source]

Return node which checks if left input node is less or equal the right node element-wise.

Parameters:
  • left_node – The first input node providing data.
  • right_node – The second input node providing data.
  • name – The optional new name for output node.
Returns:

The node performing element-wise check whether left_node is less than or equal the right_node.

ngraph.ops.log(node, name=None)[source]

Return node which applies natural logarithm to the input node element-wise.

Parameters:
  • node – The input node providing data for operation.
  • name – The optional new name for output node.
Returns:

The new node performing log operation element-wise.

ngraph.ops.logical_and(left_node, right_node, name=None)[source]

Return node which perform logical and operation on input nodes element-wise.

Parameters:
  • left_node – The first input node providing data.
  • right_node – The second input node providing data.
  • name – The optional new name for output node.
Returns:

The node performing logical and operation on input nodes corresponding elements.

ngraph.ops.logical_not(node, name=None)[source]

Return node which applies logical negation to the input node elementwise.

ngraph.ops.logical_or(left_node, right_node, name=None)[source]

Return node which performs logical or operation on input nodes element-wise.

Parameters:
  • left_node – The first input node providing data.
  • right_node – The second input node providing data.
  • name – The optional new name for output node.
Returns:

The node performing logical or operation on input nodes corresponding elements.

ngraph.ops.lrn(data, alpha=1, beta=0.5, bias=1, size=5, name=None)[source]

Return a node which performs element-wise Local Response Normalization (LRN) operation.

Parameters:
  • data – Input data.
  • alpha – A scale factor (usually positive).
  • beta – An exponent.
  • bias – An offset (usually positive) to avoid dividing by 0.
  • size – Width of the 1-D normalization window.
  • name – An optional name of the output node.
Returns:

The new node which performs LRN.

ngraph.ops.max(node, reduction_axes=None, name=None)[source]

Max-reduction operation on input tensor, eliminating the specified reduction axes.

Parameters:
  • node – The tensor we want to max-reduce.
  • reduction_axes – The axes to eliminate through max operation.
  • name – Optional name for output node.
ngraph.ops.max_pool(x, window_shape, strides=None, padding_above=None, padding_below=None, name=None)[source]

Return max pooling node.

ngraph.ops.maximum(left_node, right_node, name=None)[source]

Return node which applies the maximum operation to input nodes elementwise.

ngraph.ops.min(node, reduction_axes=None, name=None)[source]

Min-reduction operation on input tensor, eliminating the specified reduction axes.

Parameters:
  • node – The tensor we want to min-reduce.
  • reduction_axes – The axes to eliminate through min operation.
  • name – Optional name for output node.
ngraph.ops.minimum(left_node, right_node, name=None)[source]

Return node which applies the minimum operation to input nodes elementwise.

ngraph.ops.multiply(left_node, right_node, name=None)[source]

Return node which applies f(x) = A*B to the input nodes elementwise.

ngraph.ops.negative(node, name=None)[source]

Return node which applies f(x) = -x to the input node elementwise.

ngraph.ops.not_equal(left_node, right_node, name=None)[source]

Return node which checks if input nodes are unequal element-wise.

Parameters:
  • left_node – The first input node for not-equal operation.
  • right_node – The second input node for not-equal operation.
  • name – The optional name for output new node.
Returns:

The node performing element-wise inequality check.

ngraph.ops.one_hot(node, shape, one_hot_axis, name=None)[source]

Create node performing one-hot encoding on input data.

Parameters:
  • node – The input node providing data for operation.
  • shape – The output node shape including the new one-hot axis.
  • one_hot_axis – The index within the output shape of the new one-hot axis.
  • name – The optional name for new output node.
Returns:

New node performing one-hot operation.

ngraph.ops.pad(data_batch, value, padding_below=None, padding_above=None, padding_in=None, name=None)[source]

Return padding node.

Parameters:
  • data_batch – The input node providing data.
  • value – The node producing the scalar value to be inserted for padding.
  • padding_below – The padding-below widths.
  • padding_above – The padding-above widths.
  • padding_in – The interior-padding widths.
  • name – The optional new name for output node.
Returns:

Return node that represents a padding of input nodes data.

ngraph.ops.parameter(shape, dtype=<type 'numpy.float32'>, name=None)[source]

Return an ngraph Parameter object.

ngraph.ops.power(left_node, right_node, name=None)[source]

Return node which perform element-wise exponentiation operation.

Parameters:
  • left_node – The node providing the base of operation.
  • right_node – The node providing the exponent of operation.
  • name – The optional name for the new output node.
Returns:

The new node performing element-wise exponentiation operation on input nodes.

ngraph.ops.prod(node, reduction_axes=None, name=None)[source]

Product-reduction operation on input tensor, eliminating the specified reduction axes.

Parameters:
  • node – The tensor we want to product-reduce.
  • reduction_axes – The axes to eliminate through product operation.
  • name – Optional name for output node.
Returns:

The new node performing product-reduction operation.

ngraph.ops.relu(node, name=None)[source]

Perform rectified linear unit operation on input node element-wise.

Parameters:
  • node – One of: input node, array or scalar.
  • name – The optional ouptut node name.
Returns:

The new node performing relu operation on its input element-wise.

ngraph.ops.replace_slice(dest_node, src_node, lower_bounds, upper_bounds, strides=None, name=None)[source]

Return a copy of dest_node with the specified slice overwritten by the src_node data.

Parameters:
  • dest_node – The node providing data to be overwritten by the specified slice.
  • src_node – The node providing data for overwriting.
  • lower_bounds – The (inclusive) lower-bound coordinates for the replaced slice.
  • upper_bounds – The (exclusive) upper-bound coordinates for the replaced slice.
  • strides – The strides for the replaced slice.
  • name – The optional name for the output new node.
Returns:

The new node with copy of dest_node with the specified slice overwritten by the src_node.

ngraph.ops.reshape(node, output_shape, input_order=None, name=None)[source]

Return reshaped node according to provided parameters.

Parameters:
  • node – The tensor we want to reshape.
  • input_order – The order in which to iterate over input axes of input tensor.
  • output_shape – The new shape for input tensor.
ngraph.ops.reverse(node, reversed_axes, name=None)[source]

Perform axis-reverse operation.

Parameters:
  • node – The input node on which operation will be carried out.
  • reversed_axes – The list of indices of axes to be reversed.
  • name – The optional name of the output node.
Returns:

The new node with reversed axes.

ngraph.ops.select(selection_node, input_node1, input_node2, name=None)[source]

Perform an element-wise selection operation on input tensors.

Parameters:
  • selection_node – The node providing selection values of bool type.
  • input_node1 – The node providing data to be selected if respective selection_node item value is True.
  • input_node2 – The node providing data to be selected if respective selection_node item value is False.
  • name – The optional new name for output node.
Returns:

The new node with values selected according to provided arguments.

ngraph.ops.sign(node, name=None)[source]

Perform element-wise sign operation.

Parameters:
  • node – One of: input node, array or scalar.
  • name – The optional new name for ouptut node.
Returns:

The node with mapped elements of the input tensor to -1 (if it is negative), 0 (if it is zero), or 1 (if it is positive).

ngraph.ops.sin(node, name=None)[source]

Apply sine function on the input node element-wise.

Parameters:
  • node – One of: input node, array or scalar.
  • name – Optional new name for output node.
Returns:

New node with sin operation applied on it.

ngraph.ops.sinh(node, name=None)[source]

Apply hyperbolic sine function on the input node element-wise.

Parameters:
  • node – One of: input node, array or scalar.
  • name – Optional new name for output node.
Returns:

New node with sin operation applied on it.

ngraph.ops.slice(node, lower_bounds, upper_bounds, strides=None, name=None)[source]

Take a slice of an input tensor, (sub-tensor) that resides within a bounding box.

Optionally this function may be provided with stride along each axis.

Parameters:
  • node – The tensor we want to slice.
  • lower_bounds – The (inclusive) lower-bound coordinates for the tensor slice.
  • upper_bounds – The (exclusive) upper-bound coordinates for the tensor slice.
  • strides – The strides for the tensor slice.
  • name – Optional name for the output node.
Returns:

Return node that represents a slice of input nodes data.

ngraph.ops.softmax(node, axes, name=None)[source]

Apply softmax operation on each element of input tensor.

Parameters:
  • node – The tensor providing input data.
  • axes – The list of axes indices which are used to calculate divider of the softmax function.
  • name – The optional new name for output node.
Returns:

The new node with softmax operation applied on each element.

ngraph.ops.sqrt(node, name=None)[source]

Return node which applies square root to the input node element-wise.

Parameters:
  • node – One of: input node, array or scalar.
  • name – Optional new name for output node.
Returns:

The new node with sqrt operation applied element-wise.

ngraph.ops.subtract(left_node, right_node, name=None)[source]

Return node which applies f(x) = A-B to the input nodes element-wise.

Parameters:
  • left_node – The node providing data for left hand side of operator.
  • right_node – The node providing data for right hand side of operator.
  • name – The optional name for output node.
Returns:

The new output node performing subtraction operation on both tensors element-wise.

ngraph.ops.sum(node, reduction_axes=None, name=None)[source]

Perform element-wise sums of the input tensor, eliminating the specified reduction axes.

Parameters:
  • node – The node providing data for operation.
  • reduction_axes – The axes to eliminate through summation.
  • name – The optional new name for ouptut node.
Returns:

The new node performing summation along reduction_axes element-wise.

ngraph.ops.tan(node, name=None)[source]

Apply tangent function on the input node element-wise.

Parameters:
  • node – One of: input node, array or scalar.
  • name – Optional new name for output node.
Returns:

New node with tan operation applied on it.

ngraph.ops.tanh(node, name=None)[source]

Return node which applies hyperbolic tangent to the input node element-wise.

Parameters:
  • node – One of: input node, array or scalar.
  • name – Optional new name for output node.
Returns:

New node with tanh operation applied on it.

ngraph.ops.topk(data, k, kaxis=-1, cmax=True)[source]

Return a node which performs TopK.

Parameters:
  • data – Input data.
  • kaxis – TopK Axis.
  • k
  • cmax – Compute TopK largest (True) or smallest (False)
Returns:

The new node which performs TopK (both indices and values)

ngraph.runtime module

Provide a layer of abstraction for the ngraph++ runtime environment.

class ngraph.runtime.Computation(runtime, ng_function)[source]

Bases: object

ngraph callable computation object.

serialize(indent=0)[source]

Serialize function (compute graph) to a JSON string.

Parameters:indent – set indent of serialized output
Returns:serialized model
class ngraph.runtime.Runtime(backend_name)[source]

Represents the ngraph++ runtime environment.

computation(node_or_function, *inputs)[source]

Return a callable Computation object.

ngraph.runtime.runtime(backend_name='CPU')[source]

Create a Runtime object (helper factory).

Use signature to parameterize runtime as needed.