pymoose.edsl.base module#

class pymoose.edsl.base.AbsExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.AbstractComputation(func, role_map)[source]#

Bases: object

with_role_map(role_map)[source]#
class pymoose.edsl.base.AddNExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.ArgmaxExpression(placement, inputs, vtype, axis, upmost_index)[source]#

Bases: pymoose.edsl.base.Expression

axis: Optional[Union[int, Tuple[int]]]#
upmost_index: int#
class pymoose.edsl.base.Argument(placement, dtype=None, vtype=None)[source]#

Bases: object

A type annotation Arguments to Moose computations.

This class is used for annotating the parameters of Moose computations with extra information needed to identify their graph Values in the compiler, and eventually to materialize those values at runtime.

Parameters
  • placement – A placement to pin this Argument to. The corresponding InputOp for the argument will be pinned to this placement.

  • dtype – If the Value is a Tensor, specify its dtype. Using this argument is equivalent to specifying vtype=TensorType(dtype=dtype).

  • vtype – The Moose Value type for the Argument. This type information is used during compilation to check correctness of the computation and to lower the computation graph into one that is runtime-ready. The type information of arguments is also checked at runtime.

dtype: Optional[pymoose.computation.dtypes.DType] = None#
placement: pymoose.edsl.base.PlacementExpression#
vtype: Optional[pymoose.computation.types.ValueType] = None#
class pymoose.edsl.base.ArgumentExpression(placement, inputs, vtype, arg_name)[source]#

Bases: pymoose.edsl.base.Expression

arg_name: str#
class pymoose.edsl.base.AtLeast2DExpression(placement, inputs, vtype, to_column_vector)[source]#

Bases: pymoose.edsl.base.Expression

to_column_vector: bool#
class pymoose.edsl.base.BinaryAndExpression(placement, inputs, vtype, op_name)[source]#

Bases: pymoose.edsl.base.Expression

op_name: str#
class pymoose.edsl.base.BinaryOpExpression(placement, inputs, vtype, op_name)[source]#

Bases: pymoose.edsl.base.Expression

op_name: str#
class pymoose.edsl.base.BitwiseAndExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.BitwiseOrExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.CastExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.ConcatenateExpression(placement, inputs, vtype, axis)[source]#

Bases: pymoose.edsl.base.Expression

axis: Optional[int]#
class pymoose.edsl.base.ConstantExpression(placement, inputs, vtype, value)[source]#

Bases: pymoose.edsl.base.Expression

value: Union[int, float]#
class pymoose.edsl.base.DecryptExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.ExpExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.ExpandDimsExpression(placement, inputs, vtype, axis)[source]#

Bases: pymoose.edsl.base.Expression

axis: Tuple[int]#
class pymoose.edsl.base.Expression(placement, inputs, vtype)[source]#

Bases: object

inputs: List[pymoose.edsl.base.Expression]#
placement: pymoose.edsl.base.PlacementExpression#
vtype: Optional[pymoose.computation.types.ValueType]#
class pymoose.edsl.base.GreaterExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.HostPlacementExpression(name)[source]#

Bases: pymoose.edsl.base.PlacementExpression

class pymoose.edsl.base.IdentityExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.IndexAxisExpression(placement, inputs, vtype, axis, index)[source]#

Bases: pymoose.edsl.base.Expression

axis: int#
index: int#
class pymoose.edsl.base.InverseExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.LessExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.LoadExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.Log2Expression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.LogExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.MaximumExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.MeanExpression(placement, inputs, vtype, axis)[source]#

Bases: pymoose.edsl.base.Expression

axis: Optional[Union[int, Tuple[int]]]#
class pymoose.edsl.base.MirroredPlacementExpression(name, players)[source]#

Bases: pymoose.edsl.base.PlacementExpression

players: List[pymoose.edsl.base.PlacementExpression]#
class pymoose.edsl.base.MuxExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.OnesExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.OutputExpression(placement, inputs, vtype, tag)[source]#

