# Math functions¶

## qm.qua.lib.Math¶

### abs staticmethod ¶

Computes the absolute value of x

PARAMETER DESCRIPTION
x

a QUA variable

RETURNS DESCRIPTION

a QUA fixed

### aelu staticmethod ¶

Computes faster an approximated Exponential Linear Unit activation function of x $$\mathrm{aELU}(x) \sim \mathrm{ELU}(x)$$

PARAMETER DESCRIPTION
x

a QUA fixed

RETURNS DESCRIPTION

a QUA fixed

### argmax staticmethod ¶

Return the index of the maximum of an array

PARAMETER DESCRIPTION
x

a QUA array

RETURNS DESCRIPTION

the index of maximum value of array, a QUA Integer

### argmin staticmethod ¶

Return the index of the minimum of an array

PARAMETER DESCRIPTION
x

a QUA array

RETURNS DESCRIPTION

the index of minimum value of array, a QUA Integer

### atan staticmethod ¶

Computes $$\mathrm{atan}(x)$$

-- Available from QOP 2.4 --

RETURNS DESCRIPTION

a QUA fixed

### atan2 staticmethod ¶

Computes $$\mathrm{atan2}(y,x)$$

-- Available from QOP 2.4 --

RETURNS DESCRIPTION

a QUA fixed

### atan2_2pi staticmethod ¶

Computes $$\mathrm{1/2 \pi * atan2}(y,x)$$

-- Available from QOP 2.4 --

RETURNS DESCRIPTION

a QUA fixed

### atan_2pi staticmethod ¶

Computes $$\mathrm{1/2 \pi * atan}(x)$$

-- Available from QOP 2.4 --

RETURNS DESCRIPTION

a QUA fixed

### cos staticmethod ¶

Computes $$\mathrm{cos}(x)$$

PARAMETER DESCRIPTION
x

TYPE: QUA variable of type fixed

RETURNS DESCRIPTION

a QUA fixed

### cos2pi staticmethod ¶

Computes $$\mathrm{cos}(2 \pi x)$$. This is more efficient than Math.cos($$2 \pi x$$). In addition, this function is immune to overflows: An overflow means that the argument gets a :math:\pm 16, which does not change the result due to the periodcity of the cosine function.

PARAMETER DESCRIPTION
x

TYPE: QUA variable of type fixed

RETURNS DESCRIPTION

a QUA fixed

### div staticmethod ¶

Computes the division between two same-type variables $$x/y$$

PARAMETER DESCRIPTION
x

a QUA parameter

y

a QUA parameter not equal to 0

RETURNS DESCRIPTION

a QUA fixed

### dot staticmethod ¶

Calculates a dot product of two QUA arrays of identical size.

PARAMETER DESCRIPTION
x

a QUA array

y

a QUA array

RETURNS DESCRIPTION

The dot product of x and y, has same type as x and y

Example
assign(c, dot(a, b))


### elu staticmethod ¶

Computes the Exponential Linear Unit activation function of x $$\mathrm{ELU(x)} = \mathrm{max}(0, x) + \mathrm{min}(0, \mathrm{exp}(x)-1)$$.

PARAMETER DESCRIPTION
x

a QUA fixed

RETURNS DESCRIPTION

a QUA fixed

### exp staticmethod ¶

Computes $$e^{x}$$

PARAMETER DESCRIPTION
x

a QUA fixed smaller than ln(8)=2.0794415416

RETURNS DESCRIPTION

a QUA fixed

### inv staticmethod ¶

Computes the inverse of x

PARAMETER DESCRIPTION
x

a QUA fixed which is x<=-1/8 or 1/8<x

RETURNS DESCRIPTION

a QUA fixed

### inv_sqrt staticmethod ¶

Computes the inverse square root of x

PARAMETER DESCRIPTION
x

a QUA fixed larger than 1/64

RETURNS DESCRIPTION

a QUA fixed

### ln staticmethod ¶

Computes $$\mathrm{ln}(x)$$

PARAMETER DESCRIPTION
x

a QUA fixed larger than exp(-8)=0.0003354627

RETURNS DESCRIPTION

a QUA fixed

### log staticmethod ¶

Computes $$\mathrm{log}_{base}(x)$$

PARAMETER DESCRIPTION
x

a QUA fixed larger than pow2(-8)=0.00390625

base

a QUA fixed larger than pow2(1/8)=1.09051

RETURNS DESCRIPTION

