Name

SPVM::R::OP::Time::Piece - N-Dimensional Array Operations for R::NDArray::Time::Piece

Description

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

Usage

use R::OP::Time::Piece as TPOP;

my $ndarray_scalar = TPOP->c(Time::Piece->strptime("2024-01-01 00-00-00", '%Y-%m-%d %H:%M:%S'));

my $ndarray_scalar = TPOP->c("2024-01-01");

my $ndarray_scalar = TPOP->c("2024-01-01 12:01:05");

my $data = [
  Time::Piece->strptime("2024-01-01 00-00-00", '%Y-%m-%d %H:%M:%S'),
  Time::Piece->strptime("2024-01-02 00-00-00", '%Y-%m-%d %H:%M:%S'),
  Time::Piece->strptime("2024-01-03 00-00-00", '%Y-%m-%d %H:%M:%S'),
  Time::Piece->strptime("2024-01-04 00-00-00", '%Y-%m-%d %H:%M:%S'),
  Time::Piece->strptime("2024-01-05 00-00-00", '%Y-%m-%d %H:%M:%S'),
  Time::Piece->strptime("2024-01-06 00-00-00", '%Y-%m-%d %H:%M:%S'),
];

my $ndarray_vector = TPOP->c($data);

my $ndarray_vector = TPOP->c(["2024-01-01", "2024-01-02"]);

my $ndarray_vector = TPOP->c(["2024-01-01 12:01:05", "2024-01-02 12:01:10"]);

my $ndarray = TPOP->c($data, [3, 2]);

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

Class Methods

c

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

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

Implemetation:

If $data is defined and the type of $data is Time::Piece, $data is set to [(Time::Piece)$data].

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

If $data is defined and the type of $data is string, $data is set to R::OP::String->c($data)->to_time_piece_ndarray->data.

If $data is defined and the type of $data is string[], $data is set to the return value of R::OP::String->c($data)->to_time_piece_ndarray->data.

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

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

Exceptions:

The type of the data $data must be Time::Piece, Time::Piece[], R::NDArray::Time::Piece, string, string[], R::NDArray::String if defined. Othrewise, an exception is thrown.

eq

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

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs the comparison logic $x_ndarray->elem_cmp($x_ndarray->data, $i, $y_ndarray->data, $i) == 0 on the each element(the index is $i) 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::Time::Piece, $y_ndarray : R::NDArray::Time::Piece);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs the comparison logic $x_ndarray->elem_cmp($x_ndarray->data, $i, $y_ndarray->data, $i) != 0 on the each element(the index is $i) 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::Time::Piece, $y_ndarray : R::NDArray::Time::Piece);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs the comparison logic $x_ndarray->elem_cmp($x_ndarray->data, $i, $y_ndarray->data, $i) > 0 on the each element(the index is $i) 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::Time::Piece, $y_ndarray : R::NDArray::Time::Piece);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs the comparison logic $x_ndarray->elem_cmp($x_ndarray->data, $i, $y_ndarray->data, $i) >= 0 on the each element(the index is $i) 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::Time::Piece, $y_ndarray : R::NDArray::Time::Piece);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs the comparison logic $x_ndarray->elem_cmp($x_ndarray->data, $i, $y_ndarray->data, $i) < 0 on the each element(the index is $i) 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::Time::Piece, $y_ndarray : R::NDArray::Time::Piece);

Creates a new R::NDArray::Int object of the same dimensions as the n-dimensional array $x_ndarray for a return value, performs the comparison logic $x_ndarray->elem_cmp($x_ndarray->data, $i, $y_ndarray->data, $i) <= 0 on the each element(the index is $i) 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::Time::Piece ($x_ndarray : R::NDArray::Time::Piece, $times : int);

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

rep_length

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

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

See Also

Copyright & License

Copyright (c) 2024 Yuki Kimoto

MIT License