MPCR: MPCR S4 Class

01-MPCRR Documentation

MPCR S4 Class

Description

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.

Value

MPCR object (constructor - accessors - methods)

Constructor

new Creates a new instance of zero values of the MPCR class. new(MPCR,size, "precision","placement")

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").

placement

String to indicate whether the allocation should be made on CPU (default) or GPU ("CPU","GPU") .

Accessors

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.

Methods

The following methods are available for objects of class MPCR:

PrintValues

PrintValues(): Prints all the values stored in the matrix or vector, along with metadata about the object.

ToMatrix

ToMatrix(row,col): Changes the object representation to match the new dimensions, no memory overhead.

ToVector

ToVector(): Changes the MPCR matrix to vector, no memory overhead.

IsGPUAllocated

IsGPUAllocated(): Returns TRUE if the MPCR object is allocated on GPU.

IsCPUAllocated

IsCPUAllocated(): Returns TRUE if the MPCR object is allocated on CPU.

FreeGPU

FreeGPU(): Free the data allocated on GPU.

FreeCPU

FreeCPU(): Free the data allocated on CPU.

Examples

  
    # 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
  

MPCR documentation built on Aug. 23, 2026, 5:10 p.m.

Related to MPCR in MPCR...