02-MPCRTile | R Documentation |
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.