LinearAlgebra

  • namespace: Rindow\Math\Matrix
  • classname: LinearAlgebra

Linear algebra library for arrays. For this library, speed is more important than flexibility.

The input data area and output data area are shared by many functions. So note that the contents of the input array will be destroyed.

The BLAS library and the MATH library specified by “MatrixOperator” are used internally. When the OpenBLAS FFI is specified, high-speed operations are possible.

Methods

constructor

$la = $matrixoperator->la();

Example

$mo = new MatrixOperator();
$la = $mo->la();

alloc

public function alloc(array $shape,$dtype=null)

Creates the specified NDArray and does not initialize its contents.

Arguments

  • shape: Shape of array
  • dtype: data type of array

Example

$x = $mo->la()->alloc([2,2]);

zeros

\(\begin{align*} X := 0 \end{align*}\)

public function zeros(NDArray $X) : NDArray

Initialize the array with zeros.

Arguments

  • X: The array to be initialized

Result

  • An initialized array. The same instance as the input array.

Example

$x = $mo->la()->zeros($mo->la()->alloc([2,2]));

zeros

\(\begin{align*} X := n \end{align*}\)

public function fill(
    $value,
    NDArray $X
    )

Initialize the array with zeros.

Arguments

  • value: fill value
  • X: Destination array

Result

  • The same instance as X.

Example

$x = $mo->la()->alloc([2,2]);
$mo->la()->fill(1.0, $x);
## x =>
## [[1,1]
##  [1,1]]

astype

