Learn R Programming

gmatrix (version 0.3)

gdup: Duplicate a GPU object

Description

This function duplicates a gmatrix or gvector object on the specified device.

Usage

gdup(x, dev=getDevice())

Arguments

x
object to duplicate
dev
device to duplicate the object on

Value

a gmatrix or gvector object.

Details

This function is very important because the gmatrix and gvector classes store only a pointer to an object on the GPU device. Thus, a line such as y<-x will duplicate the pointer but not the actual data on the GPU. One should use instead y<-gdup(x). The gdup function is also useful for copying the data to a different GPU device.

See Also

To move data to a different device instead of copying it see device

Examples

Run this code

#problematic code
x=gseq(1,10)
y=x 
x[1]=1000 
show(y)#changes to x also change y

#correct
x=gseq(1,10)
y=gdup(x) 
x[1]=1000 
show(y) #changes to x do not change y

#copy to a different device 
#y=gdup(x, dev=2L)

Run the code above in your browser using DataLab