Bases: pymoose.edsl.base.Expression

tag: str#
class pymoose.edsl.base.PlacementExpression(name)[source]#

Bases: object

name: str#
class pymoose.edsl.base.ReluExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.ReplicatedPlacementExpression(name, players)[source]#

Bases: pymoose.edsl.base.PlacementExpression

players: List[pymoose.edsl.base.PlacementExpression]#
class pymoose.edsl.base.ReshapeExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.SaveExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.SelectExpression(placement, inputs, vtype, axis)[source]#

Bases: pymoose.edsl.base.Expression

axis: int#
class pymoose.edsl.base.ShapeExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.SigmoidExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.SliceExpression(placement, inputs, vtype, begin, end)[source]#

Bases: pymoose.edsl.base.Expression

begin: int#
end: int#
class pymoose.edsl.base.SoftmaxExpression(placement, inputs, vtype, axis, upmost_index)[source]#

Bases: pymoose.edsl.base.Expression

axis: Optional[Union[int, Tuple[int]]]#
upmost_index: int#
class pymoose.edsl.base.SqrtExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.SquareExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.SqueezeExpression(placement, inputs, vtype, axis)[source]#

Bases: pymoose.edsl.base.Expression

axis: Optional[Union[int, Tuple[int]]]#
class pymoose.edsl.base.StridedSliceExpression(placement, inputs, vtype, slices)[source]#

Bases: pymoose.edsl.base.Expression

slices: Optional[Tuple[slice]]#
class pymoose.edsl.base.SumExpression(placement, inputs, vtype, axis)[source]#

Bases: pymoose.edsl.base.Expression

axis: Optional[Union[int, Tuple[int]]]#
class pymoose.edsl.base.TransposeExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

class pymoose.edsl.base.ZerosExpression(placement, inputs, vtype)[source]#

Bases: pymoose.edsl.base.Expression

pymoose.edsl.base.abs(x, placement=None)[source]#

Compute the absolute value.

If the input is a tensor. the operation is performed elementwise.

Parameters
  • x – A value

  • placement – An optional Placement to pin this operation to.

Returns

The absolute value of x.

pymoose.edsl.base.add(lhs, rhs, placement=None)[source]#

Add two values.

Equivalent to lhs + rhs for the two inputs. If the inputs are tensors, the addition is performed elementwise.

Parameters
  • lhs – First addend.

  • rhs – Second addend.

  • placement – An optional Placement to pin this operation to.

Returns

Sum of the two inputs.

pymoose.edsl.base.add_n(arrays, placement=None)[source]#

Elementwise addition of a collection of tensors.

Parameters
  • arrays – Tuple or list of tensors w/ identical shape and dtype.

  • placement – An optional Placement to pin this operation to.

Returns

A tensor containing the elementwise sum of all input tensors.

pymoose.edsl.base.argmax(x, axis, upmost_index, placement=None)[source]#

Compute the index of the maximal element of a tensor along a given dimension.

Parameters
  • x – A tensor.

  • axis – The dimension along which to compute the argmax. upmost_index.

  • upmost_index – The max index that should be considered for computing the argmax. Generally, this should be the size of the axis dimension of x.

  • placement – An optional Placement to pin this operation to.

Returns

A dimension-reduced tensor representing the argmax of x along axis.

pymoose.edsl.base.atleast_2d(x, to_column_vector=False, placement=None)[source]#
pymoose.edsl.base.cast(x, dtype, placement=None)[source]#

Cast a tensor to a new dtype.

Parameters
  • x – A tensor.

  • dtype – A DType.

  • placement – An optional Placement to pin this operation to.

Returns

The tensor x converted to dtype.

pymoose.edsl.base.computation(func=None, role_map=None)[source]#

Annotates a Python function as a Moose computation.

Parameters
  • func – A Callable.

  • role_map – A map of abstract placements to identities in the current runtime context.

