Name
SPVM::R::NDArray::String - N-Dimensional Array of string Type.
Description
R::NDArray::String class in SPVM represents n-dimensional array of string
type.
Usage
use R::NDArray::String;
my $ndarray = R::NDArray::String->new({data => [(string)"a", "b", "c", "d", "e", "f"], dim => [3, 2]});
Super Class
Field
data
method data : string[] ();
Same as R::NDArray#data method, but the return type is different.
Class Methods
new
static method new : R::NDArray::String ($options : object[] = undef);
Creates a new R::NDArray::String given the options $options and returns it.
This method calls R::NDArray#init method given the options $options.
Instance Methods
create_default_data
method create_default_data : string[] ($length : int = 0);
Creates a default data given the length $length and returns it.
The default data is created by the following code.
my $default_data = new string[$length];
Exceptions:
The length $length must be more than or equal to 0. Otherwise an exception is thrown.
elem_to_string
method elem_to_string : string ($data : string[], $data_index : int);
Converts an element $data at index $data_index to a string and returns it.
The string is created by the following code.
my $string = copy $data->[$data_index];
elem_assign
method elem_assign : void ($dist_data : string[], $dist_data_index : int, $src_data : string[], $src_data_index : int);
Assigns the element $src_data at index $src_data_index to the element $dist_data at index $dist_data_index.
elem_clone
method elem_clone : void ($dist_data : string[], $dist_data_index : int, $src_data : string[], $src_data_index : int);
Clones the element $src_data at index $src_data_indext to the element $dist_data at index $dist_data_index.
The clone is created by the following code.
$dist_data->[$dist_data_index] = copy $src_data->[$src_data_index];
elem_cmp
method elem_cmp : int ($a_data : string[], $a_data_index : int, $b_data : string[], $b_data_index : int);
Compares the element $a_data at index $a_data_index and the element $b_data at index $b_data_index using the string comparison operator cmp
and returns the result.
elem_is_na
method elem_is_na : int ($data : object, $data_index : int);
Checks if an element represets NA.
If the element $data at index $data_index is not defined, returns 1, otherwise returns 0.
clone
method clone : R::NDArray::String ($shallow : int = 0);
Same as R::NDArray#clone method, but the return type is different.
slice
method slice : R::NDArray::String ($indexes_product : R::NDArray::Int[]);
Same as R::NDArray#slice method, but the return type is different.
to_string_buffer_ndarray
method to_string_buffer_ndarray : R::NDArray::StringBuffer ();
Converts this n-dimensional array to a n-dimensional array of R::NDArray::StringBuffer and returns it.
Each element is converted to a StringBuffer object by the following code.
my $ret_elem = (StringBuffer)undef;
if ($elem) {
$ret_elem = StringBuffer->new($elem);
}
to_time_piece_ndarray
method to_time_piece_ndarray : R::NDArray::Time::Piece ();
Converts this n-dimensional array to a n-dimensional array of R::NDArray::Time::Piece and returns it.
Each element is converted to a Time::Piece object by the following code.
my $ret_elem = (Time::Piece)undef;
if ($elem) {
eval { $ret_elem = Time::Piece->strptime($elem, "%Y-%m-%d %H:%M:%S"); }
unless ($ret_elem) {
eval { $ret_elem = Time::Piece->strptime($elem, "%Y-%m-%d"); }
}
}
Every string format must be %Y-%m-%d %H:%M:%S
or %Y-%m-%d
if the element is defined.
See Also
Copyright & License
Copyright (c) 2024 Yuki Kimoto
MIT License