\(\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(NDArray $X, $dtype) : NDArray

Cast an array to a specified data type.

Arguments

  • X: the vector X.
  • dtype: data type.
    • NDArray data type constant

Result

  • new vector.

Examples

use Interop\Polite\Math\Matrix\NDArray;
$x = $mo->array([[1,2,3],[4,5,6]],NDArray::float32);
$y = $mo->la()->astype($x,NDArray::uint8);
## y => [[1,2,3],[4,5,6]] <uint8>

copy

\(\begin{align*} Y := X \end{align*}\)

public function copy(
    NDArray $X,
    NDArray $Y=null ) : NDArray

Copy array elements

Arguments

  • X: Original vector.
  • Y: Destination vector.
    • If omitted, it will be allocated automatically.

Result

  • Same instance as vector Y.

Example

$x = $mo->array([1,-2,-3]);
$y = $mo->la()->copy($x);
## y => [1.0, -2.0, -3.0]

scal

\(\begin{align*} X := \alpha X \end{align*}\)

public function scal(
    float $alpha,
    NDArray $X) : NDArray

Scales a vector by a constant.

Arguments

  • alpha: a constant.
  • X: a vector.
    • Input and output are shared.

Result

  • The same instance as the input array.

Example

$x = $mo->array([1,2,3]);
$mo->la()->scale(2,$x);

axpy

\(\begin{align*} Y := \alpha X + Y \end{align*}\)

public function axpy(
    NDArray $X,
    NDArray $Y,
    float $alpha=null) : NDArray

Scales a vector by a constant.

Arguments

  • X: the vector X.
  • Y: the vector Y.
    • Input and output are shared.
  • alpha: a constant.
    • Default is 1.0.

Result

  • The same instance as the Y.

Example

$x = $mo->array([1,2,3]);
$y = $mo->array([1,2,3]);
$mo->la()->axpy($x,$y,2.0);
## y => [ 3.0, 6.0, 9.0]

dot

\(\begin{align*} f = \sum_{k=0}^n x_k y_k \end{align*}\)

public function dot(
    NDArray $X,
    NDArray $Y)

Dot product of vectors. Vectors are treated as one-dimensional arrays, regardless of shape.

Arguments

  • X: the vector X.
  • Y: the vector Y.

Result

  • value of result.

Example

$x = $mo->array([1,2,3]);
$y = $mo->array([1,2,3]);
$z = $mo->la()->dot($x,$y);
## z => 14.0

asum

\(\begin{align*} f = \sum_{k=0}^n \begin{vmatrix}x_k\end{vmatrix} \end{align*}\)

public function asum(NDArray $X) : float

Sum of absolute values of array elements

Arguments

  • X: the vector X.

Result

  • value of result.

Example

$x = $mo->array([1,-2,-3]);
$z = $mo->la()->asum($x);
## z => 6.0

iamax

\(\begin{align*} f = \arg \max \begin{vmatrix}x_k\end{vmatrix} \end{align*}\)

public function iamax(NDArray $X) : int

Get the element number of the maximum absolute value in array element

Arguments

  • X: the vector X.

Result

  • value of result.

Example

$x = $mo->array([1,-2,-3]);
$z = $mo->la()->iamax($x);
## z => 2

iamin

\(\begin{align*} f = \arg \min \begin{vmatrix}x_k\end{vmatrix} \end{align*}\)

public function iamin(NDArray $X) : int

Get the element number of the minimum absolute value in array element

Arguments

  • X: the vector X.

Result

  • value of result.

Example

$x = $mo->array([1,-2,-3]);
$z = $mo->la()->iamin($x);
## z => 0

amax

\(\begin{align*} f = \max \begin{vmatrix}x_k\end{vmatrix} \end{align*}\)

public function amax(NDArray $X) : float

Get the maximum absolute value in array element

Arguments

  • X: the vector X.

Result

  • value of result.

Example

$x = $mo->array([1,-2,-3]);
$z = $mo->la()->amax($x);
## z => -3.0

amin

\(\begin{align*} f = \min \begin{vmatrix}x_k\end{vmatrix} \end{align*}\)

public function amin(NDArray $X) : float

Get the minimum absolute value in array element

Arguments

  • X: the vector X.

Result

  • value of result.

Example

$x = $mo->array([1,-2,-3]);
$z = $mo->la()->amin($x);
## z => 1.0

nrm2

\(\begin{align*} f = \sqrt{\sum_{k=0}^n (x_k)^2} \end{align*}\)

public function nrm2(NDArray $X) : float

Get the norm value in array element

Arguments

  • X: the vector X.

Result

  • value of result.

Example

$x = $mo->array([1,2,3]);
$z = $mo->la()->nrm2($x);
## z => 3.7416574954987

rotg

\(\begin{align*} r,z,c,s = rotg (x, y) \end{align*}\)

public function rotg(
    NDArray $X,
    NDArray $Y,
    NDArray $R=null,
    NDArray $Z=null,
    NDArray $C=null,
    NDArray $S=null) : array

Get the Givens rotation.

Arguments

  • X: the value of axis X.
  • Y: the value of axis Y.

Result

  • array of result.

Example

$x = $mo->array(3.0);
$y = $mo->array(4.0);
[$r,$z,$c,$s] = $mo->la()->rotg($x,$y);
echo $r->toArray()."\n";
echo $z->toArray()."\n";
echo $c->toArray()."\n";
echo $s->toArray()."\n";
## r => 5
## z => 1.6666666269302
## c => 0.60000002384186
## s => 0.80000001192093

$x = $mo->array([3.0]);
$y = $mo->array([4.0]);
[$r,$z,$c,$s] = $mo->la()->rotg($x,$y);
echo $r[0]."\n";
echo $z[0]."\n";
echo $c[0]."\n";
echo $s[0]."\n";
## r => 5
## z => 1.6666666269302
## c => 0.60000002384186
## s => 0.80000001192093

rot

\(\begin{align*} X,Y := rot (X,Y,c,s) \end{align*}\)

public function rot(
    NDArray $X,
    NDArray $Y,
    NDArray $C,
    NDArray $S) : void

Get Coordinate rotation

Arguments

  • X: the value of axis X.
  • Y: the value of axis Y.
  • c: the value of cos.
  • s: the value of sin.

Result

  • array of result.

Example

$x = $mo->array([1,2,3]);
$y = $mo->array([1,2,3]);
$c = $mo->array([cos(pi()/4)]);
$s = $mo->array([sin(pi()/4)]);
$mo->la()->rot($x,$y,$c,$s);
echo $mo->toString($x)."\n";
echo $mo->toString($y)."\n";
## x => [1.4142135381699,2.8284270763397,4.2426404953003]
## y => [0,0,0]

swap

\(\begin{align*} x,y := y,x \end{align*}\)

public function swap(NDArray $X, NDArray $Y) : void

Swap the value in array element

Arguments

  • X: the vector X.
  • Y: the vector Y.

Result

  • value of result.

Example

$x = $mo->array([1, 2, 3]);
$y = $mo->array([4, 5, 6]);
$mo->la()->swap($x,$y);
## x => [4, 5, 6]
## y => [1, 2, 3]

gemv

\(\begin{align*} y := \alpha A \times x + \beta y \end{align*}\)

public function gemv(
    NDArray $A,
    NDArray $X,
    float $alpha=null,
    float $beta=null,
    NDArray $Y=null,
    bool $trans=null) : NDArray

Cross product of matrix and vector

Arguments

  • A: A matrix.
  • X: X vector.
  • alpha: constant value.
    • If omitted, default is 1.0
  • beta: constant value.
    • If omitted, default is 0.0
  • Y: Y vector.
    • If omitted, it will be allocated automatically.
    • Input and output are shared.
  • trans: transpose A matrix.
    • If omitted, default is false.

Result

  • Same instance as vector Y.

Example

$a = $mo->array([[1,2,3],[4,5,6]]);
$x = $mo->array([1,2,3]);
$y = $mo->array([1,1]);
$mo->la()->gemv($a,$x,2,3,$y);
## y => [31.0, 67.0]

gemm

\(\begin{align*} C := \alpha A \times B + \beta C \end{align*}\)

public function gemm(
    NDArray $A,
    NDArray $B,
    float $alpha=null,
    float $beta=null,
    NDArray $C=null,
    bool $transA=null,
    bool $transB=null) : NDArray

Cross product of matrix and matrix

Arguments

  • A: A matrix.
  • B: B matrix.
  • alpha: constant value.
    • If omitted, default is 0.1
  • beta: constant value.
    • If omitted, default is 0.0
  • C: C matrix.
    • If omitted, it will be allocated automatically.
    • Input and output are shared.
  • transA: transpose A matrix.
    • If omitted, it is false.
  • transB: transpose B matrix.
    • If omitted, it is false.

Result

  • Same instance as vector C.

Example

$a = $mo->array([[1,2,3],[4,5,6]]);
$b = $mo->array([[1,2],[3,4],[5,6]]);
$c = $mo->array([[1,2],[3,4]]);
$mo->la()->gemm($a,$b,2,3,$c);
## c => [[47,62],[107,140]]

symm

\(\begin{align*} C := \left \{ \begin{array}{l} A = Symmetric matrix \\ \alpha \times A B + \beta C \hspace{5mm} ( right = false ) \\ \alpha \times B A + \beta C \hspace{5mm} ( right = true ) \end{array} \right. \end{align*}\)

public function symm(
    NDArray $A,
    NDArray $B,
    float $alpha=null,
    float $beta=null,
    NDArray $C=null,
    bool $right=null,
    bool $lower=null
    ) : NDArray

Cross product of matrix and matrix

Arguments

  • A: A matrix.
  • B: B matrix.
  • alpha: constant value.
    • If omitted, default is 0.1
  • beta: constant value.
    • If omitted, default is 0.0
  • C: C matrix.
    • If omitted, it will be allocated automatically.
    • Input and output are shared.
  • right: multiply from right side.
    • If omitted, it is false.
  • lower: use lower side.
    • If omitted, it is false.

Result

  • Same instance as vector C.

Example

$a = $mo->array([
    [1,2,3],
    [0,5,6],
    [0,0,9],
]);
$b = $mo->array([[1,2],[3,4],[5,6]]);
$c = $mo->la()->symm($a,$b);
## c =>
##  [[22.0,28.0],
##   [47.0,60.0],
##   [66.0,84.0]]

syrk

\(\begin{align*} C := \left \{ \begin{array}{l} \alpha \times A A^T + \beta C \hspace{5mm} ( trans = false ) \\ \alpha \times A^T A + \beta C \hspace{5mm} ( trans = true ) \end{array} \right. \end{align*}\)

public function syrk(
    NDArray $A,
    float $alpha=null,
    float $beta=null,
    NDArray $C=null,
    bool $lower=null,
    bool $trans=null) : NDArray

Cross product of a matrix and transposed

Arguments

  • A: A matrix.
  • alpha: constant value.
    • If omitted, default is 0.1
  • beta: constant value.
    • If omitted, default is 0.0
  • C: C matrix.
    • If omitted, it will be allocated automatically.
    • Input and output are shared.
  • lower: use lower side result.
    • If omitted, it is false.
  • trans: transpose A matrix.
    • If omitted, it is false.

Result

  • Same instance as vector C.

Example

$a = $mo->array([
    [1,2],
    [3,4],
    [5,6],
]);
$c = $mo->la()->syrk($a);
## c =>
## [[5.0,11.0,17.0],
##  [0.0,25.0,39.0],
##  [0.0,0.0,61.0]]

syr2k

\(\begin{align*} C := \left \{ \begin{array}{l} \alpha \times A B^T + \alpha \times B A^T + \beta C \hspace{5mm} ( trans = false ) \\ \alpha \times B A^T + \alpha \times A B^T + \beta C \hspace{5mm} ( trans = true ) \end{array} \right. \end{align*}\)

public function syr2k(
    NDArray $A,
    NDArray $B,
    float $alpha=null,
    float $beta=null,
    NDArray $C=null,
    bool $lower=null,
    bool $trans=null) : NDArray

Cross product of a matrix and transposed

Arguments

  • A: A matrix.
  • B: B matrix.
  • alpha: constant value.
    • If omitted, default is 0.1
  • beta: constant value.
    • If omitted, default is 0.0
  • C: C matrix.
    • If omitted, it will be allocated automatically.
    • Input and output are shared.
  • lower: use lower side result.
    • If omitted, it is false.
  • trans: transpose A matrix.
    • If omitted, it is false.

Result

  • Same instance as vector C.

Example

$a = $mo->array([
    [1,2,3],
    [4,5,6],
    [7,8,9],
    [10,11,12],
]);
$b = $mo->array([
    [1,3,5],
    [2,4,6],
    [7,9,11],
    [8,10,12],
]);
$c = $mo->la()->syr2k($a,$b);
## c =>
## [[10.0, 22.0,  34.0],
##  [ 0.0, 50.0,  78.0],
##  [ 0.0,  0.0, 122.0]]

trmm

\(\begin{align*} B := \left \{ \begin{array}{l} \alpha \times A B \hspace{5mm} ( trans = false ) \\ \alpha \times B A \hspace{5mm} ( trans = true ) \end{array} \right. \end{align*}\)

public function trmm(
    NDArray $A,
    NDArray $B,
    float $alpha=null,
    bool $right=null,
    bool $lower=null,
    bool $trans=null,
    bool $unit=null) : NDArray

Cross product of a triangular matrix

Arguments

  • A: A matrix.
  • B: B matrix.
  • alpha: constant value.
    • If omitted, default is 0.1
  • lower: use lower side.
    • If omitted, it is false.
  • right: multiply from right side.
    • If omitted, it is false.
  • trans: transpose A matrix.
    • If omitted, it is false.
  • uni­t: uni­triangular.
    • If omitted, it is false.

Result

  • Same instance as vector C.

Example

$a = $mo->array([
    [1,2,3],
    [0,4,5],
    [0,0,6],
]);
$b = $mo->array([
    [1,2,3,4],
    [5,6,7,8],
    [9,10,11,12],
]);
$mo->la()->trmm($a,$b);
## b =>
##  [[38.0, 44.0, 50.0, 56.0],
##   [65.0, 74.0, 83.0, 92.0],
##   [54.0, 60.0, 66.0, 72.0]]

trsm

\(\begin{align*} B := \left \{ \begin{array}{l} \alpha \times A^{-1} B \hspace{5mm} ( trans = false ) \\ \alpha \times B A^{-1} \hspace{5mm} ( trans = true ) \end{array} \right. \end{align*}\)

public function trsm(
    NDArray $A,
    NDArray $B,
    float $alpha=null,
    bool $right=null,
    bool $lower=null,
    bool $trans=null,
    bool $unit=null) : NDArray

Cross product of a triangular matrix

Arguments

  • A: A matrix.
  • B: B matrix.
  • alpha: constant value.
    • If omitted, default is 0.1
  • right: multiply from right side.
    • If omitted, it is false.
  • lower: use lower side.
    • If omitted, it is false.
  • trans: transpose A matrix.
    • If omitted, it is false.
  • uni­t: uni­triangular.
    • If omitted, it is false.

Result

  • Same instance as vector C.

Example

$a = $mo->array([
    [1,2,3],
    [0,4,5],
    [0,0,6],
]);
$b = $mo->array([
    [1,2,3,4],
    [5,6,7,8],
    [9,10,11,12],
]);
$mo->la()->trsm($a,$b);
## b =>
## [[-2.250,-1.833,-1.417,-1.000],
##  [-0.625,-0.583,-0.542,-0.500],
##  [ 1.500, 1.667, 1.833, 2.000]]

svd

\(\begin{align*} U Σ V^T = M \end{align*}\)

public function svd(NDArray $matrix,$fullMatrices=null)

Cross product of a triangular matrix

Arguments

  • matrix: Input matrix.

Result

  • List of result value.
    • U: left matrix.
    • S: Sigma matrix.
    • VT: right matrix.

Example

$x = $mo->la()->randomUniform([6,5],-10,10);
[$u,$s,$vt] = $mo->la()->svd($x);

sum

\(\begin{align*} f = \sum_{k=0}^n x_k \end{align*}\)

public function sum(NDArray $X) : float

Sum of array elements

Arguments

  • X: the vector X.

Result

  • value of result.

Example

$x = $mo->array([1,2,3]);
$z = $mo->la()->sum($x);
## z => 6.0

imax

\(\begin{align*} f = \arg \max x_k \end{align*}\)

public function imax(NDArray $X) : int

Get the element number of the maximum value in array element

Arguments

  • X: the vector X.

Result

  • value of result.

Example

$x = $mo->array([1,2,3]);
$z = $mo->la()->imax($x);
## z => 2

imin

\(\begin{align*} f = \arg \min x_k \end{align*}\)

public function imin(NDArray $X) : int

Get the element number of the minimum value in array element

Arguments

  • X: the vector X.

Result

  • value of result.

Example

$x = $mo->array([1,2,3]);
$z = $mo->la()->imin($x);
## z => 0

max

\(\begin{align*} f = \max x_k \end{align*}\)

public function max(NDArray $X) : float

Get the maximum value in array element

Arguments

  • X: the vector X.

Result

  • value of result.

Example

$x = $mo->array([1,2,3]);
$z = $mo->la()->max($x);
## z => 3

min

\(\begin{align*} f = \min x_k \end{align*}\)

public function min(NDArray $X) : float

Get the minimum value in array element

Arguments

  • X: the vector X.

Result

  • value of result.

Example

$x = $mo->array([1,2,3]);
$z = $mo->la()->min($x);
## z => 1

increment

\(\begin{align*} X := \alpha X + \beta \end{align*}\)

public function increment(
    NDArray $X,
    float $beta=null,
    float $alpha=null) : NDArray

Increment the entire array element by a constant

Arguments

  • X: the vector X.
    • Input and output are shared.
  • beta: Increment constant.
  • alpha: multiply constant.

Result

  • Same instance as vector X.

Examples

\(\begin{align*} X := X + 1 \end{align*}\)

$x = $mo->array([1,2,3]);
$mo->la()->increment($x,1);
## x => [2.0, 3.0, 4.0]

\(\begin{align*} X := 1 - X \end{align*}\)

$x = $mo->array([1,2,3]);
$mo->la()->increment($x,1,-1);
## x => [0.0, -1.0, -2.0]

reciprocal

\(\begin{align*} X := \frac{1}{\alpha X + \beta} \end{align*}\)

public function reciprocal(
    NDArray $X,
    float $beta=null,
    float $alpha=null) : NDArray

Compute the reciprocal of a vector element

Arguments

  • X: the vector X.
    • Input and output are shared.
  • beta: Increment constant.
  • alpha: multiply constant.

Result

  • Same instance as vector X.

Examples

\(\begin{align*} X := \frac{1}{X + 1} \end{align*}\)

$x = $mo->array([1,2,3]);
$mo->la()->reciprocal($x,1);
## x => [0.5, 0.33333334326744, 0.25]

\(\begin{align*} X := \frac{1}{1 - X} \end{align*}\)

$x = $mo->array([2,3,4]);
$mo->la()->reciprocal($x,1,-1);
## x => [-1,-0.5,-0.33333334326744]

maximum

\(\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(float $alpha, NDArray $X) : NDArray

Set the larger of vector elements and constant

Arguments

  • alpha: Constant to compare.
  • X: the vector X.
    • Input and output are shared.

Result

  • Same instance as vector X.

Examples

$x = $mo->array([2,3,4]);
$mo->la()->maximum(3,$x);
## x => [3.0, 3.0, 4.0]

minimum

\(\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(float $alpha, NDArray $X) : NDArray

Set the smaller of the vector elements and constant

Arguments

  • alpha: Constant to compare.
  • X: the vector X.
    • Input and output are shared.

Result

  • Same instance as vector X.

Examples

$x = $mo->array([2,3,4]);
$mo->la()->minimum(3,$x);
## x => [2.0, 3.0, 3.0]

greater

\(\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(float $alpha, NDArray $X) : NDArray

Check if vector element is greater than constant

Arguments

  • alpha: Constant to compare.
  • X: the vector X.
    • Input and output are shared.

Result

  • Same instance as vector X.

Examples

$x = $mo->array([2,3,4]);
$mo->la()->greater(3,$x);
## x => [0.0, 0.0, 1.0]

less

\(\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(float $alpha, NDArray $X) : NDArray

Check if vector element is less than constant

Arguments

  • alpha: Constant to compare.
  • X: the vector X.
    • Input and output are shared.

Result

  • Same instance as vector X.

Examples

$x = $mo->array([2,3,4]);
$mo->la()->less(3,$x);
## x => [1.0, 0.0, 0.0]

multiply

\(\begin{align*} a_{ij} := x_j a_{ij} \end{align*}\)

public function multiply(NDArray $X, NDArray $A, bool $trans=null) : NDArray

Broadcast vector X to array A and multiply.

Arguments

  • X: the vector X.
    • It need not be a one-dimensional array.
  • A: the matrix A.
    • Input and output are shared.
    • The same shape as the shape of the vector X, or the shape of an array for multiple vectors X
  • trans: transpose the matrix A.
    • default is false.

Result

  • Same instance as vector A.

Examples

$a = $mo->array([[1,2,3],[4,5,6]]);
$x = $mo->array([30,20,10]);
$mo->la()->multiply($x,$a);
## a => [[30.0, 40.0, 30.0],[120.0, 100.0, 60.0]]
$a = $mo->array([[1,2,3],[4,5,6]]);
$x = $mo->array([20,10]);
$mo->la()->multiply($x,$a,true);
## a => [[20.0, 40.0, 60.0],[40.0, 50.0, 60.0]]

add

\(\begin{align*} a_{ij} := \alpha x_j + a_{ij} \end{align*}\)

public function add(
   NDArray $X,
   NDArray $A,
   float $alpha=null,
   bool $trans=null
   ) : NDArray

Broadcast vector X to array A and add.

Arguments

  • X: the vector X.
    • It need not be a one-dimensional array.
  • A: the matrix A.
    • Input and output are shared.
    • The same shape as the shape of the vector X, or the shape of an array for multiple vectors X
  • alpha: the constant
    • default is 1.0
  • trans: transpose the matrix A.
    • default is false.

Result

  • Same instance as vector A.

Examples

\(\begin{align*} X := X + A \end{align*}\)

$a = $mo->array([[1,2,3],[4,5,6]]);
$x = $mo->array([10,20,30]);
$mo->la()->add($x,$a);
## a => [[11.0, 22.0, 33.0],[14.0, 25.0, 36.0]]

\(\begin{align*} X := A + X \end{align*}\)

$a = $mo->array([[10,20,30],[40,50,60]]);
$x = $mo->array([1,2,3]);
$mo->la()->add($x,$a,-1);
## a => [[9,18,27],[39,48,57]]

square

\(\begin{align*} x_k := (x_k)^2 \end{align*}\)

public function square(NDArray $X) : NDArray

Square array elements

Arguments

  • X: the vector X.
    • Input and output are shared.

Result

  • Same instance as vector X.

Examples

$x = $mo->array([[1,2,3],[4,5,6]]);
$mo->la()->square($x);
## x => [[1.0, 4.0, 9.0],[16.0, 25.0, 36.0]]

sqrt

\(\begin{align*} x_k := \sqrt{x_k} \end{align*}\)

public function sqrt(NDArray $X) : NDArray

Square root of array elements

Arguments

  • X: the vector X.
    • Input and output are shared.

Result

  • Same instance as vector X.

Examples

$x = $mo->array([[0,1,4],[9,16,25]]);
$mo->la()->sqrt($x);
## x => [[0.0, 1.0, 2.0],[3.0, 4.0, 5.0]]

rsqrt

\(\begin{align*} x_k := \frac{1}{\alpha \sqrt{x_k} + \beta} \end{align*}\)

public function rsqrt(
    NDArray $X,
    float $beta=null,
    float $alpha=null) : NDArray

Square root of array elements and reciprocal it.

Arguments

  • X: the vector X.
    • Input and output are shared.
  • alpha: constant value.
    • If omitted, default is 1.0
  • beta: constant value.
    • If omitted, default is 0.0

Result

  • Same instance as vector X.

Examples

$x = $mo->array([1,4,9,16,25]);
$mo->la()->rsqrt($x);
## x => [1,0.5,0.33333334326744,0.25,0.20000000298023]

pow

\(\begin{align*} x_k := (x_k)^\alpha \end{align*}\)

public function pow(NDArray $X, float $alpha) : NDArray

To power array elements

Arguments

  • X: the vector X.
    • Input and output are shared.
  • alpha: the constant

Result

  • Same instance as vector X.

Examples

$x = $mo->array([[0,1,2],[3,4,5]]);
$mo->la()->pow($x,3);
## x => [[0.0, 1.0, 8.0],[27.0, 64.0, 125.0]]

exp

\(\begin{align*} x_k := e^{x_k} \end{align*}\)

public function exp(NDArray $X) : NDArray

calculate “e” to a power

Arguments

  • X: the vector X.
    • Input and output are shared.

Result

  • Same instance as vector X.

Examples

$x = $mo->array([[0,1,2],[3,4,5]]);
$mo->la()->exp($x);
## x => [[1.0, 2.7182817459106,7.3890562057495],[20.085536956787,54.598148345947,148.41316223145]]

log

\(\begin{align*} x_k := \log x_k \end{align*}\)

public function log(NDArray $X) : NDArray

Calculate the natural logarithm

Arguments

  • X: the vector X.
    • Input and output are shared.

Result

  • Same instance as vector X.

Examples

$x = $mo->array([[1,2,3],[4,5,6]]);
$mo->la()->log($x);
## x => [[0.0, 0.6931471824646,1.0986123085022],[1.3862943649292,1.6094379425049,1.7917594909668]]

tanh

\(\begin{align*} x_k := \tanh x_k \end{align*}\)

public function tanh(NDArray $X) : NDArray

Calculate the hyperbolic tangent

Arguments

  • X: the vector X.
    • Input and output are shared.

Result

  • Same instance as vector X.

Examples

$x = $mo->array([[1,2,3],[4,5,6]]);
$mo->la()->tanh($x);

equal

\(\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(
    NDArray $X,
    NDArray $Y) : NDArray

Aggregate the average value of array elements in the specified dimension

Arguments

  • X: the vector X.
  • Y: the vector Y.
    • Input and output are shared.

Result

  • Same instance as vector Y.

Examples

$x = $mo->array([[1,2,3],[6,5,4]]);
$y = $mo->array([[1,0,3],[4,5,6]]);
$mo->la()->equal($x,$y);
## y => [[1,0,1],[0,1,0]]

duplicate

\(\begin{align*} a_{ij} := x_j \end{align*}\)

public function duplicate(
    NDArray $X,
    int $repeats=null,
    bool $trans=null,
    NDArray $A=null) : NDArray

Copy vector X multiple times

Arguments

  • X: the vector X.
    • It need not be a one-dimensional array.
  • repeats: Number of copies
    • default is 1.
  • trans: transpose the matrix A.
    • default is false.
  • A: Destination matrix.
    • If omitted, it will be allocated automatically.

Result

  • Same instance as vector A.

Examples

$x = $mo->array([1,2,3]);
$a = $mo->la()->duplicate($x,2);
## a => [[1.0,2.0,3.0],[1.0,2.0,3.0]]
$x = $mo->array([1,2]);
$a = $mo->la()->duplicate($x,3,true);
## a => [[1.0,1.0,1.0],[2.0,2.0,2.0]]

transpose

\(\begin{align*} B = \alpha \times A^T \end{align*}\)

public function transpose(
    NDArray $A,
    NDArray $B=null,
    float $alpha=null
    )

Transpose a matrix

Arguments

  • A: input matrix.
  • B: output matrix
  • alpha: multiply value.
    • default is 1.0

Result

  • Same instance as Matrix B.

Examples

$a = $mo->array([[1,2][3,4]]);
$b = $mo->la()->transpose($a);
## b => [[1,3],[2,4]]

gather

\(\begin{align*} y := \left \{ \begin{array}{l} a_{x,k} \hspace{5mm} ( axis = null ) \\ a_{m,x,k} \hspace{5mm} ( axis \neq null ) \end{array} \right. \end{align*}\)

public function gather(
    NDArray $A,
    NDArray $X,
    int $axis=null,
    NDArray $B=null,
    $dtype=null) : NDArray

Select values from source array by indexes.

Arguments

  • A: source data.
  • X: selection index vector.
    • N-dimensional integer array.
  • axis: selection dimension
    • default is null.
    • If null, Match from the beginning of the selector.
    • If not null, Reduce on the specified axis.
  • B: Destination matrix.
    • If omitted, it will be allocated automatically.

Result

  • Same instance as vector B.

Examples

$a = $mo->array([[1,2,3],[4,5,6],[7,8,9]]);
$x = $mo->array([0,2],NDArray::int32);
$b = $mo->la()->gather($a,$x);
## b => [[1,2,3],[7,8,9]]
$a = $mo->array([[1,2,3],[4,5,6],[7,8,9]]);
$x = $mo->array([2,1,0],NDArray::int32);
$b = $mo->la()->gather($a,$x,$axis=0);
## b => [7,5,3]
$a = $mo->array([[1,2,3],[4,5,6],[7,8,9]]);
$x = $mo->array([2,1,0],NDArray::int32);
$b = $mo->la()->gather($a,$x,$axis=1);
## b => [3,5,7]

scatter

\(\begin{align*} y := \left \{ \begin{array}{l} a_{x,k} \hspace{5mm} ( axis = null ) \\ a_{m,x,k} \hspace{5mm} ( axis \neq null ) \end{array} \right. \end{align*}\)

public function scatter(
    NDArray $X,
    NDArray $A,
    int $numClass,
    int $axis=null,
    NDArray $B=null,
    $dtype=null) : NDArray

Set values to array by indexes. Reverse operation of gather.

Arguments

  • X: selection index vector.
  • A: source data vector.
    • N-dimensional integer array.
  • numClass: The size of the destination array.
    • Must be integer
  • axis: selection dimension
    • default is null.
    • If null, Match from the beginning of the selector.
    • If not null, Expand on the specified axis.
  • B: Destination array.

Result

  • Same instance as Matrix B.

Examples

$x = $mo->array([0,2],NDArray::int32);
$a = $mo->array([[1,2,3],[4,5,6]]);
$b = $mo->la()->scatter($x,$a,$n=3);
## b => [[1,2,3],[0,0,0],[4,5,6]]
$x = $mo->array([2,1,0],NDArray::int32);
$a = $mo->array([1,2,3]);
$b = $mo->la()->scatter($x,$a,$n=3,$axis=0);
## b => [[0,0,3],[0,2,0],[1,0,0]]
$x = $mo->array([2,1,0],NDArray::int32);
$a = $mo->array([1,2,3]);
$b = $mo->la()->scatter($x,$a,$n=3,$axis=1);
## b => [[0,0,1],[0,2,0],[3,0,0]]

scatterAdd

\(\begin{align*} B_{x} := B_{x} + A_{x} \end{align*}\)

public function scatterAdd(
    NDArray $X,
    NDArray $A,
    NDArray $B,
    int $axis=null,
    $dtype=null) : NDArray

Add values to array by indexes.

Arguments

  • X: selection index vector.
  • A: source data.
    • N-dimensional integer array.
  • B: Destination data.
  • axis: selection dimension
    • default is null.
    • If null, Match from the beginning of the selector.
    • If not null, Expand on the specified axis.

Result

  • Same instance as Matrix B.

Examples

$x = $mo->array([0,2],NDArray::int32);
$a = $mo->array([[1,2,3],[4,5,6]]);
$b = $mo->array([[1,1,1],[1,1,1],[1,1,1]]);
$mo->la()->scatterAdd($x,$a,$b);
## b => [[2,3,4],[1,1,1],[5,6,7]]
$x = $mo->array([2,1,0],NDArray::int32);
$a = $mo->array([1,2,3]);
$b = $mo->array([[1,1,1],[1,1,1],[1,1,1]]);
$mo->la()->scatterAdd($x,$a,$b,$axis=0);
## b => [[1,1,4],[1,3,1],[2,1,1]]
$x = $mo->array([2,1,0],NDArray::int32);
$a = $mo->array([1,2,3]);
$b = $mo->array([[1,1,1],[1,1,1],[1,1,1]]);
$mo->la()->scatterAdd($x,$a,$b,$axis=1);
## b => [[1,1,2],[1,3,1],[4,1,1]]

slice

public function slice(
    NDArray $input,
    array $begin,
    array $size,
    NDArray $output=null
    ) : NDArray

Slice a array with indicator.

Arguments

  • input: source data.
  • begin: begin of slice.
    • Must be integer array.
  • size: size of slice.
    • Must be integer array.
  • output: Destination array.

Result

  • Same instance as Matrix output.

Examples

$x = $mo->array($mo->arange(24,null,null,NDArray::float32)->reshape([2,4,3]));
$y = $la->slice(
    $x,
    $start=[0,1],
    $size=[-1,2]
    );
## y =>
##   [[[3,4,5],
##     [6,7,8],],
##    [[15,16,17],
##     [18,19,20],],
##   ]

stick

public function stick(
    NDArray $input,
    NDArray $output,
    array $begin,
    array $size
    ) : NDArray

Stick values to array with indicator.

Arguments

  • input: values.
  • output: Destination array.
  • begin: begin of value index.
    • Must be integer array.
  • size: size of values.
    • Must be integer array.
  • output: Destination array.

Result

  • Same instance as Matrix output.

Examples

$x = $mo->array($mo->arange(12,null,null,NDArray::float32)->reshape([2,2,3]));
$y = $mo->array($mo->zeros([2,4,3]));
$mo->la()->stick(
    $x,
    $y,
    $start=[0,1],
    $size=[-1,2]
    );
## y =>
##   [[[0,0,0],
##     [0,1,2],
##     [3,4,5],
##     [0,0,0]],
##    [[0,0,0],
##     [6,7,8],
##     [9,10,11],
##     [0,0,0]],]

stack

public function stack(
    array $values,
    int $axis=null
)

Concat arrays with a axis.

Arguments

  • values: list of input array.
    • Must be list of NDArray that are same the shapes.
  • axis: Coordinate axes to combine.

Result

  • NDArray as Matrix output.

Examples

$a = $mo->array($mo->arange(6,0,null,NDArray::float32)->reshape([2,3]));
$b = $mo->array($mo->arange(6,6,null,NDArray::float32)->reshape([2,3]));
$y = $mo->la()->stack(
    [$a,$b],
    $axis=0
    );
## y =>
##  [[[0,1,2],
##    [3,4,5]],
##   [[6,7,8],
##    [9,10,11]],]

concat

public function concat(
    array $values,
    int $axis=null
) : NDArray

Concat arrays with a axis.

Arguments

  • values: list of input array.
    • Must be list of NDArray that are same the shapes.
  • axis: Coordinate axes to combine.

Result

  • NDArray as Matrix output.

Examples

$a = $mo->array($mo->arange(6,$start=0,null,NDArray::float32)->reshape([3,2]));
$b = $mo->array($mo->arange(4,$start=6,null,NDArray::float32)->reshape([2,2]));
$y = $mo->la()->concat(
    [$a,$b],
    $axis=0
    );
## y =>
##  [[0,1],
##   [2,3],
##   [4,5],
##   [6,7],
##   [8,9],]

split

public function split(
    NDArray $input, array $sizeSplits, $axis=null
    ) : array

Split a array with a axis.

Arguments

  • input: input array.
  • sizeSplits: list of size.
    • Must be integer list
  • axis: Coordinate axes to split.

Result

  • List of NDArray as Matrix output.

Examples

$x = $mo->array([
    [0,1],
    [2,3],
    [4,5],
    [6,7],
    [8,9],
]);
$y = $mo->la()->split(
    $x,
    [3,2],
    $axis=0
);
## $y[0] =>
##  [[0,1],
##   [2,3],
##   [4,5]]
## $y[1] =>
##  [[6,7],
##   [8,9]]

repeat

public function repeat(
    NDArray $A,
    int $repeats,
    int $axis=null) : NDArray

Repeat array.

Arguments

  • A: values.
  • repeats: number of repeat.
  • axis: repeat axis.
    • If null, flat array output
    • If not null, repeat with specified axis. Result
  • Repeaded Matrix output.

Examples

$A = $mo->array([[1,2,3],[4,5,6]]);
$B = $la->repeat($X,2);
## b => [1,2,3,4,5,6,1,2,3,4,5,6]
$B = $la->repeat($X,2,$axis=0);
## b => [[[1,2,3],[4,5,6]],[[1,2,3],[4,5,6]]]
$B = $la->repeat($X,2,$axis=1);
## b => [[[1,2,3],[1,2,3]],[[4,5,6],[4,5,6]]]

onehot

\(\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 onehot(
    NDArray $X,
    int $numClass,
    float $a=null,
    NDArray $Y=null) : NDArray

Convert classification number to the onehot format.

Arguments

  • X: classification numbers.
    • Must be one-dimensional integer array.
  • numClass: Total number of classifications
  • a: Scalar value.
    • Default is 1.0.
    • The result is multiplied.
  • Y: Destination matrix.
    • If omitted, it will be allocated automatically.
    • If you specify an existing array, the result is added.

Result

  • Same instance as vector Y.

Examples

\(\begin{align*} Y := {\rm onehot} X \end{align*}\)

$x = $mo->array([0,1,2,0]);
$y = $mo->la()->onehot($x,3);
## y => [[1.0, 0.0, 0.0],[0.0, 1.0, 0.0],[0.0, 0.0, 1.0],[1.0, 0.0, 0.0]]

\(\begin{align*} Y := Y - \frac{ 1 }{ 2 }{\rm onehot} X \end{align*}\)

$y = $mo->array([[1,1,1],[1,1,1],[1,1,1],[1,1,1]]);
$x = $mo->array([0,1,2,0]);
$mo->la()->onehot($x,3,-0.5,$y);
## y => [[0.5, 1.0, 1.0],[1.0, 1.0, 5,0],[1.0, 1.0, 0.5],[0.5, 1.0, 1.0]]

softmax

\(\begin{align*} y_i = \frac{ e^{x_i} }{ \sum_{j=0}^{n} e^{x_j}} \end{align*}\)

public function softmax(
    NDArray $X
    ) : NDArray

Softmax function

Arguments

  • X: Must be a two-dimensional array.
    • Input and output are shared.

Result

  • Same instance as vector X.

Examples

$x = $mo->array([[1,2,3],[4,5,6],[7,8,9]]);
$mo->la()->softmax($x);
## x => [[0.090030573308468,0.2447284758091,0.66524094343185],
## [0.090030573308468,0.2447284758091,0.66524094343185],
## [0.090030573308468,0.2447284758091,0.66524094343185]]

reduceArgMax

\(\begin{align*} x_i = \arg {\rm maximum} (a_j) \end{align*}\)

public function reduceArgMax(
    NDArray $A,
    int $axis,
    NDArray $B=null,
    $dtypeB=null) : NDArray

Aggregate the index of the array element with the maximum value for the specified dimension.

Arguments

  • A: source data array.
  • axis: Aggregate dimension
    • Must be integer. If you give a negative number, it will be specified from the right.
  • B: Array to store the result.
    • If omitted, it will be allocated automatically.
  • dtypeB: Data type when creating array B.
    • If omitted, it will be int64 or int32.

Result

  • Same instance as matrix B.

Examples

$a = $mo->array([[1,2,3],[6,5,4]]);
$b = $mo->la()->reduceArgMax($a,1);
## b => [2,0]
$b = $mo->la()->reduceArgMax($a,0);
## b => [1,1,1]
$a = $mo->array([
    [[1,2],[5,6]],
    [[7,8],[3,4]]]);
$b = $mo->la()->reduceArgMax($a,1);
echo $mo->toString($b)."\n";
## b => [[1,1],[0,0]]

reduceMax

\(\begin{align*} x_i = {\rm maximum} (a_j) \end{align*}\)

public function reduceMax(
    NDArray $A,
    int $axis,
    NDArray $B=null,
    $dtypeB=null) : NDArray

Aggregate the array element with the maximum value for the specified dimension.

Arguments

  • A: source data array.
  • axis: Aggregate dimension
    • Must be integer. If you give a negative number, it will be specified from the right.
  • B: Array to store the result.
    • If omitted, it will be allocated automatically.
  • dtypeB: Data type when creating array B.
    • If omitted, same as original data

Result

  • Same instance as matrix B.

Examples

$a = $mo->array([[1,2,3],[6,5,4]]);
$b = $mo->la()->reduceMax($a,1);
## b => [3,6]
$b = $mo->la()->reduceMax($a,0);
## b => [6,5,4]
$a = $mo->array([
    [[1,2],[5,6]],
    [[7,8],[3,4]]]);
$b = $mo->la()->reduceMax($a,1);
echo $mo->toString($b)."\n";
## b => [[5,6],[7,8]]

reduceSum

\(\begin{align*} x_i = \sum_{j=0}^n a_ij \end{align*}\)

public function reduceSum(
   NDArray $A,
   int $axis=null,
   NDArray $B=null
   $dtypeB=null) : NDArray

Aggregate the sum of array elements in the specified dimension

Arguments

  • A: source data array.
  • axis: Aggregate dimension
    • Must be integer. If you give a negative number, it will be specified from the right.
    • Default is 0.
  • B: Array to store the result.
    • If omitted, it will be allocated automatically.
  • dtypeB: Data type when creating array B.
    • If omitted, same as original data

Result

  • Same instance as matrix B.

Examples

$a = $mo->array([[1,2,3],[6,5,4]]);
$b = $mo->la()->reduceSum($a,1);
## b => [6, 15]
$b = $mo->la()->reduceSum($a,0);
## b => [7, 7, 7]
$a = $mo->array([
    [[1,2],[5,6]],
    [[7,8],[3,4]]]);
$b = $mo->la()->reduceSum($a,1);
echo $mo->toString($b)."\n";
## b => [[6,8],[10,12]]

reduceMean

\(\begin{align*} x_i = \frac{ \sum_{j=0}^n a_j }{ n } \end{align*}\)

public function reduceMean(
    NDArray $A,
    int $axis,
    NDArray $B=null,
    $dtypeB=null) : NDArray

Aggregate the average value of array elements in the specified dimension

Arguments

  • A: source data array.
  • axis: Aggregate dimension
    • Must be 0 or 1.
  • B: Array to store the result.
    • If omitted, it will be allocated automatically.
  • dtypeB: Data type when creating array B.
    • If omitted, same as original data

Result

  • Same instance as Matrix B.

Examples

$a = $mo->array([[1,2,3],[6,5,4]]);
$b = $mo->la()->reduceMean($a,1);
## b => [2,5]
$b = $mo->la()->reduceMean($a,0);
## b => [3.5, 3.5, 3.5]
$a = $mo->array([
    [[1,2],[5,6]],
    [[7,8],[3,4]]]);
$b = $mo->la()->reduceSum($a,1);
echo $mo->toString($b)."\n";
## b => [[3,4],[5,6]]

im2col

public function im2col(
    NDArray $images,
    array $filterSize=null,
    array $strides=null,
    bool $padding=null,
    bool $channels_first=null,
    array $dilation_rate=null,
    bool $cols_channels_first=null,
    NDArray $cols=null
    ) : NDArray

Convert image data to cols format.

Arguments

  • images: Batch set of 1D or 2D or 3D data with channels.
    • The 1D data must be 3D NDArray. The 2D data must be 4D NDArray. The 3D data must be 5D NDArray.
  • filterSize: convolution filter size.
    • Integer list that matches the input data.
  • strides: strides size.
    • Integer list that matches the input data.
  • padding: Whether to padding.
    • When padded, the output image will be the same size as the input image.
  • channels_first: Input image data format.
    • The input image NDArray is whether the channel is the first axes.
    • If false : images shape [batchs,image_width,channels]
    • If true : images shape [batchs,channels,image_width]
  • dilation_rate: dilation rate size.
    • Integer list that matches the input data.
  • cols_channels_first: Output image data format.
    • The output cols NDArray is whether the channel is before the filters.
    • If false : cols shape [batches,image_width,filter_size,channels]. Used in convolution.
    • If true : cols shape [batches,image_width,channels,filter_size]. Used in pooling.
  • cols: Output cols data.
    • Converted output.

Result

  • Same instance as Matrix Cols.

Examples

$batches = 8;
$channels = 3;
$images = $mo->ones([$batches,28,28,$channels]);
$cols = $la->im2col(
    $images,
    $filterSize=[4,4],
    $strides=[1,1],
    $padding=false,
    $channels_first=false,
    $dilation_rate=[1,1],
    $cols_channels_first=false
);
## cols->shape() => [8,25,25,4,4,3]

col2im

public function col2im(
    NDArray $cols,
    NDArray $images,
    array $filterSize=null,
    array $strides=null,
    bool $padding=null,
    bool $channels_first=null,
    array $dilation_rate=null,
    bool $cols_channels_first=null
    ) : NDArray

Convert cols format to image data.

Arguments

  • cols: Input cols data.
    • Converted output.
  • images: Ouput batch set of 1D or 2D or 3D data with channels.
    • The 1D data must be 3D NDArray. The 2D data must be 4D NDArray. The 3D data must be 5D NDArray.
  • filterSize: convolution filter size.
    • Integer list that matches the input data.
  • strides: strides size.
    • Integer list that matches the input data.
  • padding: Whether to padding.
    • When padded, the output image will be the same size as the input image.
  • channels_first: Input image data format.
    • The output image NDArray is whether the channel is the first axes.
  • dilation_rate: dilation rate size.
    • Integer list that matches the input data.
  • cols_channels_first: Output image data format.
    • The input cols NDArray is whether the channel is the first axes.

Result

  • Same instance as Matrix Cols.

Examples

$batches = 8;
$channels = 3;
$cols = $mo->ones([$batches,25,25,4,4,$channels]);
$images = $mo->ones([$batches,28,28,$channels]);
$la->col2im(
    $cols,
    $images,
    $filterSize=[4,4],
    $strides=[1,1],
    $padding=false,
    $channels_first=false,
    $dilation_rate=[1,1],
    $cols_channels_first=false
);

randomUniform

public function randomUniform(
    array $shape,
    $low,
    $high,
    $dtype=null,
    int $seed=null,
    NDArray $X=null) : NDArray

Generate random numbers.

Arguments

  • shape: Output shape.
    • Integer list.
  • low: lower value.
    • float value.
  • high: higher value.
    • float value.
  • dtype: NDArray data type.
    • Constant of NDArray data type.
  • seed: seed for randomize.
  • output: output.
    • The output image NDArray is whether the channel is the first axes.

Result

  • Same instance as Matrix Cols.

Examples

$x = $mo->la()->randomUniform(
    [2,2],
    0.0, 1.0
);

randomNormal

public function randomNormal(
    array $shape,
    $mean,
    $scale,
    $dtype=null,
    int $seed=null,
    NDArray $X=null) : NDArray

Generate dormal distribution random numbers.

Arguments

  • shape: Output shape.
    • Integer list.
  • mean: mean of values.
    • float value.
  • scale: scale of values.
    • float value.
  • dtype: NDArray data type.
    • Constant of NDArray data type.
  • seed: seed for randomize.
  • output: output.
    • The output image NDArray is whether the channel is the first axes.

Result

  • Same instance as Matrix output.

Examples

$x = $mo->la()->randomNormal(
    [2,2],
    0.0, 1.0
);

randomSequence

public function randomSequence(
    int $base,
    int $size=null,
    int $seed=null
    ) : NDArray

Randomly selected from the population. Returns a uniquely selected value from a population of sequential integers.

Arguments

  • base: Population size.
    • Integer.
  • size: Data size to generate.
    • If omitted, it is the same size as the population.
  • seed: seed for randomize.

Result

  • output Matrix.

Examples

$x = $mo->la()->randomSequence(10);

imagecopy

public function imagecopy(
    NDArray $A,
    NDArray $B=null,
    bool $channels_first=null,
    int $heightShift=null,
    int $widthShift=null,
    bool $verticalFlip=null,
    bool $horizontalFlip=null
    ) : NDArray

Copy 2D image data with various conversions

Arguments

  • A: Source 2D image data.
    • 3D NDArray. [h,w,c] or [c,h,w]
  • B: Destination.
    • Default is allocated output.
    • Same shape as A.
  • channels_first: data format.
    • Default false,
    • If false, the format is channels_last [h,w,c].
    • If true, the format is channels_first [c,h,w].
  • heightShift: Up and down shift range.
  • widthShift: Left and right shift range.
  • verticalFlip: Upside down.
  • horizontalFlip: Left-right reversal.

Result

  • same B object.

Examples

$A = $mo->array([
    [1,2,3],
    [4,5,6],
    [7,8,9]
])->reshape([3,3,1]);
$B = $mo->la()->imagecopy($A,null,null,null,
    $heightShift=null,$widthShift=null,$verticalFlip=true)->reshape([3,3]);
## B = [[3,2,1],
##      [6,5,4],
##      [9,8,7]]