The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

Name

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

Description

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

Usage

  use R::OP::StringBuffer as BUFOP;
  
  my $ndarray_scalar = BUFOP->c(StringBuffer->new("a"));
  
  my $ndarray_scalar = BUFOP->c("a");
  
  my $data = [
    StringBuffer->new("a"),
    StringBuffer->new("b"),
    StringBuffer->new("c"),
    StringBuffer->new("d"),
    StringBuffer->new("e"),
    StringBuffer->new("f")
  ];
  
  my $ndarray_vector = BUFOP->c($data);
  
  my $ndarray_vector = BUFOP->c([(string)"a", "b", "c", "d", "e", "f"]);
  
  my $ndarray = BUFOP->c($data, [3, 2]);
  
  my $ndarray2 = BUFOP->c($ndarray);

Class Methods

c

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

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

Implemetation:

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

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

If $data is defined and the type of $data is string, $data is set to [StringBuffer->new((string)$data)].

If $data is defined and the type of $data is string[], $data is set to the return value of R::OP::String-c((string[])$data)->to_string_buffer_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_string_buffer_ndarray->data.

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

Exceptions:

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

push

static method push : void ($x_ndarray : R::NDArray::StringBuffer, $y_ndarray : R::NDArray::String);

Performs $x_elem->push($y_elem) method on each element(named $x_elem, $y_elem) 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.

If push method throw an exceptions, $x_elem is unchanged.

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.

eq

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

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::StringBuffer, $y_ndarray : R::NDArray::StringBuffer);

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::StringBuffer, $y_ndarray : R::NDArray::StringBuffer);

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::StringBuffer, $y_ndarray : R::NDArray::StringBuffer);

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::StringBuffer, $y_ndarray : R::NDArray::StringBuffer);

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::StringBuffer, $y_ndarray : R::NDArray::StringBuffer);

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::StringBuffer ($x_ndarray : R::NDArray::StringBuffer, $times : int);

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

rep_length

static method rep_length : R::NDArray::StringBuffer ($x_ndarray : R::NDArray::StringBuffer, $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