Learn R Programming

gmatrix (version 0.3)

gmatrix: Create and object of class gmatrix

Description

This function creates a gmatrix object from an input value.

Usage

gmatrix(data = NA, nrow = 1L, ncol = 1L, byrow = FALSE, dimnames = NULL, type = NULL, dup = TRUE)

Arguments

data
The input data. Must be a vector or gvector.
nrow
the desired number of rows
ncol
the desired number of rows.
byrow
logical. If FALSE (the default) the matrix is filled by columns, otherwise the matrix is filled by rows.
dimnames
A dimnames attribute for the matrix: NULL or a list of length 2 giving the row and column names respectively. An empty list is treated as NULL.
type
The type (i.e. "double", "single", "integer" or "logical")
dup
dup=FALSE will return the original data without duplicating it on the GPU. The dup=FALSE should only be used if the data in the input will not be used in it's original form again.

Value

returns a gmatrix object.

Details

This is implemented in a very similar fashion to the matrix function in R base.

See Also

matrix

Examples

Run this code
x=gmatrix(grnorm(100),10,10, type='d') #this makes an unneeded duplication
x=gmatrix(grnorm(100),10,10, dup=FALSE) #this avoids the duplication

#problematic code
x=grnorm(100)
y=as.gmatrix(x,10,10, dup=FALSE) #don't do this
y[1,1]=100 #this changes both y and x because both point to the same spot in GPU memory
x

Run the code above in your browser using DataLab