Arithmetic¶

dragon.operators.arithmetic.Add(inputs, **kwargs)

Calculate A + B.

Type Constraints: (int8, uint8, int32, int64, float16, float32, float64)

Parameters: inputs (sequence of Tensor) – The inputs, A and B. The output tensor. Tensor
dragon.operators.arithmetic.Sub(inputs, **kwargs)

Calculate A - B.

Type Constraints: (int8, uint8, int32, int64, float16, float32, float64)

Parameters: inputs (sequence of Tensor) – The inputs, A and B. The output tensor. Tensor
dragon.operators.arithmetic.Mul(inputs, **kwargs)

Calculate A * B.

Type Constraints: (int8, uint8, int32, int64, float16, float32, float64)

Parameters: inputs (sequence of Tensor) – The inputs, A and B. The output tensor. Tensor
dragon.operators.arithmetic.Div(inputs, **kwargs)

Calculate A / B.

Type Constraints: (int8, uint8, int32, int64, float16, float32, float64)

Parameters: inputs (sequence of Tensor) – The inputs, A and B. The output tensor. Tensor
dragon.operators.arithmetic.Maximum(inputs, **kwargs)

Return the max value of given two inputs.

Type Constraints: (int8, uint8, int32, int64, float16, float32, float64)

Parameters: inputs (sequence) – The inputs, can be either Tensor or number. The output tensor. Tensor
dragon.operators.arithmetic.Minimum(inputs, **kwargs)

Return the min value of given two inputs.

Type Constraints: (int8, uint8, int32, int64, float16, float32, float64)

Parameters: inputs (sequence) – The inputs, can be either Tensor or number. The output tensor. Tensor
dragon.operators.arithmetic.Moments(inputs, axes=None, keep_dims=False, **kwargs)

Calculate the mean and variance of inputs along the given axes.

The data type of moments will be float32 typically, except the float64 inputs (float64 moments instead).

If axes is None, a Scalar will be returned.

Type Constraints: (int8, uint8, int32, int64, float16, float32, float64)

Parameters: inputs (Tensor) – The input tensor. axes (int or sequence of int, optional) – The axes to compute the moments. keep_dims (bool, optional) – Whether to keep the reduced dimensions of moments. The mean and variance. sequence of Tensor
dragon.operators.arithmetic.Clip(inputs, low=None, high=None, **kwargs)

Clip the input to be between lower and higher bounds.

Type Constraints: (int8, uint8, int32, int64, float16, float32, float64)

Parameters: inputs (Tensor) – The input tensor. low (number, optional) – The lower bound. high (number, optional) – The higher bound. The output tensor. Tensor
dragon.operators.arithmetic.Matmul(inputs, transA=False, transB=False, **kwargs)

Matrix Multiplication.

This operator can calculate a batch of matrix multiplication.

Type Constraints: (float16, float32, float64)

Parameters: inputs (sequence of Tensor) – The inputs, A and B. transA (bool, optional, default=False) – Whether to transpose A. transB (bool, optional, default=False) – Whether to transpose B. The output tensor. Tensor
dragon.operators.arithmetic.Dot(inputs, transA=False, transB=False, **kwargs)

Calculate the Vector dot.

This operator can trigger Matrix Multiplication (Right Alignment) or

Matrix Vector Multiplication (Right Alignment) also.

Type Constraints: (float16, float32, float64)

Parameters: inputs (sequence of Tensor) – The inputs, A and B. transA (bool, optional, default=False) – Whether to transpose A. transB (bool, optional, default=False) – Whether to transpose B. The output tensor. Tensor
dragon.operators.arithmetic.FullyConnected(
inputs,
num_output,
axis=1,
transW=True,
**kwargs
)

Calculate Y = X * W’ + b.

Where W’ = Transpose(W) if transW else W.

Type Constraints: (float16, float32, float64)

