Main Content

gpu2nndata

Reformat neural data back from GPU

Syntax

X = gpu2nndata(Y,Q)
X = gpu2nndata(Y)
X = gpu2nndata(Y,Q,N,TS)

Description

Training and simulation of neural networks require that matrices be transposed. But they do not require (although they are more efficient with) padding of column length so that each column is memory aligned. This function copies data back from the current GPU and reverses this transform. It can be used on data formatted with nndata2gpu or on the results of network simulation.

X = gpu2nndata(Y,Q) copies the QQ-by-N gpuArray Y into RAM, takes the first Q rows and transposes the result to get an N-by-Q matrix representing Q N-element vectors.

X = gpu2nndata(Y) calculates Q as the index of the last row in Y that is not all NaN values (those rows were added to pad Y for efficient GPU computation by nndata2gpu). Y is then transformed as before.

X = gpu2nndata(Y,Q,N,TS) takes a QQ-by-(N*TS) gpuArray where N is a vector of signal sizes, Q is the number of samples (less than or equal to the number of rows after alignment padding QQ), and TS is the number of time steps.

The gpuArray Y is copied back into RAM, the first Q rows are taken, and then it is partitioned and transposed into an M-by-TS cell array, where M is the number of elements in N. Each Y{i,ts} is an N(i)-by-Q matrix.

Examples

Copy a matrix to the GPU and back:

x = rand(5,6)
[y,q] = nndata2gpu(x)
x2 = gpu2nndata(y,q)

Copy from the GPU a neural network cell array data representing four time series, each consisting of five time steps of 2-element and 3-element signals.

x = nndata([2;3],4,5)
[y,q,n,ts] = nndata2gpu(x)
x2 = gpu2nndata(y,q,n,ts)

Version History

Introduced in R2012b

See Also