Returns

An abstract Moose computation that can be invoked in a runtime context.

pymoose.edsl.base.concatenate(arrays, axis=0, placement=None)[source]#

Concatenation of a collection of tensors along a given axis/dimension.

Note the tensors must have similar dtype and shape along all dimensions but the given one. The dimension must already exist in the input tensors; use expand_dims() on inputs to create a new dimnesion for concatenating along.

Parameters
  • arrays – Tuple or List of tensors to be concatenated.

  • axis – Optional integer representing the dimension to concatenate along. Dimension must already exist for all input tensors.

pymoose.edsl.base.constant(value, dtype=None, vtype=None, placement=None)[source]#

Embed a constant of a particular type.

Parameters
  • value – The Python value to embed as constant. Supported types include the Python native variants of those listed in pymoose.computation.types. Tensors are embeddable as numpy ndarrays.

  • dtype – If given, coerces value into a Moose tensor with this dtype. Otherwise, if value is an ndarray, the Moose dtype is inferred from the ndarray’s numpy dtype.

  • vtype – If given, coerces value into a Moose value with this vtype, i.e. ValueType. Otherwise, infers the vtype from value’s Python type.

  • placement – An optional Placement to pin this operation to.

Returns

A Moose Value of type vtype embedded into the computation graph.

pymoose.edsl.base.decrypt(key, ciphertext, placement=None)[source]#
pymoose.edsl.base.div(lhs, rhs, placement=None)[source]#

Divide two tensors.

Equivalent to lhs / rhs for the two inputs. If the inputs are tensors, the division is performed elementwise.

Parameters
  • lhs – Dividend.

  • rhs – Divisor.

  • placement – An optional Placement to pin this operation to.

Returns

Quotient of the two inputs.

pymoose.edsl.base.dot(lhs, rhs, placement=None)[source]#

Dot product of two tensors.

Tensor contraction along the second and first dimensions of the respective inputs. For 1 and 2 dimensional inputs, this is equivalent to np.dot(lhs, rhs).

Parameters
  • lhs – Left-hand tensor factor.

  • rhs – Right-hand tensor factor.

  • placement – An optional Placement to pin this operation to.

Returns

Dot product of the two input tensors.

pymoose.edsl.base.exp(x, placement=None)[source]#

Elementiwise exponential function: \(e^x\).

If the input is a tensor, the operation is performed elementwise.

Parameters
  • x – A value.

  • placement – An optional Placement to pin this operation to.

Returns

The exponentiated input.

pymoose.edsl.base.expand_dims(x, axis, placement=None)[source]#

Expand the rank of x with new singleton dimensions.

Parameters
  • x – The tensor to expand.

  • axis – Index of the new dimension. If a tuple/list, should contain the indices where each new dimension will be expanded.

  • placement – An optional Placement to pin this operation to.

Returns

The expanded tensor, complete with new singleton dimensions.

pymoose.edsl.base.get_current_placement()[source]#
pymoose.edsl.base.get_current_runtime()[source]#

Get a global runtime context.

pymoose.edsl.base.greater(lhs, rhs, placement=None)[source]#

Evaluate the boolean greater-than operation, i.e. lhs > rhs.

If tensors, the comparison is performed elementwise.

Parameters
  • lhs – Left-hand side of comparison.

  • rhs – Right-hand side of comparison.

  • placement – An optional Placement to pin this operation to.

Returns

The comparison of the two inputs.

pymoose.edsl.base.host_placement(name)[source]#
pymoose.edsl.base.identity(x, placement=None)[source]#

The identity operation, f(x) = x.

Although the value of x is guaranteed to remain unchanged, note that its placement may differ.

Parameters
  • x – Input value to be returned.

  • placement – An optional Placement to pin this operation to.

Returns

The unchanged value x.

pymoose.edsl.base.index_axis(x, axis, index, placement=None)[source]#

Index a tensor along a given dimension.

