Name
SPVM::R::OP::Matrix::Double - Matrix Operations for R::NDArray::Double
Description
R::OP::Matrix::Double class in SPVM has methods for matrix operations for R::NDArray::Double.
Usage
use R::OP::Matrix::Double as MDOP;
my $nrow = 3;
my $ncol = 2;
my $ndarray = MDOP->matrix([(double)1, 2, 3, 4, 5, 6], $nrow, $ncol);
See also Matrix Examples.
Class Methods
matrix
static method matrix : R::NDArray::Double ($data : object of Double|double[]|R::NDArray::Double, $nrow : int, $ncol : int);
Creates a new R::NDArray::Double 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::Double#c method.
my $ret_ndarray = R::OP::Double->c($data, [$nrow, $ncol]);
Exceptions:
Exceptions thrown by R::OP::Double#c method could be thrown.
matrix_byrow
static method matrix_byrow : R::NDArray::Double ($data : object of Double|double[]|R::NDArray::Double, $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::Double ($x_ndarray : R::NDArray::Double, $y_ndarray : R::NDArray::Double);
Same as R::OP::Matrix#cbind method, but the return type is different.
rbind
static method rbind : R::NDArray::Double ($x_ndarray : R::NDArray::Double, $y_ndarray : R::NDArray::Double);
Same as R::OP::Matrix#rbind method, but the return type is different.
diag
static method diag : R::NDArray::Double ($x_ndarray : R::NDArray::Double);
Creates a R::NDArray::Double 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::Double ($x_ndarray : R::NDArray::Double);
Creates a new R::NDArray::Double, 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::Double ($nrow : int);
Creates a new R::NDArray::Double 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::Double ($x_ndarray : R::NDArray::Double, $y_ndarray : R::NDArray::Double);
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::Double 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::Double ($x_ndarray : R::NDArray::Double);
Performs a matrix transpose on the n-dimension array $x_ndarray that is a matrix, creates a new R::NDArray::Double 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::Double ($x_ndarray : R::NDArray::Double);
Calculates the determinant of the n-dimension array $x_ndarray that is a matrix, creates a new R::NDArray::Double 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::Double ($x_ndarray : R::NDArray::Double);
Calculates the inverse of the n-dimension array $x_ndarray that is a matrix, creates a new R::NDArray::Double 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::Double);
Finds the eigenvectors and eigenvalues of the n-dimension array $x_ndarray that is a matrix, and creates a new two R::NDArray::DoubleComplex 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