Parameters: inputs (sequence of Tensor) – The inputs, represent [X, W] + [b]. num_output (int) – The output dim. axis (int, optional, default=1) – The start axis to calculate, can be negative. transW (bool, optional, default=True) – Whether to transpose the W. The output tensor. Tensor
dragon.operators.arithmetic.Eltwise(inputs, operation='SUM', coef=None, **kwargs)

Element-wise Sum or Product the arbitrary number of inputs.

If coef is None, 1.0 will be used instead.

Type Constraints: (int8, uint8, int32, int64, float16, float32, float64)

Parameters: inputs (sequence of Tensor) – The inputs. operation ({SUM, PROD}, optional) – The operation to apply. coef (sequence of number, optional) – The coefficients on inputs. The output tensor. Tensor
dragon.operators.arithmetic.Log(inputs, **kwargs)

Calculate the logarithm of input.

Type Constraints: (float16, float32, float64)

Parameters: inputs (Tensor) – The input tensor. The logarithm tensor. Tensor
dragon.operators.arithmetic.Exp(inputs, **kwargs)

Calculate the exponential of input.

Type Constraints: (float16, float32, float64)

Parameters: inputs (Tensor) – The input tensor. The exponential result. Tensor
dragon.operators.arithmetic.Pow(
inputs,
power,
shift=0.0,
scale=1.0,
**kwargs
)

Calculate the power of input.

Formulation: $$\\ \, y = [(Scale * x) + Shift]^{Power}$$

Type Constraints: (float16, float32, float64)

Parameters: inputs (Tensor) – The input tensor. power (float, required) – The power factor. shift (float, optional, default=0.) – The shift magnitude. scale (float, optional, default=1.) – The scale factor. The powered result. Tensor
dragon.operators.arithmetic.Square(inputs, **kwargs)

Calculate the square of input.

Type Constraints: (int8, uint8, int32, int64, float16, float32, float64)

Parameters: inputs (Tensor) – The input tensor. The square result. Tensor
dragon.operators.arithmetic.Sqrt(inputs, **kwargs)

Calculate the sqrt of input.

Type Constraints: (float16, float32, float64)

Parameters: inputs (Tensor) – The input tensor. The sqrt result. Tensor
dragon.operators.arithmetic.Affine(inputs, axis=1, num_axes=1, **kwargs)

Calculate Y = Ax + b along the given range of axes.

The scale ranges are: $$\\ [Axis, Axis + NumAxes)$$

Set axis to specific the start axis.

Set num_axes to -1 will scale all remained axes.

Type Constraints: (float16, float32)

Parameters: inputs (sequence of Tensor) – The inputs, represent [x, A] + [b]. axis (int, optional, default=1) – The start axis to scale, can be negative. num_axes (int, optional, default=1) – The number of axes to scale. The output tensor. Tensor
dragon.operators.arithmetic.GramMatrix(inputs, axis=1, **kwargs)

Calculate the gram matrix. [Gatys et.al, 2016].

Formulation: $$\\ \, y = xx^{T}$$

Type Constraints: float32

Parameters: inputs (Tensor) – The input tensor. axis (int, optional, default=1) – The start axis to calculate. The gram matrix. Tensor
dragon.operators.arithmetic.Accumulate(inputs, alpha=1.0, beta=1.0, **kwargs)

Calculate y = alpha * x + beta * y

Type Constraints: (int8, uint8, int32, int64, float16, float32, float64)

Parameters: inputs (sequence of Tensor) – The inputs, i.e., the x. alpha (float, optional, default=1.) – The value of alpha. beta (float, optional, default=1.) – The value beta. The outputs, i.e., the y. sequence of Tensor
dragon.operators.arithmetic.MovingAverage(inputs, decay, **kwargs)

Calculate the y = (1 - decay) * x + decay * y

Type Constraints: (int8, uint8, int32, int64, float16, float32, float64)

Parameters: inputs (sequence of Tensor) – The inputs, i.e., the x. decay (float, required) – The decay factor. The outputs, i.e., the y. sequence of Tensor