Skip to contents

Zero-based Wrapper for Sparse Matrices

Zero-based Wrapper for Sparse Matrices

Details

matrixZeroBasedView is a wrapper shim for a matrix or Matrix::sparseMatrix that allows elemental matrix access using zero-based indices.

Methods


Method new()

Initialize (lifecycle: maturing).

Usage

Arguments

x

A matrix.


Method take()

Zero-based matrix element access.

Usage

matrixZeroBasedView$take(i = NULL, j = NULL)

Arguments

i

Row index (zero-based).

j

Column index (zero-based).

Returns

The specified matrix slice as another matrixZeroBasedView.


Method dim()

dim.

Usage

matrixZeroBasedView$dim()

Returns

The dimensions of the matrix.


Method nrow()

nrow.

Usage

matrixZeroBasedView$nrow()

Returns

Matrix row count.


Method ncol()

ncol.

Usage

matrixZeroBasedView$ncol()

Returns

Matrix column count.


Method get_one_based_matrix()

Get the one-based R matrix with its original class.

Usage

matrixZeroBasedView$get_one_based_matrix()

Returns

One-based matrix.


Method sum()

Perform arithmetic sum between this matrixZeroBasedView and another matrixZeroBasedView.

Usage

matrixZeroBasedView$sum(x)

Arguments

x

the matrixZeroBasedView to sum.

Returns

The result of the sum as a matrixZeroBasedView.


Method print()

print.

Usage

matrixZeroBasedView$print()

Returns

Invisibly returns self.


Method clone()

The objects of this class are cloneable with this method.

Usage

matrixZeroBasedView$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

(mat <- Matrix::rsparsematrix(3L, 3L, 0.3))
#> 3 x 3 sparse Matrix of class "dgCMatrix"
#>                  
#> [1,]  .    0.84 .
#> [2,] -0.27 .    .
#> [3,]  .    0.24 .
(mat0 <- matrixZeroBasedView$new(mat))
#> Non-mutable 0-based 'view' class for matrices.
#> To get 1-based matrix use `x$get_one_based_matrix()
#> Dimensions: 3x3

mat0$take(0, 0)
#> Non-mutable 0-based 'view' class for matrices.
#> To get 1-based matrix use `x$get_one_based_matrix()
#> Dimensions: 1x1
mat0$take(0, 0:2)$get_one_based_matrix()
#> 1 x 3 sparse Matrix of class "dgCMatrix"
#>              
#> [1,] . 0.84 .