Name
SPVM::R::OP::Matrix::Float - Matrix Operations for R::NDArray::Float
Description
R::OP::Matrix::Float class in SPVM has methods for matrix operations for R::NDArray::Float.
Usage
use R::OP::Matrix::Float as MFOP;
my $nrow = 3;
my $ncol = 2;
my $ndarray = MFOP->matrix([(float)1, 2, 3, 4, 5, 6], $nrow, $ncol);
See also Matrix Examples.
Class Methods
matrix
static method matrix : R::NDArray::Float ($data : object of Float|float[]|R::NDArray::Float, $nrow : int, $ncol : int);
Creates a new R::NDArray::Float object that represents a matrix given the data $data, the row numers $nrow, and the column numbers $ncol, and returns the new object.
This method calls R::OP::Float#c method.
my $ret_ndarray = R::OP::Float->c($data, [$nrow, $ncol]);
Exceptions:
Exceptions thrown by R::OP::Float#c method could be thrown.
matrix_byrow
static method matrix_byrow : R::NDArray::Float ($data : object of Float|float[]|R::NDArray::Float, $nrow : int, $ncol : int);
Same as "matrix" method, but the input data $data is interpreted as column major order.
Exceptions:
Exceptions thrown by "matrix" method could be thrown.
cbind
static method cbind : R::NDArray::Float ($x_ndarray : R::NDArray::Float, $y_ndarray : R::NDArray::Float);
Same as R::OP::Matrix#cbind method, but the return type is different.
rbind
static method rbind : R::NDArray::Float ($x_ndarray : R::NDArray::Float, $y_ndarray : R::NDArray::Float);
Same as R::OP::Matrix#rbind method, but the return type is different.
diag
static method diag : R::NDArray::Float ($x_ndarray : R::NDArray::Float);
Creates a R::NDArray::Float object that represents a diagonal matrix given a n-dimensional array $x_ndarray that is a vector with diagonal values, and returns the new object.
The row numbers and column numbers of the new object is equal to the value of length
field of $x_ndarray.
Exceptions:
The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.
The n-dimensional array $x_ndarray must be a vector. Otherwise, an exception is thrown.
slice_diag
static method slice_diag : R::NDArray::Float ($x_ndarray : R::NDArray::Float);
Creates a new R::NDArray::Float, sets its data to the diagonal values of the n-dimension array $x_ndarray that is a matrix, and returns the new object.
The value of length
field of the new object is equal to the row numbers of $x_ndarray.
Exceptions:
The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.
The n-dimensional array $x_ndarray must be a matrix. Otherwise, an exception is thrown.
identity
static method identity : R::NDArray::Float ($nrow : int);
Creates a new R::NDArray::Float object that represets an identity matrix given the row numbers $nrow, and returns the new object.
Exceptions:
The row numbers $nrow must be greater than 0. Otherwise, an exception is thrown.
mul
static method mul : R::NDArray::Float ($x_ndarray : R::NDArray::Float, $y_ndarray : R::NDArray::Float);
Performs a matrix multiplication on the n-dimension array $x_ndarray that is a matrix and the n-dimension array $y_ndarray that is a matrix.
And creates a new R::NDArray::Float object with the result, and returns the new object.
Exceptions:
The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.
The n-dimensional array $x_ndarray must be a matrix. Otherwise, an exception is thrown.
The n-dimensional array $y_ndarray must be defined. Otherwise, an exception is thrown.
The n-dimensional array $y_ndarray must be a matrix. Otherwise, an exception is thrown.
The column numbers of the matrix $x_ndarray must be equal to the row numbers of the matrix $y_ndarray. Otherwise, an exception is thrown.
t
static method t : R::NDArray::Float ($x_ndarray : R::NDArray::Float);
Performs a matrix transpose on the n-dimension array $x_ndarray that is a matrix, creates a new R::NDArray::Float object with the result, and returns the new object.
Excetpions:
The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.
The n-dimensional array $x_ndarray must be a matrix. Otherwise, an exception is thrown.
det
static method det : R::NDArray::Float ($x_ndarray : R::NDArray::Float);
Calculates the determinant of the n-dimension array $x_ndarray that is a matrix, creates a new R::NDArray::Float object with the result, and returns the new object.
The new object is a scalar.
Exceptions:
The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.
The n-dimensional array $x_ndarray must be a square matrix. Otherwise, an exception is thrown.
solve
static method solve : R::NDArray::Float ($x_ndarray : R::NDArray::Float);
Calculates the inverse of the n-dimension array $x_ndarray that is a matrix, creates a new R::NDArray::Float object with the result, and returns the new object.
Exceptions:
The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.
The n-dimensional array $x_ndarray must be a square matrix. Otherwise, an exception is thrown.
The determinant of the n-dimensional array $x_ndarray that is a matrix must not be equal to 0. Otherwise, an exception is thrown.
eigen
static method eigen : R::NDArray::Hash ($x_ndarray : R::NDArray::Float);
Finds the eigenvectors and eigenvalues of the n-dimension array $x_ndarray that is a matrix, and creates a new two R::NDArray::FloatComplex object for each results.
And creates a new R::NDArray::Hash object, sets the value of key "vectors"
to the new object that has the eigenvectors, sets the value of key "values"
to the new object that has the eigenvalues. Note that these vectores and values are complex numbers even if the result is able to be represented by real numbers.
And returns the new R::NDArray::Hash.
Exceptions:
The n-dimensional array $x_ndarray must be defined. Otherwise, an exception is thrown.
The n-dimensional array $x_ndarray must be a square matrix. Otherwise, an exception is thrown.
See Also
Copyright & License
Copyright (c) 2024 Yuki Kimoto
MIT License