Parameters
  • x – A tensor.

  • axis – The dimension along which to index.

  • placement – An optional Placement to pin this operation to.

Returns

A slice of x corresponding to the sub-tensor at index along axis.

pymoose.edsl.base.inverse(x, placement=None)[source]#

Invert a floating-point matrix.

Parameters

x – A 2-dimensional float tensor to invert.

Returns

The matrix inverse of x.

pymoose.edsl.base.less(lhs, rhs, placement=None)[source]#

Evaluate the boolean less-than operation, i.e. lhs < rhs.

If the inputs are tensors, the comparison is performed elementwise.

Parameters
  • lhs – Left-hand side of comparison.

  • rhs – Right-hand side of comparison.

  • placement – An optional Placement to pin this operation to.

Returns

The comparison of the two inputs.

pymoose.edsl.base.load(key, query='', dtype=None, vtype=None, placement=None)[source]#

Load a value from placement storage.

The underlying key-value store implementation is runtime-specific. Generally, assume that each HostPlacement can be using a different storage implementation in its Moose worker/executor.

Parameters
  • key – A string or Moose String corresponding to the value that should be loaded.

  • query – An optional query string/String to provide to executor storage. Most common storage implementations ignore this.

  • dtype – If value should be loaded as a tensor, the DType to coerce the tensor to. If None, inferred from the value’s numpy dtype.

  • vtype – The Moose type to coerce the loaded value into. If None, will be traced as UnknownType and the compiler will attempt to fill it in during its initial Typing pass.

  • placement – An optional Placement to pin this operation to.

Returns

The loaded value, as provided by the worker backing the HostPlacement.

pymoose.edsl.base.log(x, placement=None)[source]#

Compute the elementwise natural logarithm of a tensor.

Parameters
  • x – A tensor.

  • placement – An optional Placement to pin this operation to.

Returns

The tensor representing log(x).

pymoose.edsl.base.log2(x, placement=None)[source]#

Compute the elementwise base-2 logarithm of a tensor.

Parameters
  • x – A tensor.

  • placement – An optional Placement to pin this operation to.

Returns

The tensor representing log_2(x).

pymoose.edsl.base.logical_and(lhs, rhs, placement=None)[source]#

Evaluate the boolean AND operation, i.e. lhs & rhs.

If tensors, the operation is performed elementwise.

Parameters
  • lhs – Left-hand side of operation.

  • rhs – Right-hand side of operation.

  • placement – An optional Placement to pin this operation to.

Returns

The logical intersection of the two inputs when treated as booleans.

pymoose.edsl.base.logical_or(lhs, rhs, placement=None)[source]#

Evaluate the boolean OR operation, i.e. lhs | rhs.

If tensors, the operation is performed elementwise.

Parameters
  • lhs – Left-hand side of operation.

  • rhs – Right-hand side of operation.

  • placement – An optional Placement to pin this operation to.

Returns

The logical union of the two inputs when treated as booleans.

pymoose.edsl.base.maximum(arrays, placement=None)[source]#

Elementwise maximum of a collection of input tensors.

Parameters
  • arrays – Tuple or list of tensors w/ identical shape and dtype.

  • placement – An optional Placement to pin this operation to.

Returns

A tensor containing the elementwise max of all input tensors.

pymoose.edsl.base.mean(x, axis=None, placement=None)[source]#

Mean-reduce an input tensor.

Parameters
  • x – A tensor.

  • axis – An optional dimension along which to mean-reduce the tensor. If None, mean-reduces the entire tensor and outputs a scalar tensor.

  • placement – An optional Placement to pin this operation to.

Returns

The averaged input, with one or all dimensions reduced out.

pymoose.edsl.base.mirrored_placement(name, players)[source]#
pymoose.edsl.base.mul(lhs, rhs, placement=None)[source]#

Multiply two values.

Equivalent to lhs * rhs for the two inputs. If the inputs are tensors, the multiplication is performed elementwise.

Parameters
  • lhs – First factor.

  • rhs – Second factor.

  • placement – An optional Placement to pin this operation to.

