| Title: | Multi Precision Computing |
|---|---|
| Description: | Provides new data-structure support for multi- and mixed-precision for R users.The package supports 16-bit, 32-bit, and 64-bit operations. To the best of our knowledge, 'MPCR' differs from the currently available packages in the following:'MPCR' introduces a new data structure that supports three different precisions (16-bit, 32-bit, and 64-bit), allowing for optimized memory allocation based on the desired precision. This feature offers significant advantages in-memory optimization. 'MPCR' extends support to all basic linear algebra methods across different precisions. 'MPCR' maintains a consistent interface with normal R functions, allowing for seamless code integration and a user-friendly experience. |
| Authors: | David Helmy [aut, cph], Sameh Abdulah [cre, cph], KAUST King Abdullah University of Science and Technology [fnd, cph], Brightskies [cph] |
| Maintainer: | Sameh Abdulah <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 2.0.0 |
| Built: | 2026-05-22 19:17:56 UTC |
| Source: | https://github.com/stsds/mpcr |
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)) on CPU and GPU. MPCR uses smart cache memory allocation system that minimize the number of memory transfers required during the transition from CPU to GPU operations and vice verse. So the object at some point can be allocated on both CPU and GPU, in case, the user needed to free specific allocation, helper functions can be used.
MPCR object (constructor - accessors - methods)
new Creates a new instance of zero values of the MPCR class.
new(MPCR,size, "precision","placement")
sizeThe total number of values for which memory needs to be allocated.
precisionString to indicate the precision of MPCR object ("half","single", or "double").
placementString to indicate whether the allocation should be made on CPU (default) or GPU ("CPU","GPU") .
The following accessors can be used to get the values of the slots:
IsMatrixBoolean to indicate whether the MPCR object is a vector or matrix.
SizeTotal number of elements inside the object, (row*col) in the case of matrix, and number of elements in the case of vector.
RowNumber of rows.
ColNumber 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.
IsGPUAllocated(): Returns TRUE if the MPCR object is allocated on GPU.
IsCPUAllocated(): Returns TRUE if the MPCR object is allocated on CPU.
FreeGPU(): Free the data allocated on GPU.
FreeCPU(): Free the data allocated on CPU.
# Example usage of the class and its methods library(MPCR) MPCR_object <- new(MPCR,50,"single","CPU") 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$IsCPUAllocated() #TRUE MPCR_object$IsGPUAllocated() #FALSE MPCR_object# Example usage of the class and its methods library(MPCR) MPCR_object <- new(MPCR,50,"single","CPU") 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$IsCPUAllocated() #TRUE MPCR_object$IsGPUAllocated() #FALSE MPCR_object
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,placement): Converts R object to MPCR object.
dataR matrix/vector.
nrowNumber of rows of the new MPCR matrix, default = zero which means a vector will be created.
ncolNumber of cols of the new MPCR matrix, default = zero which means a vector will be created.
precisionString indicates the precision of the new MPCR object (half, single, or double).
placementString indicates whether the data should be allocated on CPU (default) or GPU ("CPU", "GPU")
Convert an MPCR object to R object.
MPCR.ToNumericVector(x): Converts an MPCR object to a numeric R vector.
xMPCR object.
MPCR.ToNumericMatrix(x): Converts an MPCR object to a numeric R matrix.
xMPCR 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", placement="CPU") 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", placement="CPU") 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 > s2library(MPCR) s1 <- as.MPCR(1:20,nrow=2,ncol=10,"single") s2 <- as.MPCR(21:40,nrow=2,ncol=10,"double") x <- s1 > s2
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.
xMPCR object.
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] #200library(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
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)
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] <- 100library(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
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] #50library(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 2library(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") x$ToMatrix(5, 10) temp_center_scale <- new(1:10,precision="double") z <- scale(x=input, center=FALSE, scale=temp_center_scale)library(MPCR) input <-as.MPCR(1:50,precision="single") x$ToMatrix(5, 10) temp_center_scale <- new(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) #TRUElibrary(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) #FALSElibrary(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) #Truelibrary(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 ylibrary(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.
library(MPCR) s <- runif(10, 3) cross_prod <- crossprod(s) x <- as.MPCR(cross_prod,nrow(cross_prod),nrow(cross_prod),precision) y <- eigen(x)library(MPCR) s <- runif(10, 3) cross_prod <- crossprod(s) x <- as.MPCR(cross_prod,nrow(cross_prod),nrow(cross_prod),precision) y <- eigen(x)
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 crossprod_output<-crossprod(x) isSymmetric(crossprod_output) #truelibrary(MPCR) x <- as.MPCR(1:50,25,2,"Single") isSymmetric(x) #false crossprod_output<-crossprod(x) isSymmetric(crossprod_output) #true
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 qr_out[["qr"]]$PrintValues() qr_out[["qraux"]]$PrintValues() qr_out[["pivot"]]$PrintValues() qr_out[["rank"]]$PrintValues() qr_q <- qr.Q(qr_out) qr_qlibrary(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 qr_out[["qr"]]$PrintValues() qr_out[["qraux"]]$PrintValues() qr_out[["pivot"]]$PrintValues() qr_out[["rank"]]$PrintValues() qr_q <- qr.Q(qr_out) qr_q
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:20,precision="double") rcond(x)library(MPCR) x <- as.MPCR(1:20,precision="double") 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") y <- crossprod(x) solve(y)library(MPCR) x <- as.MPCR(1:20,4,5,"double") y <- crossprod(x) solve(y)
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 <- forwardsolve(a_MPCR, b_MPCR) xlibrary(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 <- forwardsolve(a_MPCR, b_MPCR) x
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.
library(MPCR) # create 3 MPCR matrices a,b,c print(c) MPCR.gemm(a,b,c,transpose_a=false,transpose_b=TRUE,alpha=1,beta=1) print(c)library(MPCR) # create 3 MPCR matrices a,b,c print(c) MPCR.gemm(a,b,c,transpose_a=false,transpose_b=TRUE,alpha=1,beta=1) print(c)
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.
library(MPCR) a <- matrix(c(3.12393, -1.16854, -0.304408, -2.15901, -1.16854, 1.86968, 1.04094, 1.35925, -0.304408, 1.04094, 4.43374, 1.21072, -2.15901, 1.35925, 1.21072, 5.57265), 4,4) mat_a <- as.MPCR(a,4,4,"single") mat_b <- as.MPCR(a,4,4,"double") MPCR.trsm(a=mat_a,b=mat_b,side='R',upper_triangle=TRUE,transpose=FALSE,alpha=1) print(mat_b)library(MPCR) a <- matrix(c(3.12393, -1.16854, -0.304408, -2.15901, -1.16854, 1.86968, 1.04094, 1.35925, -0.304408, 1.04094, 4.43374, 1.21072, -2.15901, 1.35925, 1.21072, 5.57265), 4,4) mat_a <- as.MPCR(a,4,4,"single") mat_b <- as.MPCR(a,4,4,"double") MPCR.trsm(a=mat_a,b=mat_b,side='R',upper_triangle=TRUE,transpose=FALSE,alpha=1) print(mat_b)
The Context Placement handling mechanism used by MPCR manages the dispatch of operations to either the CPU or GPU. When the operation placement is set to "GPU," all operations with GPU implementations (e.g., Linear Algebra functions) will execute on the GPU. If an operation is not supported on the GPU, it will execute on the CPU without altering the Context Placement for subsequent code execution.
By default, the placement is set to the CPU at the start of execution. To switch to GPU placement, users must use specific functions to set and get the current placement.
The Context Placement mechanism does not control initial memory allocation. For optimal performance, users should be aware of where data is allocated. If the user is uncertain about data allocation, the package will automatically manage allocation and data movement between the CPU and GPU. It employs an internal caching mechanism to minimize memory transfers, although data might be allocated on both the CPU and GPU during the object's lifetime. Helper functions are available to check if memory is allocated on the CPU/GPU and to free memory on either one.
Operation Context (Setting and Getting).
MPCR.SetOperationPlacement Set the placement for the up-coming flow of code ( "CPU", "GPU").
MPCR.SetOperationPlacement(placement)
placementString to indicate on which hardware should the up-coming flow of code be executed.
MPCR.GetOperationPlacement Get the placement used currently for dispatching operations ( "CPU", "GPU").
MPCR.GetOperationPlacement()
returns the placement currently used for operations.
library(MPCR) values <- c(3.12393, -1.16854, -0.304408, -2.15901, -1.16854, 1.86968, 1.04094, 1.35925, -0.304408, 1.04094, 4.43374, 1.21072, -2.15901, 1.35925, 1.21072, 5.57265) x <- new(MPCR, 16, "float","GPU") # Data will be allocated on GPU y <- new(MPCR, 16, "float","GPU") # Since this two for loops changes the data inside the MPCR objects, # the GPU memory will be freed. for (val in 1:16) { x[[val]] <- values[[val]] y[[val]] <- values[[val]] } # At this point only CPU memory is allocated. x$ToMatrix(4, 4) y$ToMatrix(4, 4) paste("X and Y values") x$PrintValues() # CPU Function y$PrintValues() # CPU Function MPCR.SetOperationPlacement("GPU") # Set Function Dispatching to GPU cat("----------------------- CrossProduct C=XY --------------------\n") # GPU Cuda Kernel, The data will be automatically copied to GPU. crossproduct <- crossprod(x, y) # Data won't be moved to CPU, since crossprod didn't change the content. x$PrintValues() # CPU Function y$PrintValues() # CPU Function # CPU Function, so the data will be copied to CPU after finalizing the GPU Call. crossproduct$PrintValues()library(MPCR) values <- c(3.12393, -1.16854, -0.304408, -2.15901, -1.16854, 1.86968, 1.04094, 1.35925, -0.304408, 1.04094, 4.43374, 1.21072, -2.15901, 1.35925, 1.21072, 5.57265) x <- new(MPCR, 16, "float","GPU") # Data will be allocated on GPU y <- new(MPCR, 16, "float","GPU") # Since this two for loops changes the data inside the MPCR objects, # the GPU memory will be freed. for (val in 1:16) { x[[val]] <- values[[val]] y[[val]] <- values[[val]] } # At this point only CPU memory is allocated. x$ToMatrix(4, 4) y$ToMatrix(4, 4) paste("X and Y values") x$PrintValues() # CPU Function y$PrintValues() # CPU Function MPCR.SetOperationPlacement("GPU") # Set Function Dispatching to GPU cat("----------------------- CrossProduct C=XY --------------------\n") # GPU Cuda Kernel, The data will be automatically copied to GPU. crossproduct <- crossprod(x, y) # Data won't be moved to CPU, since crossprod didn't change the content. x$PrintValues() # CPU Function y$PrintValues() # CPU Function # CPU Function, so the data will be copied to CPU after finalizing the GPU Call. crossproduct$PrintValues()