a QUA fixed

### log10 staticmethod ¶

Computes $$\mathrm{log}_{10}(x)$$

PARAMETER DESCRIPTION
x

a QUA fixed larger than pow10(-8)=0.00000001

RETURNS DESCRIPTION

a QUA fixed

### log2 staticmethod ¶

Computes $$\mathrm{log}_{2}(x)$$

PARAMETER DESCRIPTION
x

a QUA fixed larger than pow2(-8)=0.00390625

RETURNS DESCRIPTION

a QUA fixed

### lrelu staticmethod ¶

Computes the Leaky Rectified Linear Unit activation function of x $$\mathrm{LReLU}(x)=\mathrm{max}(0, x)+0.01*\mathrm{min}(0, x)$$

PARAMETER DESCRIPTION
x

a QUA fixed

RETURNS DESCRIPTION

a QUA fixed

### max staticmethod ¶

Computes the max of an array x

PARAMETER DESCRIPTION
x

a QUA array

RETURNS DESCRIPTION

the max value of the array, has same type as x

### min staticmethod ¶

Computes the min of an array x

PARAMETER DESCRIPTION
x

a QUA array

RETURNS DESCRIPTION

the min value of the array, has same type as x

### msb staticmethod ¶

Finds the index of the most significant bit in the parameter x. Notes:

• Result is independent of sign, for example, +3 and -3 will return the same msb
• The returned value will be the closet log2, rounded down.

This is given by $$\mathrm{floor}(\mathrm{log}_2(|x|))$$.

For example:

• msb(0.1) will return -4.
• msb(5) will return 2.
• For an integer, msb(0) will return 0.
• For a fixed point number, msb(0) will return -28.
PARAMETER DESCRIPTION
x

a QUA fixed or a QUA int

RETURNS DESCRIPTION

a QUA int

### plrelu staticmethod ¶

Computes the Parametric Leaky Rectified Linear Unit activation function of x $$\mathrm{PLReLU}(x, a) = \mathrm{max}(0, x)+a*\mathrm{min}(0, x)$$

PARAMETER DESCRIPTION
x

a QUA fixed

a

a QUA fixed

RETURNS DESCRIPTION

a QUA fixed

### pow staticmethod ¶

Computes $${base}^{x}$$. Does not support base=1, nor the case where both base=0 & x=0.

PARAMETER DESCRIPTION
base

a non-negative QUA fixed

x

a QUA fixed

RETURNS DESCRIPTION

a QUA fixed

### pow2 staticmethod ¶

Computes $$2^{x}$$

PARAMETER DESCRIPTION
x

a QUA fixed smaller than 3 (to avoid overflow)

RETURNS DESCRIPTION

a QUA fixed

### relu staticmethod ¶

Computes the Rectified Linear Unit activation function of x $$\mathrm{ReLU}(x) = \mathrm{max}(0, x)$$

PARAMETER DESCRIPTION
x

a QUA fixed

RETURNS DESCRIPTION

a QUA fixed

### selu staticmethod ¶

Computes the Scaled Exponential Linear Unit activation function of x $$\mathrm{SELU}(x) = s*(\mathrm{max}(0, x)+a*\mathrm{min}(0, \mathrm{exp}(x)-1))$$, $$a=1.67326324$$, $$s=1.05070098$$

PARAMETER DESCRIPTION
x

a QUA fixed

RETURNS DESCRIPTION

a QUA fixed

### sin staticmethod ¶

Computes $$\mathrm{sin}(x)$$

PARAMETER DESCRIPTION
x

TYPE: QUA variable of type fixed

RETURNS DESCRIPTION

a QUA fixed

### sin2pi staticmethod ¶

Computes $$\mathrm{sin}(2 \pi x)$$. This is more efficient than Math.sin(2*np.pi*x). In addition, this function is immune to overflows: An overflow means that the argument gets a $$\pm 16$$, which does not change the result due to the periodicity of the sine function.

PARAMETER DESCRIPTION
x

TYPE: QUA variable of type fixed

RETURNS DESCRIPTION

a QUA fixed

### sqrt staticmethod ¶

Computes the square root of x

PARAMETER DESCRIPTION
x

a non-negative QUA fixed

RETURNS DESCRIPTION

a QUA fixed

### sum staticmethod ¶

Computes the sum of an array x

PARAMETER DESCRIPTION
x

a QUA array

RETURNS DESCRIPTION

the sum of the array, has same type as x