Name

SPVM::R::OP::Int - N-Dimensional Array Operations for R::NDArray::Int

Description

R::OP::Int class in SPVM has methods for n-dimensional array operations for R::NDArray::Int.

Usage

use R::OP::Int as IOP;

my $ndarray_scalar = IOP->c((int)1);

my $ndarray_vector = IOP->c([(int)1, 2, 3]);

my $ndarray = IOP->c([(int)1, 2, 3, 4, 5, 6], [3, 2]);

my $ndarray2 = IOP->c($ndarray);

Class Methods

c

static method c : R::NDArray::Int ($data : object of Int|int[]|R::NDArray::Int, $dim : int[] = undef);

Creates a new R::NDArray::Int object given the data $data and the dimensions $dim.

Implemetation:

If $data is defined and the type of $data is Int, $data is set to [(int)$data-(Int)]>.

If $data is defined and the type of $data is R::NDArray::Int, $dim is set to $data->(R::NDArray::Int)->dim unless $dim is defined and $data is set to $data->(R::NDArray::Int)->data.

And this method calls R::NDArray::Int#new method given $dim and $data.

Exceptions:

The type of the data $data must be Int, int[], or R::NDArray::Int if defined. Othrewise, an exception is thrown.

add

static method add : R::NDArray::Int ($x_ndarray : R::NDArray::Int, $y_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs addition + operation on each element of the n-dimensional array $x_ndarray and $y_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

The n-dimensional array $y_ndarray must be defined. Otherwise, an exception is thrown.

The dimensions of $x_ndarray must be equal to the dimensions of $y_ndarray. Otherwise, an exception is thrown.

sub

static method sub : R::NDArray::Int ($x_ndarray : R::NDArray::Int, $y_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs subtraction - operation on each element of the n-dimensional array $x_ndarray and $y_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

The n-dimensional array $y_ndarray must be defined. Otherwise, an exception is thrown.

The dimensions of $x_ndarray must be equal to the dimensions of $y_ndarray. Otherwise, an exception is thrown.

mul

static method mul : R::NDArray::Int ($x_ndarray : R::NDArray::Int, $y_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs multiplication * operation on each element of the n-dimensional array $x_ndarray and $y_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

The n-dimensional array $y_ndarray must be defined. Otherwise, an exception is thrown.

The dimensions of $x_ndarray must be equal to the dimensions of $y_ndarray. Otherwise, an exception is thrown.

scamul

static method scamul : R::NDArray::Int ($x_ndarray : R::NDArray::Int, $scalar_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs multiplication * operation on each element of the n-dimensional array $x_ndarray, and sets each element of the new n-dimensional array and the n-dimensional array $scalar_ndarray at data index 0 to the each operation result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $scalar_ndarray must be defined. Otherwise, an exception is thrown.

The n-dmension array $scalar_ndarray must be a scalar.

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

div

static method div : R::NDArray::Int ($x_ndarray : R::NDArray::Int, $y_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs division / operation on each element of the n-dimensional array $x_ndarray and $y_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

The n-dimensional array $y_ndarray must be defined. Otherwise, an exception is thrown.

The dimensions of $x_ndarray must be equal to the dimensions of $y_ndarray. Otherwise, an exception is thrown.

scadiv

static method scadiv : R::NDArray::Int ($x_ndarray : R::NDArray::Int, $scalar_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs division / operations on the n-dimensional array $scalar_ndarray at data index 0 and each element of the n-dimensional array $x_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $scalar_ndarray must be defined. Otherwise, an exception is thrown.

The n-dmension array $scalar_ndarray must be a scalar.

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

div_u

static method div_u : R::NDArray::Int ($x_ndarray : R::NDArray::Int, $y_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs unsigned division div_uint operation on each element of the n-dimensional array $x_ndarray and $y_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

The n-dimensional array $y_ndarray must be defined. Otherwise, an exception is thrown.

The dimensions of $x_ndarray must be equal to the dimensions of $y_ndarray. Otherwise, an exception is thrown.

mod

static method mod : R::NDArray::Int ($x_ndarray : R::NDArray::Int, $y_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs modulo % operation on each element of the n-dimensional array $x_ndarray and $y_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

The n-dimensional array $y_ndarray must be defined. Otherwise, an exception is thrown.

The dimensions of $x_ndarray must be equal to the dimensions of $y_ndarray. Otherwise, an exception is thrown.

mod_u

static method mod_u : R::NDArray::Int ($x_ndarray : R::NDArray::Int, $y_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs unsigned modulo mod_uint operation on each element of the n-dimensional array $x_ndarray and $y_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

The n-dimensional array $y_ndarray must be defined. Otherwise, an exception is thrown.

The dimensions of $x_ndarray must be equal to the dimensions of $y_ndarray. Otherwise, an exception is thrown.

neg

static method neg : R::NDArray::Int ($x_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs negation - operation on each element of the n-dimensional array $x_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

abs

static method abs : R::NDArray::Int ($x_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs Fn#abs method on each element of the n-dimensional array $x_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

eq

static method eq : R::NDArray::Int ($x_ndarray : R::NDArray::Int, $y_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs numeric comparison == operation on each element of the n-dimensional array $x_ndarray and $y_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

The n-dimensional array $y_ndarray must be defined. Otherwise, an exception is thrown.

The dimensions of $x_ndarray must be equal to the dimensions of $y_ndarray. Otherwise, an exception is thrown.

ne

static method ne : R::NDArray::Int ($x_ndarray : R::NDArray::Int, $y_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs numeric comparison != operation on each element of the n-dimensional array $x_ndarray and $y_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

The n-dimensional array $y_ndarray must be defined. Otherwise, an exception is thrown.

The dimensions of $x_ndarray must be equal to the dimensions of $y_ndarray. Otherwise, an exception is thrown.

gt

static method gt : R::NDArray::Int ($x_ndarray : R::NDArray::Int, $y_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs numeric comparison > operation on each element of the n-dimensional array $x_ndarray and $y_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

The n-dimensional array $y_ndarray must be defined. Otherwise, an exception is thrown.

The dimensions of $x_ndarray must be equal to the dimensions of $y_ndarray. Otherwise, an exception is thrown.

ge

static method ge : R::NDArray::Int ($x_ndarray : R::NDArray::Int, $y_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs numeric comparison >= operation on each element of the n-dimensional array $x_ndarray and $y_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

The n-dimensional array $y_ndarray must be defined. Otherwise, an exception is thrown.

The dimensions of $x_ndarray must be equal to the dimensions of $y_ndarray. Otherwise, an exception is thrown.

lt

static method lt : R::NDArray::Int ($x_ndarray : R::NDArray::Int, $y_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs numeric comparison < operation on each element of the n-dimensional array $x_ndarray and $y_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

The n-dimensional array $y_ndarray must be defined. Otherwise, an exception is thrown.

The dimensions of $x_ndarray must be equal to the dimensions of $y_ndarray. Otherwise, an exception is thrown.

le

static method le : R::NDArray::Int ($x_ndarray : R::NDArray::Int, $y_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs numeric comparison <= operation on each element of the n-dimensional array $x_ndarray and $y_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

The n-dimensional array $y_ndarray must be defined. Otherwise, an exception is thrown.

The dimensions of $x_ndarray must be equal to the dimensions of $y_ndarray. Otherwise, an exception is thrown.

rep

static method rep : R::NDArray::Int ($x_ndarray : R::NDArray::Int, $times : int);

Same as R::OP#rep method, but the return type is different.

rep_length

static method rep_length : R::NDArray::Int ($x_ndarray : R::NDArray::Int, $length : int);

Same as R::OP#rep_length method, but the return type is different.

seq

static method seq : R::NDArray::Int ($begin : int, $end : int, $by : int = 1);

Creates a R::NDArray::Int object from $bigin to $end at intervals of $by.

Exceptions:

$by must not be 0. Otherwise, an exception is thrown.

If $by is greater than 0 and $end is not greater than or equal to $begin, an exception is thrown.

If $by is less than 0 and $end Is not greater than or equal to $begin, an exception is thrown.

undef

static method undef : R::NDArray::Int ();

Returns undef.

sum

static method sum : R::NDArray::Int ($x_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object with the dimenstion [1] for a return value, calculates the sum of all elements of the n-dimensional array $x_ndarray, and sets the element of the new n-dimensional array to the result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

cumsum

static method cumsum : R::NDArray::Int ($x_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, calculates the cumulative sum on each element of the n-dimensional array $x_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Examples are

# data
[(int)3, 1, 4, 1, 5, 9, 2, 6, 5]

# result
[(int)0, 3, 4, 8, 9, 14, 23, 25, 31, 36]

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

prod

static method prod : R::NDArray::Int ($x_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object with the dimenstion [1] for a return value, calculates the production of all elements of the n-dimensional array $x_ndarray, and sets the element of the new n-dimensional array to the result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

cumprod

static method cumprod : R::NDArray::Int ($x_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, calculates the cumulative product on each element of the n-dimensional array $x_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Examples are

# data
[(int)2, 3, 4, 5]

# result
[(int)2, 6, 24, 120]

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

diff

static method diff : R::NDArray::Int ($x_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the dimensions as the n-dimensional array $x_ndarray minus 1 for a return value, calculats the difference of adjacent elements of the n-dimensional array $x_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Examples are

# data
[(int)2, 4, 7]

# result
[(int)2, 3]

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

max

static method max : R::NDArray::Int ($x_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object with the dimenstion [1] for a return value, calculates the maximum value of all elements of the n-dimensional array $x_ndarray, and sets the element of the new n-dimensional array to the result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

min

static method min : R::NDArray::Int ($x_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object with the dimenstion [1] for a return value, calculates the minimum value of all elements of the n-dimensional array $x_ndarray, and sets the element of the new n-dimensional array to the result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

and

static method and : R::NDArray::Int ($x_ndarray : R::NDArray::Int, $y_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs logical AND operator && operation on each element of the n-dimensional array $x_ndarray and $y_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

Exceptions:

The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.

The n-dimensional array $y_ndarray must be defined. Otherwise, an exception is thrown.

The dimensions of $x_ndarray must be equal to the dimensions of $y_ndarray. Otherwise, an exception is thrown.

or

static method or : R::NDArray::Int ($x_ndarray : R::NDArray::Int, $y_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs logical OR operator || operation on each element of the n-dimensional array $x_ndarray and $y_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

not

static method not : R::NDArray::Int ($x_ndarray : R::NDArray::Int);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs logical NOT operator ! operation on each element of the n-dimensional array $x_ndarray and $y_ndarray, and sets each element of the new n-dimensional array to the each operation result, and returns the new n-dimensional array.

See Also

Copyright & License

Copyright (c) 2024 Yuki Kimoto

MIT License