Math

Math

  • namespace: Rindow\Matlib\FFI
  • classname: Math

Mathematics functions library.

Methods

Table of contents

constructor

public function __construct();

Arguments

  • size: buffer size.
    • Number of elements in array. (Note that it is not the memory size)
  • dtype: data type.
    • Specify one of the data types defined in Interop\Polite\Math\Matrix\NDArray.

sum

f=k=0nxk\begin{align*} f = \sum_{k=0}^n x_k \end{align*}
public function sum(
    int $n,
    Buffer $X, int $offsetX, int $incX ) : float

sum of array element.

Supported deta types

  • float32, float64, bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64

Arguments

  • n: Number of array elements.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X

Return

  • result sum

imax

f=argmaxxk\begin{align*} f = \arg \max x_k \end{align*}
public function imax(
    int $n,
    Buffer $X, int $offsetX, int $incX) : int

Index of max value.

Supported deta types

  • float32, float64

Arguments

  • n: Number of array elements.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X

Return

  • result imax

imin

f=argminxk\begin{align*} f = \arg \min x_k \end{align*}
public function imin(
    int $n,
    Buffer $X, int $offsetX, int $incX) : int

Index of max value.

Supported deta types

  • float32, float64

Arguments

  • n: Number of array elements.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X

Return

  • result imin

increment

aij:=xjaij\begin{align*} a_{ij} := x_j a_{ij} \end{align*}
public function increment(
    int $n,
    float $alpha,
    Buffer $X, int $offsetX, int $incX,
    float $beta) : void

increment array.

Supported deta types

  • float32, float64

Arguments

  • n: Number of array elements.
  • alpha: scale.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X
  • beta: bias.

reciprocal

X:=1αX+β\begin{align*} X := \frac{1}{\alpha X + \beta} \end{align*}
public function reciprocal(
    int $n,
    float $alpha,
    Buffer $X, int $offsetX, int $incX,
    float $beta) : void

increment array.

Supported deta types

  • float32, float64

Arguments

  • n: Number of array elements.
  • alpha: scale.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X
  • beta: bias.

maximum

