Title: | Multi- And Mixed-Precision Computations |
---|---|
Description: | Designed for multi- and mixed-precision computations, accommodating 64-bit and 32-bit data structures. This flexibility enables fast execution across various applications. The package enhances performance by optimizing operations in both precision levels, which is achieved by integrating with high-speed 'BLAS' and 'LAPACK' libraries like 'MKL' and 'OpenBLAS'. Including a 32-bit option caters to applications where high precision is unnecessary, accelerating computational processes whenever feasible. The package also provides support for tile-based algorithms in three linear algebra operations: CHOL(), TRSM(), and GEMM(). The tile-based algorithm splits the matrix into smaller tiles, facilitating parallelization through a predefined Directed Acyclic Graph (DAG) for each operation. Enabling 'OpenMP' enhances the efficiency of these operations, leveraging multi-core parallelism. In this case, 'MPCR' facilitates mixed-precision execution by permitting varying precision levels for different tiles. This approach is advantageous in numerous applications, as it maintains the accuracy of the application while accelerating execution in scenarios where single-precision alone does not significantly affect the accuracy of the application. |
Authors: | David Helmy [aut], Sameh Abdulah [cre], KAUST King Abdullah University of Science and Technology [fnd, cph] |
Maintainer: | Sameh Abdulah <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.1.3 |
Built: | 2024-11-08 07:10:12 UTC |
Source: | CRAN |
MPCR is a multi-precision vector/matrix, that enables the creation of vector/matrix with three different precisions (16-bit (half), 32-bit(single), and 64-bit(double)).
MPCR object (constructor - accessors - methods)
new
Creates a new instance of zero values of the MPCR
class.
new(MPCR,size, "precision")
size
The total number of values for which memory needs to be allocated.
precision
String to indicate the precision of MPCR object ("half","single", or "double").
The following accessors can be used to get the values of the slots:
IsMatrix
Boolean to indicate whether the MPCR object is a vector or matrix.
Size
Total number of elements inside the object, (row*col) in the case of matrix, and number of elements in the case of vector.
Row
Number of rows.
Col
Number of cols.
The following methods are available for objects of class MPCR
:
PrintValues()
: Prints all the values stored in the matrix or vector, along with metadata about the object.
ToMatrix(row,col)
: Changes the object representation to match the new dimensions, no memory overhead.
ToVector()
: Changes the MPCR matrix to vector, no memory overhead.
# Example usage of the class and its methods library(MPCR) MPCR_object <- new(MPCR,50,"single") MPCR_object$ToMatrix(5,10) MPCR_object$Row #5 MPCR_object$Col #10 MPCR_object$Size #50 MPCR_object$IsMatrix #TRUE MPCR_object$PrintValues() MPCR_object$ToVector() MPCR_object
# Example usage of the class and its methods library(MPCR) MPCR_object <- new(MPCR,50,"single") MPCR_object$ToMatrix(5,10) MPCR_object$Row #5 MPCR_object$Col #10 MPCR_object$Size #50 MPCR_object$IsMatrix #TRUE MPCR_object$PrintValues() MPCR_object$ToVector() MPCR_object
MPCRTile is a data structure for tile matrices with mixed precision, where each tile possesses a specific precision level.
MPCRTile object (constructor - accessors - methods)
new
creates a new instance of Tile-Matrix MPCRTile
class.
new(MPCRTile,rows,cols,rows_per_tile,cols_per_tile,values,precisions)
rows
Number of rows in the matrix.
cols
Number of cols in the matrix.
rows_per_tile
Number of rows in each tile.
cols_per_tile
Number of cols in each tile.
values
R matrix or vector containing all the values that should be in the matrix.
precisions
R matrix or vector of strings, containing precision type of each tile.
The following accessors can be used to get the values of the slots:
Size
Total number of elements inside the Matrix.
Row
Number of rows.
Col
Number of cols.
TileRow
Number of rows in each tile.
TileCol
Number of cols in each tile.
TileSize
Total number of elements in each tile.
The following methods are available for objects of class MPCRTile
:
PrintTile(tile_row_idx,tile_col_idx)
: Prints all the values stored inside a specific tile plus meta-data about the tile.
tile_row_idx
Row index of the tile.
tile_col_idx
Col index of the tile.
ChangeTilePrecision(tile_row_idx,tile_col_idx,precision)
: Change the precision of specific tile, this function will need to copy all the values to cast them to the new precision.
tile_row_idx
Row index of the tile.
tile_col_idx
Col index of the tile.
precision
Required new precision as a string.
FillSquareTriangle(value,upper.tri,precision)
: Fills upper or lower triangle
with a given value and precision, new tiles will be created,
replacing the old tiles. Note: The input must be a square matrix
value
A value used during matrix filling.
upper.tri
A flag to indicate what triangle to fill. if TRUE, the upper triangle will be filled, otherwise the lower triangle.
precision
The precision of the tiles created during matrix filling, in case it's not a diagonal tile.
Sum()
: Get the sum of all elements in all tiles in MPCRTile Matrix.
Prod()
: Get the product of all elements in all tiles in MPCRTile Matrix.
library(MPCR) # Example usage of the class and its methods a <- matrix(1:36, 6, 6) b <- c("double", "double", "single", "double", "half", "double", "half", "double", "single") tile_mat <- new(MPCRTile, 6, 6, 2, 2, a, b) tile_mat sum <- tile_mat$Sum() prod <- tile_mat$Prod() tile_mat$PrintTile(1,1) tile_mat$ChangeTilePrecision(1,1,"single") n_rows <- tile_mat$Row n_cols <- tile_mat$Col total_size <- tile_mat$Size rows_per_tile <- tile_mat$TileRow cols_per_tile <- tile_mat$TileCol
library(MPCR) # Example usage of the class and its methods a <- matrix(1:36, 6, 6) b <- c("double", "double", "single", "double", "half", "double", "half", "double", "single") tile_mat <- new(MPCRTile, 6, 6, 2, 2, a, b) tile_mat sum <- tile_mat$Sum() prod <- tile_mat$Prod() tile_mat$PrintTile(1,1) tile_mat$ChangeTilePrecision(1,1,"single") n_rows <- tile_mat$Row n_cols <- tile_mat$Col total_size <- tile_mat$Size rows_per_tile <- tile_mat$TileRow cols_per_tile <- tile_mat$TileCol
Converters from R to MPCR objects and vice-versa.
An MPCR or R numeric vector/matrix.
Convert R object to MPCR object.
as.MPCR(data,nrow = 0,ncol = 0,precision)
: Converts R object to MPCR object.
data
R matrix/vector.
nrow
Number of rows of the new MPCR matrix, default = zero which means a vector will be created.
ncol
Number of cols of the new MPCR matrix, default = zero which means a vector will be created.
precision
String indicates the precision of the new MPCR object (half, single, or double).
Convert an MPCR object to R object.
MPCR.ToNumericVector(x)
: Converts an MPCR object to a numeric R vector.
x
MPCR object.
MPCR.ToNumericMatrix(x)
: Converts an MPCR object to a numeric R matrix.
x
MPCR object.
# Example usage of the class and its methods library(MPCR) a <- matrix(1:36, 6, 6) MPCR_matrix <- as.MPCR(a,nrow=6,ncol=6,precision="single") r_vector <- MPCR.ToNumericVector(MPCR_matrix) r_vector r_matrix <- MPCR.ToNumericMatrix(MPCR_matrix) r_matrix
# Example usage of the class and its methods library(MPCR) a <- matrix(1:36, 6, 6) MPCR_matrix <- as.MPCR(a,nrow=6,ncol=6,precision="single") r_vector <- MPCR.ToNumericVector(MPCR_matrix) r_vector r_matrix <- MPCR.ToNumericMatrix(MPCR_matrix) r_matrix
Binary arithmetic for numeric/MPCR objects.
## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 + e2 ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 - e2 ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 * e2 ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 / e2 ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 ^ e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 + e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 * e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 - e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 / e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 ^ e2
## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 + e2 ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 - e2 ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 * e2 ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 / e2 ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 ^ e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 + e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 * e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 - e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 / e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 ^ e2
e1 , e2
|
Numeric/MPCR objects. |
An MPCR object, matching the data type of the highest precision input.
library(MPCR) s1 <- as.MPCR(1:20,nrow=2,ncol=10,"single") s2 <- as.MPCR(21:40,nrow=2,ncol=10,"double") x <- s1 + s2 typeof(x) # A 64-bit precision (double) MPCR matrix. s3 <- as.MPCR(1:20,nrow=2,ncol=10,"single") x <- s1 + s3 typeof(x) # A 32-bit precision (single) MPCR matrix.
library(MPCR) s1 <- as.MPCR(1:20,nrow=2,ncol=10,"single") s2 <- as.MPCR(21:40,nrow=2,ncol=10,"double") x <- s1 + s2 typeof(x) # A 64-bit precision (double) MPCR matrix. s3 <- as.MPCR(1:20,nrow=2,ncol=10,"single") x <- s1 + s3 typeof(x) # A 32-bit precision (single) MPCR matrix.
Binary comparison operators for numeric/MPCR objects.
## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 < e2 ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 <= e2 ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 == e2 ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 != e2 ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 > e2 ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 >= e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 < e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 <= e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 == e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 != e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 > e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 >= e2
## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 < e2 ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 <= e2 ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 == e2 ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 != e2 ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 > e2 ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' e1 >= e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 < e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 <= e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 == e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 != e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 > e2 ## S4 method for signature 'Rcpp_MPCR,BaseLinAlg' e1 >= e2
e1 , e2
|
Numeric/MPCR objects. |
A vector/matrix of logicals.
library(MPCR) s1 <- as.MPCR(1:20,nrow=2,ncol=10,"single") s2 <- as.MPCR(21:40,nrow=2,ncol=10,"double") x <- s1 > s2
library(MPCR) s1 <- as.MPCR(1:20,nrow=2,ncol=10,"single") s2 <- as.MPCR(21:40,nrow=2,ncol=10,"double") x <- s1 > s2
Extract or replace elements from an MPCR object using the '[', '[[', '[<-', and '[[<-' operators. When extracting values, they will be converted to double precision. However, if you update a single object, the double value will be cast down to match the precision. If the MPCR object is a matrix and you access it using the 'i' index, the operation is assumed to be performed in column-major order, or using 'i' and 'j' index.
## S4 method for signature 'Rcpp_MPCR' x[i, j, drop = TRUE] ## S4 replacement method for signature 'Rcpp_MPCR' x[i, j, ...] <- value ## S4 method for signature 'Rcpp_MPCR' x[[i, drop = TRUE]] ## S4 replacement method for signature 'Rcpp_MPCR' x[[i, ...]] <- value
## S4 method for signature 'Rcpp_MPCR' x[i, j, drop = TRUE] ## S4 replacement method for signature 'Rcpp_MPCR' x[i, j, ...] <- value ## S4 method for signature 'Rcpp_MPCR' x[[i, drop = TRUE]] ## S4 replacement method for signature 'Rcpp_MPCR' x[[i, ...]] <- value
x |
An MPCR object. |
i |
Row index or indices. |
j |
Column index or indices. |
... |
ignored. |
drop |
ignored. |
value |
A value to replace the selected elements with. |
library(MPCR) x <-as.MPCR(1:50,precision="single") ext <- x[5] x[5] <- 0 x$ToMatrix(5,10) x[2,5] x[3,5] <- 100
library(MPCR) x <-as.MPCR(1:50,precision="single") ext <- x[5] x[5] <- 0 x$ToMatrix(5,10) x[2,5] x[3,5] <- 100
Returns the number of rows or cols in an MPCR object.
## S4 method for signature 'Rcpp_MPCR' nrow(x) ## S4 method for signature 'Rcpp_MPCR' ncol(x)
## S4 method for signature 'Rcpp_MPCR' nrow(x) ## S4 method for signature 'Rcpp_MPCR' ncol(x)
x |
An MPCR object. |
The number of rows/cols in an MPCR object.
library(MPCR) x <- as.MPCR(1:16,4,4,"single") y <- as.MPCR(1:20,4,5,"double") rows_x <- nrow(x) cols_y <- ncol(y)
library(MPCR) x <- as.MPCR(1:16,4,4,"single") y <- as.MPCR(1:20,4,5,"double") rows_x <- nrow(x) cols_y <- ncol(y)
Functions for copying MPCR objects.
An MPCR copy from the input object.
Create a copy of an MPCR object. Typically, using 'equal' creates a new pointer for the object, resulting in any modifications made to object one affecting object two as well.
MPCR.copy(x)
: Create a new copy of an MPCR object.
x
MPCR object.
Create a duplicate of an MPCRTile object. Usually, using 'equal' creates a new pointer for the object, causing any modifications made to object one to affect object two as well.
MPCRTile.copy(x)
: Create a new copy of an MPCRTile matrix.
x
MPCRTile matrix.
library(MPCR) # Example usage of the class and its methods a <- matrix(1:36, 6, 6) MPCR_matrix <- as.MPCR(a,nrow=6,ncol=6,precision="single") # Normal equal '=' will create a new pointer of the object, so any change in object A # will affect object B temp_MPCR_matrix = MPCR_matrix temp_MPCR_matrix[2,2] <- 500 MPCR_matrix[2,2] #500 MPCR_matrix_copy <- MPCR.copy(MPCR_matrix) MPCR_matrix[2,2] <-100 MPCR_matrix_copy[2,2] <- 200 MPCR_matrix[2,2] #100 MPCR_matrix_copy[2,2] #200
library(MPCR) # Example usage of the class and its methods a <- matrix(1:36, 6, 6) MPCR_matrix <- as.MPCR(a,nrow=6,ncol=6,precision="single") # Normal equal '=' will create a new pointer of the object, so any change in object A # will affect object B temp_MPCR_matrix = MPCR_matrix temp_MPCR_matrix[2,2] <- 500 MPCR_matrix[2,2] #500 MPCR_matrix_copy <- MPCR.copy(MPCR_matrix) MPCR_matrix[2,2] <-100 MPCR_matrix_copy[2,2] <- 200 MPCR_matrix[2,2] #100 MPCR_matrix_copy[2,2] #200
c()
function for MPCR objects.
## S4 method for signature 'Rcpp_MPCR' MPCR.Concatenate(x)
## S4 method for signature 'Rcpp_MPCR' MPCR.Concatenate(x)
x |
List of MPCR objects. |
MPCR object containing values from all objects in the list.
library(MPCR) x <- as.MPCR(1:20,precision="single") y <- as.MPCR(1:20,precision="single") list <- c(x,y) new_obj <- MPCR.Concatenate(list)
library(MPCR) x <- as.MPCR(1:20,precision="single") y <- as.MPCR(1:20,precision="single") list <- c(x,y) new_obj <- MPCR.Concatenate(list)
rbind()
and cbind()
for MPCR objects.
## S4 method for signature 'Rcpp_MPCR' MPCR.rbind(x,y) ## S4 method for signature 'Rcpp_MPCR' MPCR.cbind(x,y)
## S4 method for signature 'Rcpp_MPCR' MPCR.rbind(x,y) ## S4 method for signature 'Rcpp_MPCR' MPCR.cbind(x,y)
x |
An MPCR object. |
y |
An MPCR object. |
An MPCR object, matching the data type of the highest precision input.
library(MPCR) # create 2 MPCR matrix a,b a <- as.MPCR(1:20,nrow=2,ncol=10,"single") b <- as.MPCR(21:40,nrow=2,ncol=10,"double") x <- MPCR.rbind(a,b) y <- MPCR.cbind(a,b)
library(MPCR) # create 2 MPCR matrix a,b a <- as.MPCR(1:20,nrow=2,ncol=10,"single") b <- as.MPCR(21:40,nrow=2,ncol=10,"double") x <- MPCR.rbind(a,b) y <- MPCR.cbind(a,b)
Returns the diagonal of an MPCR matrix.
## S4 method for signature 'Rcpp_MPCR' diag(x)
## S4 method for signature 'Rcpp_MPCR' diag(x)
x |
An MPCR matrix. |
An MPCR vector contains the main diagonal of the matrix.
library(MPCR) x <- as.MPCR(1:16,4,4,"single") diag_vals <- diag(x)
library(MPCR) x <- as.MPCR(1:16,4,4,"single") diag_vals <- diag(x)
Min-Max functions for MPCR objects values and indices, all NA values are disregarded.
## S4 method for signature 'Rcpp_MPCR' min(x) ## S4 method for signature 'Rcpp_MPCR' max(x) ## S4 method for signature 'Rcpp_MPCR' which.min(x) ## S4 method for signature 'Rcpp_MPCR' which.max(x)
## S4 method for signature 'Rcpp_MPCR' min(x) ## S4 method for signature 'Rcpp_MPCR' max(x) ## S4 method for signature 'Rcpp_MPCR' which.min(x) ## S4 method for signature 'Rcpp_MPCR' which.max(x)
x |
An MPCR object. |
Min/max value/index.
library(MPCR) x <- as.MPCR(1:20,precision="double") min <-min(x) min_idx <-which.min(x)
library(MPCR) x <- as.MPCR(1:20,precision="double") min <-min(x) min_idx <-which.min(x)
exp/log functions.
## S4 method for signature 'Rcpp_MPCR' exp(x) ## S4 method for signature 'Rcpp_MPCR' expm1(x) ## S4 method for signature 'Rcpp_MPCR' log(x, base = 1) ## S4 method for signature 'Rcpp_MPCR' log10(x) ## S4 method for signature 'Rcpp_MPCR' log2(x)
## S4 method for signature 'Rcpp_MPCR' exp(x) ## S4 method for signature 'Rcpp_MPCR' expm1(x) ## S4 method for signature 'Rcpp_MPCR' log(x, base = 1) ## S4 method for signature 'Rcpp_MPCR' log10(x) ## S4 method for signature 'Rcpp_MPCR' log2(x)
x |
An MPCR object. |
base |
The logarithm base. If base = 1, exp(1) is assumed, only base 1,2, and 10 available. |
An MPCR object of the same dimensions as the input.
library(MPCR) x <- as.MPCR(1:20,precision="double") log(x)
library(MPCR) x <- as.MPCR(1:20,precision="double") log(x)
Finite, infinite, and NaNs.
## S4 method for signature 'Rcpp_MPCR' is.finite(x) ## S4 method for signature 'Rcpp_MPCR' is.infinite(x) ## S4 method for signature 'Rcpp_MPCR' is.nan(x)
## S4 method for signature 'Rcpp_MPCR' is.finite(x) ## S4 method for signature 'Rcpp_MPCR' is.infinite(x) ## S4 method for signature 'Rcpp_MPCR' is.nan(x)
x |
An MPCR object. |
A bool vector/matrix of the same dimensions as the input.
library(MPCR) x <- as.MPCR(1:20,precision="double") is.nan(sqrt(x))
library(MPCR) x <- as.MPCR(1:20,precision="double") is.nan(sqrt(x))
Miscellaneous mathematical functions.
## S4 method for signature 'Rcpp_MPCR' abs(x) ## S4 method for signature 'Rcpp_MPCR' sqrt(x)
## S4 method for signature 'Rcpp_MPCR' abs(x) ## S4 method for signature 'Rcpp_MPCR' sqrt(x)
x |
An MPCR object. |
An MPCR object of the same dimensions as the input.
library(MPCR) x <- as.MPCR(1:20,precision="double") sqrt(x)
library(MPCR) x <- as.MPCR(1:20,precision="double") sqrt(x)
is.na()
,na.omit()
, and na.exclude()
for MPCR objects.
## S4 method for signature 'Rcpp_MPCR' MPCR.is.na(object,index=-1) ## S4 method for signature 'Rcpp_MPCR' MPCR.na.exclude(object,value) ## S4 method for signature 'Rcpp_MPCR' MPCR.na.omit(object)
## S4 method for signature 'Rcpp_MPCR' MPCR.is.na(object,index=-1) ## S4 method for signature 'Rcpp_MPCR' MPCR.na.exclude(object,value) ## S4 method for signature 'Rcpp_MPCR' MPCR.na.omit(object)
object |
MPCR object. |
index |
If a particular index in the MPCR matrix/vector is specified, it will be checked. If no index is provided, all elements will be checked. |
value |
Value to replace all NAN with. |
MPCR.is.na will return matrix/vector/bool according to input of the function.
MPCR.na.exclude & MPCR.na.omit will not return anything.
library(MPCR) x <- as.MPCR(1:20,precision="single") x[1] <- NaN MPCR.is.na(x,index=1) #TRUE MPCR.na.exclude(x,50) x[1] #50
library(MPCR) x <- as.MPCR(1:20,precision="single") x[1] <- NaN MPCR.is.na(x,index=1) #TRUE MPCR.na.exclude(x,50) x[1] #50
Replicates the given input number of times according to count/len , only one should be set at a time, and in case both values are given, only the len value will have effect.
## S4 method for signature 'Rcpp_MPCR' rep(x,count=0,len=0)
## S4 method for signature 'Rcpp_MPCR' rep(x,count=0,len=0)
x |
An MPCR object. |
count |
Value to determine how many times the input value will be replicated. |
len |
Value to determine the required output size, the input will be replicated until it matches the output len size. |
MPCR vector containing the replicated values.
library(MPCR) x <- as.MPCR(1:16,4,4,"single") rep_vals_1 <- rep(x,count=2) #output size will be 16*2 rep_vals_2 <- rep(x,len=2) #output size will be 2
library(MPCR) x <- as.MPCR(1:16,4,4,"single") rep_vals_1 <- rep(x,count=2) #output size will be 16*2 rep_vals_2 <- rep(x,len=2) #output size will be 2
Rounding functions.
## S4 method for signature 'Rcpp_MPCR' ceiling(x) ## S4 method for signature 'Rcpp_MPCR' floor(x) ## S4 method for signature 'Rcpp_MPCR' trunc(x) ## S4 method for signature 'Rcpp_MPCR' round(x, digits = 0)
## S4 method for signature 'Rcpp_MPCR' ceiling(x) ## S4 method for signature 'Rcpp_MPCR' floor(x) ## S4 method for signature 'Rcpp_MPCR' trunc(x) ## S4 method for signature 'Rcpp_MPCR' round(x, digits = 0)
x |
An MPCR object. |
digits |
The number of digits to use in rounding. |
An MPCR object of the same dimensions as the input.
library(MPCR) input <- runif(20,-1,1) x <- as.MPCR(input,precision="double") floor(x)
library(MPCR) input <- runif(20,-1,1) x <- as.MPCR(input,precision="double") floor(x)
Center or scale an MPCR object.
## S4 method for signature 'Rcpp_MPCR' scale(x, center, scale)
## S4 method for signature 'Rcpp_MPCR' scale(x, center, scale)
x |
An MPCR object. |
center , scale
|
Logical or MPCR objects. |
An MPCR matrix.
library(MPCR) input <-as.MPCR(1:50,precision="single") input$ToMatrix(5, 10) temp_center_scale <- as.MPCR(1:10,precision="double") z <- scale(x=input, center=FALSE, scale=temp_center_scale)
library(MPCR) input <-as.MPCR(1:50,precision="single") input$ToMatrix(5, 10) temp_center_scale <- as.MPCR(1:10,precision="double") z <- scale(x=input, center=FALSE, scale=temp_center_scale)
Sweep an MPCR vector through an MPCR matrix.
## S4 method for signature 'Rcpp_MPCR' sweep(x,stat,margin,FUN)
## S4 method for signature 'Rcpp_MPCR' sweep(x,stat,margin,FUN)
x |
An MPCR object. |
stat |
MPCR vector containing the value(s) that should be used in the operation. |
margin |
1 means row; otherwise means column. |
FUN |
Sweeping function; must be one of |
An MPCR matrix of the same type as the highest precision input.
library(MPCR) x <- as.MPCR(1:20,10,2,"single") y <- as.MPCR(1:5,precision="double") sweep_out <- sweep(x, stat=y, margin=1, FUN="+") MPCR.is.double(sweep_out) #TRUE
library(MPCR) x <- as.MPCR(1:20,10,2,"single") y <- as.MPCR(1:5,precision="double") sweep_out <- sweep(x, stat=y, margin=1, FUN="+") MPCR.is.double(sweep_out) #TRUE
Special mathematical functions.
## S4 method for signature 'Rcpp_MPCR' gamma(x) ## S4 method for signature 'Rcpp_MPCR' lgamma(x)
## S4 method for signature 'Rcpp_MPCR' gamma(x) ## S4 method for signature 'Rcpp_MPCR' lgamma(x)
x |
An MPCR object. |
An MPCR object of the same dimensions as the input.
library(MPCR) x <- as.MPCR(1:20,precision="double") lgamma(x)
library(MPCR) x <- as.MPCR(1:20,precision="double") lgamma(x)
Basic trig functions.
## S4 method for signature 'Rcpp_MPCR' sin(x) ## S4 method for signature 'Rcpp_MPCR' cos(x) ## S4 method for signature 'Rcpp_MPCR' tan(x) ## S4 method for signature 'Rcpp_MPCR' asin(x) ## S4 method for signature 'Rcpp_MPCR' acos(x) ## S4 method for signature 'Rcpp_MPCR' atan(x)
## S4 method for signature 'Rcpp_MPCR' sin(x) ## S4 method for signature 'Rcpp_MPCR' cos(x) ## S4 method for signature 'Rcpp_MPCR' tan(x) ## S4 method for signature 'Rcpp_MPCR' asin(x) ## S4 method for signature 'Rcpp_MPCR' acos(x) ## S4 method for signature 'Rcpp_MPCR' atan(x)
x |
An MPCR object. |
An MPCR object of the same dimensions as the input.
library(MPCR) mpcr_matrix <- as.MPCR(1:20,nrow=2,ncol=10,"single") x <- sin(mpcr_matrix)
library(MPCR) mpcr_matrix <- as.MPCR(1:20,nrow=2,ncol=10,"single") x <- sin(mpcr_matrix)
These functions give the obvious hyperbolic functions. They respectively compute the hyperbolic cosine, sine, tangent, and their inverses, arc-cosine, arc-sine, arc-tangent (or 'area cosine', etc).
## S4 method for signature 'Rcpp_MPCR' sinh(x) ## S4 method for signature 'Rcpp_MPCR' cosh(x) ## S4 method for signature 'Rcpp_MPCR' tanh(x) ## S4 method for signature 'Rcpp_MPCR' asinh(x) ## S4 method for signature 'Rcpp_MPCR' acosh(x) ## S4 method for signature 'Rcpp_MPCR' atanh(x)
## S4 method for signature 'Rcpp_MPCR' sinh(x) ## S4 method for signature 'Rcpp_MPCR' cosh(x) ## S4 method for signature 'Rcpp_MPCR' tanh(x) ## S4 method for signature 'Rcpp_MPCR' asinh(x) ## S4 method for signature 'Rcpp_MPCR' acosh(x) ## S4 method for signature 'Rcpp_MPCR' atanh(x)
x |
An MPCR object. |
An MPCR object of the same dimensions as the input.
library(MPCR) mpcr_matrix <- as.MPCR(1:20,nrow=2,ncol=10,precision="single") x <- sinh(mpcr_matrix)
library(MPCR) mpcr_matrix <- as.MPCR(1:20,nrow=2,ncol=10,precision="single") x <- sinh(mpcr_matrix)
Transpose an MPCR object.
## S4 method for signature 'Rcpp_MPCR' t(x)
## S4 method for signature 'Rcpp_MPCR' t(x)
x |
An MPCR object. |
An MPCR object.
library(MPCR) a <- matrix(1:20, nrow = 2) a_MPCR <- as.MPCR(a,2,10,"double") a_MPCR_transpose <- t(a_MPCR)
library(MPCR) a <- matrix(1:20, nrow = 2) a_MPCR <- as.MPCR(a,2,10,"double") a_MPCR_transpose <- t(a_MPCR)
Checks the precision of a given MPCR object.
## S4 method for signature 'Rcpp_MPCR' MPCR.is.single(x) ## S4 method for signature 'Rcpp_MPCR' MPCR.is.half(x) ## S4 method for signature 'Rcpp_MPCR' MPCR.is.double(x) ## S4 method for signature 'Rcpp_MPCR' MPCR.is.float(x)
## S4 method for signature 'Rcpp_MPCR' MPCR.is.single(x) ## S4 method for signature 'Rcpp_MPCR' MPCR.is.half(x) ## S4 method for signature 'Rcpp_MPCR' MPCR.is.double(x) ## S4 method for signature 'Rcpp_MPCR' MPCR.is.float(x)
x |
An MPCR object. |
Boolean indicates the precision of the object according to the used function.
library(MPCR) x <- as.MPCR(1:20,precision="double") MPCR.is.double(x) #TRUE MPCR.is.single(x) #FALSE
library(MPCR) x <- as.MPCR(1:20,precision="double") MPCR.is.double(x) #TRUE MPCR.is.single(x) #FALSE
Metadata functions.
## S4 method for signature 'Rcpp_MPCR' storage.mode(x) ## S4 method for signature 'Rcpp_MPCR' typeof(x) ## S4 method for signature 'Rcpp_MPCR' MPCR.object.size(x) ## S4 method for signature 'Rcpp_MPCR' MPCR.ChangePrecision(x,precision)
## S4 method for signature 'Rcpp_MPCR' storage.mode(x) ## S4 method for signature 'Rcpp_MPCR' typeof(x) ## S4 method for signature 'Rcpp_MPCR' MPCR.object.size(x) ## S4 method for signature 'Rcpp_MPCR' MPCR.ChangePrecision(x,precision)
x |
An MPCR object. |
precision |
String with the required precision. |
Prints/change metadata about an MPCR object.
library(MPCR) x <- as.MPCR(1:20,precision="double") typeof(x) MPCR.ChangePrecision(x,"single") MPCR.is.single(x) #True
library(MPCR) x <- as.MPCR(1:20,precision="double") typeof(x) MPCR.ChangePrecision(x,"single") MPCR.is.single(x) #True
Prints the precision and type of the object, and print will print the meta data of the object without printing the values. Function x$PrintValues() should be used to print the values."
## S4 method for signature 'Rcpp_MPCR' print(x) ## S4 method for signature 'Rcpp_MPCR' show(object)
## S4 method for signature 'Rcpp_MPCR' print(x) ## S4 method for signature 'Rcpp_MPCR' show(object)
x , object
|
An MPCR objects. |
Prints metadata about the object and some values.
A string containing the metadata of the MPCR object.
library(MPCR) x <- as.MPCR(1:16,4,4,"single") y <- as.MPCR(1:20,4,5,"double") x print(y)
library(MPCR) x <- as.MPCR(1:16,4,4,"single") y <- as.MPCR(1:20,4,5,"double") x print(y)
Performs the Cholesky factorization of a positive definite MPCR matrix x.
## S4 method for signature 'Rcpp_MPCR' chol(x,upper_triangle=TRUE)
## S4 method for signature 'Rcpp_MPCR' chol(x,upper_triangle=TRUE)
x |
An MPCR matrix. |
upper_triangle |
Boolean to check on which triangle the cholesky decomposition should be applied. |
An MPCR matrix.
library(MPCR) x <- as.MPCR(c(1.21, 0.18, 0.13, 0.41, 0.06, 0.23, 0.18, 0.64, 0.10, -0.16, 0.23, 0.07, 0.13, 0.10, 0.36, -0.10, 0.03, 0.18, 0.41, -0.16, -0.10, 1.05, -0.29, -0.08, 0.06, 0.23, 0.03, -0.29, 1.71, -0.10, 0.23, 0.07, 0.18, -0.08, -0.10, 0.36),6,6,precision="double") chol_out <- chol(x)
library(MPCR) x <- as.MPCR(c(1.21, 0.18, 0.13, 0.41, 0.06, 0.23, 0.18, 0.64, 0.10, -0.16, 0.23, 0.07, 0.13, 0.10, 0.36, -0.10, 0.03, 0.18, 0.41, -0.16, -0.10, 1.05, -0.29, -0.08, 0.06, 0.23, 0.03, -0.29, 1.71, -0.10, 0.23, 0.07, 0.18, -0.08, -0.10, 0.36),6,6,precision="double") chol_out <- chol(x)
Performs the inverse of the original matrix using the Cholesky factorization of an MPCR matrix x.
## S4 method for signature 'Rcpp_MPCR' chol2inv(x, size = NCOL(x))
## S4 method for signature 'Rcpp_MPCR' chol2inv(x, size = NCOL(x))
x |
An MPCR object. |
size |
The number of columns to use. |
An MPCR object.
library(MPCR) x <- as.MPCR(c(1.21, 0.18, 0.13, 0.41, 0.06, 0.23, 0.18, 0.64, 0.10, -0.16, 0.23, 0.07, 0.13, 0.10, 0.36, -0.10, 0.03, 0.18, 0.41, -0.16, -0.10, 1.05, -0.29, -0.08, 0.06, 0.23, 0.03, -0.29, 1.71, -0.10, 0.23, 0.07, 0.18, -0.08, -0.10, 0.36),6,6,precision="single") chol_out <- chol(x) chol <- chol2inv(chol_out)
library(MPCR) x <- as.MPCR(c(1.21, 0.18, 0.13, 0.41, 0.06, 0.23, 0.18, 0.64, 0.10, -0.16, 0.23, 0.07, 0.13, 0.10, 0.36, -0.10, 0.03, 0.18, 0.41, -0.16, -0.10, 1.05, -0.29, -0.08, 0.06, 0.23, 0.03, -0.29, 1.71, -0.10, 0.23, 0.07, 0.18, -0.08, -0.10, 0.36),6,6,precision="single") chol_out <- chol(x) chol <- chol2inv(chol_out)
Calculates the cross product of two MPCR matrices.
It uses BLAS routine gemm()
for A X B operations and syrk()
for A X A^T operations.
## S4 method for signature 'Rcpp_MPCR' crossprod(x, y = NULL) ## S4 method for signature 'Rcpp_MPCR' tcrossprod(x, y = NULL)
## S4 method for signature 'Rcpp_MPCR' crossprod(x, y = NULL) ## S4 method for signature 'Rcpp_MPCR' tcrossprod(x, y = NULL)
x |
An MPCR object. |
y |
Either |
Calculates cross product of two MPCR matrices performs:
x %*% y , t(x) %*% x
This function uses blas routine gemm()
for A X B operations & syrk()
for A X A^T operations.
An MPCR matrix.
library(MPCR) x <- as.MPCR(1:16,4,4,"single") y <- as.MPCR(1:20,4,5,"double") z <- crossprod(x) # t(x) x z <- tcrossprod(x) # x t(x) z <- crossprod(x,y) # x y z <- x %*% y # x y
library(MPCR) x <- as.MPCR(1:16,4,4,"single") y <- as.MPCR(1:20,4,5,"double") z <- crossprod(x) # t(x) x z <- tcrossprod(x) # x t(x) z <- crossprod(x,y) # x y z <- x %*% y # x y
Solves a system of equations or invert an MPCR matrix, using lapack routine syevr()
## S4 method for signature 'Rcpp_MPCR' eigen(x, only.values = FALSE)
## S4 method for signature 'Rcpp_MPCR' eigen(x, only.values = FALSE)
x |
An MPCR object. |
only.values |
(TRUE/FALSE)? |
A list contains MPCR objects describing the values and optionally vectors.
Check if a given MPCR matrix is symmetric.
## S4 method for signature 'Rcpp_MPCR' isSymmetric(object, ...)
## S4 method for signature 'Rcpp_MPCR' isSymmetric(object, ...)
object |
An MPCR matrix. |
... |
Ignored. |
A logical value.
library(MPCR) x <- as.MPCR(1:50,25,2,"Single") isSymmetric(x) #false
library(MPCR) x <- as.MPCR(1:50,25,2,"Single") isSymmetric(x) #false
Compute norm.
## S4 method for signature 'Rcpp_MPCR' norm(x, type = "O")
## S4 method for signature 'Rcpp_MPCR' norm(x, type = "O")
x |
An MPCR object. |
type |
"O"-ne, "I"-nfinity, "F"-robenius, "M"-ax modulus, and "1" norms. |
An MPCR object.
library(MPCR) x <- as.MPCR(1:20,precision="double") norm(x, type="O")
library(MPCR) x <- as.MPCR(1:20,precision="double") norm(x, type="O")
QR factorization and related functions.
## S4 method for signature 'Rcpp_MPCR' qr(x, tol = 1e-07) ## S4 method for signature 'ANY' qr.Q(qr, complete = FALSE, Dvec) ## S4 method for signature 'ANY' qr.R(qr, complete = FALSE)
## S4 method for signature 'Rcpp_MPCR' qr(x, tol = 1e-07) ## S4 method for signature 'ANY' qr.Q(qr, complete = FALSE, Dvec) ## S4 method for signature 'ANY' qr.R(qr, complete = FALSE)
x |
An MPCR matrix. |
qr |
QR decomposition MPCR object. |
tol |
The tolerance for determining numerical column rank. |
complete |
Should the complete or truncated factor be returned? |
Dvec |
Vector of diagonals to use when re-constructing Q (default is 1's). |
The factorization is performed by the LAPACK routine geqp3()
. This
should be similar to calling qr()
on an ordinary R matrix with the
argument LAPACK=TRUE
.
qr |
Output of |
library(MPCR) qr_input <-as.MPCR( c(1, 2, 3, 2, 4, 6, 3, 3, 3),3,3,"single") qr_out <- qr(qr_input) qr_out
library(MPCR) qr_input <-as.MPCR( c(1, 2, 3, 2, 4, 6, 3, 3, 3),3,3,"single") qr_out <- qr(qr_input) qr_out
Compute matrix norm.
## S4 method for signature 'Rcpp_MPCR' rcond(x, norm = "O", useInv = FALSE)
## S4 method for signature 'Rcpp_MPCR' rcond(x, norm = "O", useInv = FALSE)
x |
An MPCR object. |
norm |
"O"-ne or "I"-nfinity norm. |
useInv |
TRUE to use the lower triangle only. |
An MPCR Object.
library(MPCR) x <- as.MPCR(1:25,precision="double") x$ToMatrix(5,5) rcond(x)
library(MPCR) x <- as.MPCR(1:25,precision="double") x$ToMatrix(5,5) rcond(x)
Solve a system of equations or invert an MPCR matrix.
## S4 method for signature 'Rcpp_MPCR' solve(a, b = NULL, ...)
## S4 method for signature 'Rcpp_MPCR' solve(a, b = NULL, ...)
a , b
|
An MPCR objects. |
... |
Ignored. |
Solves the equation AX=B .and if B=NULL t(A) will be used.
library(MPCR) x <- as.MPCR(1:20,4,5,"double") solve(x)
library(MPCR) x <- as.MPCR(1:20,4,5,"double") solve(x)
SVD factorization.
## S4 method for signature 'Rcpp_MPCR' La.svd(x, nu = min(n, p), nv = min(n, p)) ## S4 method for signature 'Rcpp_MPCR' svd(x, nu = min(n, p), nv = min(n, p))
## S4 method for signature 'Rcpp_MPCR' La.svd(x, nu = min(n, p), nv = min(n, p)) ## S4 method for signature 'Rcpp_MPCR' svd(x, nu = min(n, p), nv = min(n, p))
x |
An MPCR matrix. |
nu , nv
|
The number of left/right singular vectors to return. |
The factorization is performed by the LAPACK routine gesdd()
.
The SVD decomposition of the MPCR matrix.
library(MPCR) svd_vals <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1) x <- as.MPCR(svd_vals,9,4,"single") y <- svd(x)
library(MPCR) svd_vals <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1) x <- as.MPCR(svd_vals,9,4,"single") y <- svd(x)
Solves a system of linear equations where the coefficient matrix is upper or lower triangular. The function solves the equation A X = B
, where A
is the coefficient matrix, X
is the solution vector, and B
is the right-hand side vector.
## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' backsolve(r, x, k = ncol(r), upper.tri = TRUE, transpose = FALSE) ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' forwardsolve(l, x, k = ncol(l), upper.tri = FALSE, transpose = FALSE)
## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' backsolve(r, x, k = ncol(r), upper.tri = TRUE, transpose = FALSE) ## S4 method for signature 'Rcpp_MPCR,Rcpp_MPCR' forwardsolve(l, x, k = ncol(l), upper.tri = FALSE, transpose = FALSE)
l |
An MPCR object. |
r |
An MPCR object. |
x |
An MPCR object whose columns give the right-hand sides for the equations. |
k |
The number of columns of r and rows of x to use. |
upper.tri |
logical; if TRUE, the upper triangular part of r is used. Otherwise, the lower one. |
transpose |
logical; if TRUE, solve for t( l , r ) %*% output == x. |
An MPCR object represents the solution to the system of linear equations.
library(MPCR) a <- matrix(c(2, 0, 0, 3), nrow = 2) b <- matrix(c(1, 2), nrow = 2) a_MPCR <- as.MPCR(a,2,2,"single") b_MPCR <- as.MPCR(b,2,1,"double") x <- backsolve(a_MPCR, b_MPCR)
library(MPCR) a <- matrix(c(2, 0, 0, 3), nrow = 2) b <- matrix(c(1, 2), nrow = 2) a_MPCR <- as.MPCR(a,2,2,"single") b_MPCR <- as.MPCR(b,2,1,"double") x <- backsolve(a_MPCR, b_MPCR)
Performs matrix-matrix multiplication of two given MPCR matrices to performs:
C = alpha A * B + beta C
C = alpha A A^T + beta C
## S4 method for signature 'Rcpp_MPCR' MPCR.gemm(a,b = NULL,c,transpose_a= FALSE,transpose_b=FALSE,alpha=1,beta=0)
## S4 method for signature 'Rcpp_MPCR' MPCR.gemm(a,b = NULL,c,transpose_a= FALSE,transpose_b=FALSE,alpha=1,beta=0)
a |
An MPCR matrix A. |
b |
An MPCR matrix B, if NULL, the function will perform syrk operation from blas. |
c |
Input/Output MPCR matrix C. |
transpose_a |
A flag to indicate whether transpose matrix A should be used, if B is NULL and transpose_a =TRUE
|
transpose_b |
A flag to indicate whether transpose matrix B should be used. |
alpha |
Specifies the scalar alpha. |
beta |
Specifies the scalar beta. |
An MPCR matrix.
Solves a triangular matrix equation.
performs:
op(A)*X=alpha*B
X*op(A)=alpha*B
## S4 method for signature 'Rcpp_MPCR' MPCR.trsm(a,b,upper_triangle,transpose,side = 'L',alpha =1)
## S4 method for signature 'Rcpp_MPCR' MPCR.trsm(a,b,upper_triangle,transpose,side = 'L',alpha =1)
a |
MPCR Matrix A. |
b |
MPCR Matrix B. |
upper_triangle |
If the value is TRUE, the referenced part of matrix A corresponds to the upper triangle, with the opposite triangle assumed to contain zeros. |
transpose |
If TRUE, the transpose of A is used. |
side |
'R for Right side, 'L' for Left side. |
alpha |
Factor used for A, If alpha is zero, A is not accessed. |
An MPCR Matrix.
Tile-based matrix-matrix multiplication of two given MPCR tiled matrices to
perform:
C = alpha*A X B + beta*C
## S4 method for signature 'Rcpp_MPCRTile' MPCRTile.gemm(a,b,c,transpose_a= FALSE,transpose_b=FALSE,alpha=1,beta=0,num_threads=1)
## S4 method for signature 'Rcpp_MPCRTile' MPCRTile.gemm(a,b,c,transpose_a= FALSE,transpose_b=FALSE,alpha=1,beta=0,num_threads=1)
a |
An MPCR tile matrix A. |
b |
An MPCR tile matrix B. |
c |
Input/Output MPCR tile matrix C. |
transpose_a |
A flag to indicate whether transpose matrix A should be used. |
transpose_b |
A flag to indicate whether transpose matrix B should be used. |
alpha |
Specifies the scalar alpha. |
beta |
Specifies the scalar beta. |
num_threads |
An integer to determine number if thread to run using openmp, default = 1 (serial with no parallelization). |
An MPCR tile matrix C.
Tile-based Cholesky decomposition of a positive definite tile-based symmetric matrix.
## S4 method for signature 'Rcpp_MPCRTile' chol(x, overwrite_input = TRUE, num_threads = 1)
## S4 method for signature 'Rcpp_MPCRTile' chol(x, overwrite_input = TRUE, num_threads = 1)
x |
An MPCR tile matrix. |
overwrite_input |
A flag to determine whether to overwrite the input ( TRUE ), or return a new MPCR tile matrix. |
num_threads |
An integer to determine number if thread to run using openmp, default = 1 (serial with no parallelization). |
An MPCR tile matrix.
Tile-based algorithm to solve a triangular matrix equation for MPCR tiled matrices.
performs:
op(A)*X=alpha*B
X*op(A)=alpha*B
## S4 method for signature 'Rcpp_MPCRTile' MPCRTile.trsm(a,b,side,upper_triangle,transpose,alpha)
## S4 method for signature 'Rcpp_MPCRTile' MPCRTile.trsm(a,b,side,upper_triangle,transpose,alpha)
a |
An MPCR tile matrix A. |
b |
An MPCR tile matrix B, X after returning. |
side |
'R' for right side, 'L' for left side. |
upper_triangle |
What part of the matrix A is referenced (if TRUE upper triangle is referenced), the opposite triangle being assumed to be zero. |
transpose |
If TRUE, the transpose of A is used. |
alpha |
Factor used for A, If alpha is zero, A is not accessed. |
An MPCR Tile Matrix B ->(X).