Returns

Product of the two inputs.

pymoose.edsl.base.mux(selector, x, y, placement=None)[source]#

Multiplex two tensors according to some condition.

This op allows for static control-flow of elements coming from two tensors. For boolean tensor s and arbitrary tensors x and y, the operation is equivalent to s * (x - y) + y.

Parameters
  • selector – Boolean tensor representing the control-flow condition.

  • x – A tensor to fill from when the selector condition is 1.

  • y – A tensor to fill from when the selector condition is 0.

  • placement – An optional Placement to pin this operation to.

Result:

A tensor with elements of x and y multiplexed according to the condition given by selector.

pymoose.edsl.base.ones(shape, dtype, placement=None)[source]#

Embed a ones array into the Moose computation graph.

Equivalent to pm.constant(np.ones(shape, dtype)) for a given dtype and shape.

Parameters
  • shape – Shape of the ones array.

  • dtype – Dtype of the ones array.

  • placement – An optional Placement to pin this operation to.

Returns

A tensor of all 1s with given shape and dtype.

pymoose.edsl.base.output(tag, value, placement=None)[source]#

Tag an output of a computation.

This op is similar to identity, but additionally tags its value. It can be used to pin an output to a particular placement without writing it to placement storage. It’s also useful for maintaining the ordering of computation outputs in PyMoose, since Moose compilation generally doesn’t preserve output order.

Parameters
  • tag – A tag to associate with the output, useful for reconstructing the original order of outputs.

  • value – The Moose value to output.

  • placement – An optional Placement to pin this operation to.

Returns

The tagged value.

pymoose.edsl.base.relu(x, placement=None)[source]#

Apply the rectified-linear unit (ReLU) function, f(x) = max(0, x).

If the input is a tensor, the operation is performed elementwise.

Parameters
  • x – A value.

  • placement – An optional Placement to pin this operation to.

Returns

A value correspoding to ReLU(x).

pymoose.edsl.base.replicated_placement(name, players)[source]#
pymoose.edsl.base.reshape(x, shape, placement=None)[source]#

Reshape a tensor.

Broadcasting is not allowed; the new shape must have the same total number of elements.

Parameters
  • x – A tensor.

  • shape – A list, tuple, or Shape dictating the new shape of the tensor.

  • placement – An optional Placement to pin this operation to.

Returns

The reshaped tensor.

pymoose.edsl.base.save(key, value, placement=None)[source]#

Save a key-value pair to placement storage.

The underlying key-value store implementation is runtime-specific. Generally, assume that each HostPlacement can be using a different storage implementation in its Moose worker/executor.

Parameters
  • key – A string or Moose String.

  • value – A Moose Value.

  • placement – An optional Placement to pin this operation to.

Returns

A Moose Value of type Unit.

pymoose.edsl.base.select(x, axis, index, placement=None)[source]#

Select elements along some axis of a tensor according to some index tensor.

Parameters
  • x – A tensor.

  • axis – The dimension along which to index.

  • index – A 1-d boolean tensor such that len(index) == x.shape[axis].

  • placement – An optional Placement to pin this operation to.

Returns

Copy of the tensor x, with the values along axis filtered such that x[..., i, ...] is kept iff index[i] == 1.

pymoose.edsl.base.set_current_runtime(runtime)[source]#

Set a global runtime context.

pymoose.edsl.base.shape(x, placement=None)[source]#

Compute the shape of an input tensor.

Parameters
  • x – A tensor.

  • placement – An optional Placement to pin this operation to.

Returns

A Moose value of type ShapeType corresponding to the input tensor’s shape.

pymoose.edsl.base.sigmoid(x, placement=None)[source]#

Apply the sigmoid function, \(\frac{1}{1 + e^{-x}}\).

If the input is a tensor, the operation is performed elementwise.

Parameters
  • x – A value.

  • placement – An optional Placement to pin this operation to.

Returns