xk:={xk(xk>α)α(xkα)\begin{align*} x_k := \left \{ \begin{array}{l} x_k \hspace{5mm} (x_k > \alpha) \\ \alpha \hspace{5mm} (x_k \leqq \alpha) \end{array} \right. \end{align*}
public function maximum(
    int $n,
    float $alpha,
    Buffer $X, int $offsetX, int $incX) : void

maximum values in comparison with the threshold

Supported deta types

  • float32, float64

Arguments

  • n: Number of array elements.
  • alpha: scale.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X

minimum

xk:={xk(xk<α)α(xkα)\begin{align*} x_k := \left \{ \begin{array}{l} x_k \hspace{5mm} (x_k < \alpha) \\ \alpha \hspace{5mm} (x_k \geqq \alpha) \end{array} \right. \end{align*}
public function minimum(
    int $n,
    float $alpha,
    Buffer $X, int $offsetX, int $incX) : void

minimum values in comparison with the threshold

Supported deta types

  • float32, float64

Arguments

  • n: Number of array elements.
  • alpha: scale.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X

greater

xk:={1(xk>α)0(xkα)\begin{align*} x_k := \left \{ \begin{array}{l} 1 \hspace{5mm} (x_k > \alpha) \\ 0 \hspace{5mm} (x_k \leqq \alpha) \end{array} \right. \end{align*}
public function greater(
    int $n,
    float $alpha,
    Buffer $X, int $offsetX, int $incX) : void

Whether it is greater compared to the threshold.

Supported deta types

  • float32, float64

Arguments

  • n: Number of array elements.
  • alpha: scale.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X

less

xk:={1(xk<α)0(xkα)\begin{align*} x_k := \left \{ \begin{array}{l} 1 \hspace{5mm} (x_k < \alpha) \\ 0 \hspace{5mm} (x_k \geqq \alpha) \end{array} \right. \end{align*}
public function less(
    int $n,
    float $alpha,
    Buffer $X, int $offsetX, int $incX) : void

Whether it is less compared to the threshold.

Supported deta types

  • float32, float64

Arguments

  • n: Number of array elements.
  • alpha: scale.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X

multiply

aij:=xjaij\begin{align*} a_{ij} := x_j a_{ij} \end{align*}
public function multiply(
    bool $trans,
    int $m,
    int $n,
    Buffer $X, int $offsetX, int $incX,
    Buffer $A, int $offsetA, int $ldA ) : void

broadcast and multiply

Supported deta types

  • float32, float64

Arguments

  • trans: transpose.
  • m: Number of array elements.
  • n: Number of array elements.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X
  • A: Buffer A.
  • offsetA: Offset buffer.
  • ldA: leading Dimension A.

add

aij:=αxj+aij\begin{align*} a_{ij} := \alpha x_j + a_{ij} \end{align*}
public function add(
    int $trans,
    int $m,
    int $n,
    float $alpha,
    Buffer $X, int $offsetX, int $incX,
    Buffer $A, int $offsetA, int $ldA ) : void

broadcast and add

Supported deta types

  • float32, float64

Arguments

  • trans: transpose.
  • m: Number of array elements.
  • n: Number of array elements.
  • alpha: scale.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X
  • A: Buffer A.
  • offsetA: Offset buffer.
  • ldA: leading Dimension A.

duplicate

aij:=xj\begin{align*} a_{ij} := x_j \end{align*}
public function duplicate(
    bool $trans,
    int $m,
    int $n,
    Buffer $X, int $offsetX, int $incX,
    Buffer $A, int $offsetA, int $ldA ) : void

broadcast and copy

Supported deta types

  • float32, float64

Arguments

  • trans: transpose.
  • m: Number of array elements.
  • n: Number of array elements.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X
  • A: Buffer A.
  • offsetA: Offset buffer.
  • ldA: leading Dimension A.

square

xk:=(xk)2\begin{align*} x_k := (x_k)^2 \end{align*}
public function square(
    int $n,
    Buffer $X, int $offsetX, int $incX) : void

Square the elements

Supported deta types

  • float32, float64

Arguments

  • n: Number of array elements.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X

sqrt

xk:=xk\begin{align*} x_k := \sqrt{x_k} \end{align*}
public function sqrt(
    int $n,
    Buffer $X, int $offsetX, int $incX) : void

Square root the elements

Supported deta types

  • float32, float64

Arguments

  • n: Number of array elements.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X

rsqrt

xk:=1αxk+β\begin{align*} x_k := \frac{1}{\alpha \sqrt{x_k} + \beta} \end{align*}
public function rsqrt(
    int $n,
    float $alpha,
    Buffer $X, int $offsetX, int $incX,
    float $beta) : void

Square root the elements

Supported deta types

  • float32, float64

Arguments

  • n: Number of array elements.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X

pow

xk:=(xk)α\begin{align*} x_k := (x_k)^\alpha \end{align*}
public function pow(
    int $n,
    float $alpha,
    Buffer $X, int $offsetX, int $incX) : void

Power the elements

Supported deta types

  • float32, float64

Arguments

  • n: Number of array elements.
  • alpha: Exponentiate.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X

exp

xk:=exk\begin{align*} x_k := e^{x_k} \end{align*}
public function exp(
    int $n,
    Buffer $X, int $offsetX, int $incX) : void

Exponentiate the elements

Supported deta types

  • float32, float64

Arguments

  • n: Number of array elements.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X

log

xk:=logxk\begin{align*} x_k := \log x_k \end{align*}
public function log(
    int $n,
    Buffer $X, int $offsetX, int $incX) : void

Logarithm the elements

Supported deta types

  • float32, float64

Arguments

  • n: Number of array elements.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X

zeros

X:=0\begin{align*} X := 0 \end{align*}
public function zeros(
    int $n,
    Buffer $X, int $offsetX, int $incX) : void

set zero to elements

Supported deta types

  • float32, float64, bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64

Arguments

  • n: Number of array elements.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X

updateAddOnehot

yij:={yij+a(xi=j)yij(xij)\begin{align*} y_{ij} := \left \{ \begin{array}{l} y_{ij} + a \hspace{5mm} ( x_i = j ) \\ y_{ij} \hspace{5mm} ( x_i \neq j ) \end{array} \right. \end{align*}
public function updateAddOnehot(
    int $m,
    int $n,
    float $a,
    Buffer $X, int $offsetX, int $incX,
    Buffer $Y, int $offsetY, int $ldY ) : void

Translate one-hot and add it.

Supported deta types

  • float32, float64

Arguments

  • m: Number of array elements.
  • n: Number of array elements.
  • a: Incremental value
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X
  • Y: Buffer Y.
  • offsetY: Offset buffer.
  • ldY: leading dimension

softmax

yij:={a(xi=j)0(xij)\begin{align*} y_{ij} := \left \{ \begin{array}{l} a \hspace{5mm} ( x_i = j ) \\ 0 \hspace{5mm} ( x_i \neq j ) \end{array} \right. \end{align*}
public function softmax(
    int $m,
    int $n,
    Buffer $A, int $offsetA, int $ldA) : void

softmax function.

Supported deta types

  • float32, float64

Arguments

  • m: Number of array elements.
  • n: Number of array elements.
  • A: Buffer A.
  • offsetA: Offset buffer.
  • ldA: leading dimension

equal

yi:={1(xi=yi)0(xiyi)\begin{align*} y_i := \left \{ \begin{array}{l} 1 \hspace{5mm} ( x_i = y_i ) \\ 0 \hspace{5mm} ( x_i \neq y_i ) \end{array} \right. \end{align*}
public function equal(
    int $n,
    Buffer $X, int $offsetX, int $incX,
    Buffer $Y, int $offsetY, int $incY ) : void

equal function.

Supported deta types

  • float32, float64, bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64

Arguments

  • n: Number of array elements.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X
  • Y: Buffer Y.
  • offsetY: Offset buffer.
  • incY: Incremental Y

reduceSum

xi=j=0naij\begin{align*} x_i = \sum_{j=0}^n a_{ij} \end{align*}
public function reduceSum(
    bool $trans,
    int $m,
    int $n,
    Buffer $A, int $offsetA, int $ldA,
    Buffer $X, int $offsetX, int $incX ) : void

equal function.

Supported deta types

  • float32, float64

Arguments

  • trans: transpose.
  • m: Number of array elements.
  • n: Number of array elements.
  • A: Buffer A.
  • offsetA: Offset buffer.
  • ldA: leading dimension
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X

astype

yi:={1(xi=yi)0(xiyi)\begin{align*} y_i := \left \{ \begin{array}{l} 1 \hspace{5mm} ( x_i = y_i ) \\ 0 \hspace{5mm} ( x_i \neq y_i ) \end{array} \right. \end{align*}
public function astype(
    int $n,
    int $dtype,
    Buffer $X, int $offsetX, int $incX,
    Buffer $Y, int $offsetY, int $incY) : void

translate data type.

Supported deta types

  • float32, float64, bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64

Arguments

  • n: Number of array elements.
  • dtype: data type of NDArray.
  • X: Buffer X.
  • offsetX: Offset buffer.
  • incX: Incremental X
  • Y: Buffer Y.
  • offsetY: Offset buffer.
  • incY: Incremental Y