Learn R Programming

pbdDMAT (version 0.2-3)

Diag: Distributed Matrix Diagonals

Description

Get the diagonal of a distributed matrix, or construct a distributed matrix which is diagonal.

Usage

## S3 method for class 'ddmatrix':
diag(x)
## S3 method for class 'vector':
diag(x, nrow, ncol, type = "matrix", ..., 
                        bldim = .BLDIM, ICTXT = .ICTXT)
## S3 method for class 'character':
diag(x, nrow, ncol, type = "matrix", ..., 
                           min = 0, max = 1, mean = 0, sd = 1,
                           rate = 1, shape, scale = 1, 
                           bldim = .BLDIM, ICTXT = .ICTXT)

Arguments

x
distributed matrix or a vector.
nrow,ncol
in the case that x is a vector, these specify the global dimension of the diagonal distributed matrix to be created.
type
character. Options are 'matrix' or 'ddmatrix', with partial matching. This specifies the return type.
...
Extra arguments
min, max
Min and max values for random uniform generation.
mean,sd
Mean and standard deviation for random normal generation.
rate
Rate for random exponential generation.
shape,scale
Shape and scale parameters for random weibull generation.
bldim
blocking dimension.
ICTXT
BLACS context number.

Value

  • If a distributed matrix is passed to diag() then it returns a global R vector. If a vector (numeric or character) is passed to diag() and type='ddmatrix', then the return is a diagonal distributed matrix.

Details

Gets the diagonal of a distributed matrix and stores it as a global R vector owned by all processes.

See Also

Extract

Examples

Run this code
# Save code in a file "demo.r" and run with 2 processors by
# > mpiexec -np 2 Rscript demo.r

library(pbdDMAT, quiet = TRUE)
init.grid()

# don't do this in production code
x <- matrix(1:16, 4)
x <- as.ddmatrix(x)

y <- diag(x)
comm.print(y)

finalize()

Run the code above in your browser using DataLab