The result of applying the sigmoid function to x.

pymoose.edsl.base.sliced(x, begin, end, placement=None)[source]#

Compute a slice of a value.

Parameters
  • x – A slice-able value, e.g. a TensorType or ShapeType.

  • begin – Index to start the slice at, e.g. 1 in x[1:5].

  • end – Non-inclusive index to end the slice at, e.g. 5 in x[1:5].

  • placement – An optional Placement to pin this operation to.

Returns

The sliced value.

pymoose.edsl.base.softmax(x, axis, upmost_index, placement=None)[source]#

Softmax function.

\[\mathrm{softmax}(x) = \frac{\exp(x_i)}{\sum_j \exp(x_j)}\]
Parameters
  • x – A tensor.

  • axis – The dimension along which the softmax divisor’s sum-reduce should be computed.

  • upmost_index – The max index that should be used for computing the softmax divisor’s sum-reduce. Generally, this should be the size of the axis dimension of x.

  • placement – An optional Placement to pin this operation to.

Returns

Result of applying the softmax function on x along the given axis.

pymoose.edsl.base.sqrt(x, placement=None)[source]#

Compute the square-root of a value \(\sqrt{x}\).

If the input is a tensor, the operation is performed elementwise.

Parameters
  • x – A value.

  • placement – An optional Placement to pin this operation to.

Returns

The square-root of the input.

pymoose.edsl.base.square(x, placement=None)[source]#

Square an input value.

If the input is a tensor, the operation is performed elementwise.

Parameters
  • x – A value to square.

  • placement – An optional Placement to pin this operation to.

Returns

The squared input.

pymoose.edsl.base.squeeze(x, axis=None, placement=None)[source]#

Reduce out any singleton dimensions of x.

Parameters
  • x – The tensor from which to drop singleton dimensions.

  • axis – Optional index into the shape of x denoting which singleton dimension to drop. If None, drops all singleton dimensions in x.

  • placement – An optional Placement to pin this operation to.

Returns

The squeezed tensor with fewer singleton dimensions.

pymoose.edsl.base.strided_slice(x, slices, placement=None)[source]#

Compute a strided slice of a value.

This version is more general than sliced, as it has support for more complex variants of Python slices.

Parameters
  • x – A value.

  • slices – A list/tuple of Python slice objects.

  • placement – An optional Placement to pin this operation to.

Returns

The sliced value.

pymoose.edsl.base.sub(lhs, rhs, placement=None)[source]#

Subtract two values.

Equivalent to lhs - rhs for the two inputs. If the inputs are tensors, the subtraction is performed elementwise.

Parameters
  • lhs – Minuend.

  • rhs – Subtrahend.

  • placement – An optional Placement to pin this operation to.

Returns

Difference of the two inputs.

pymoose.edsl.base.sum(x, axis=None, placement=None)[source]#

Sum-reduce an input tensor.

Computes the sum of tensor elements along a particular axis, or for the entire tensor if axis=None.

Parameters
  • x – A tensor.

  • axis – An optional dimension along which to sum-reduce the tensor. If None, sum-reduces the entire tensor and outputs a scalar tensor.

  • placement – An optional Placement to pin this operation to.

Returns

The summed input, with one or all dimensions reduced out.

pymoose.edsl.base.transpose(x, placement=None)[source]#

Compute the transpose of a tensor.

This is equivalent to numpy.ndarray.T.

Parameters
  • x – A tensor.

  • placement – An optional Placement to pin this operation to.

Returns

The input tensor with dimensions in reverse order.

pymoose.edsl.base.zeros(shape, dtype, placement=None)[source]#

Embed a zeros array into the Moose computation graph.

Equivalent to pm.constant(np.zeros(shape, dtype)) for a given dtype and shape.

Parameters
  • shape – Shape of the zeros array.

  • dtype – Dtype of the zeros array.

  • placement – An optional Placement to pin this operation to.

Returns

A tensor of all 0s with given shape and dtype.