Main Content

Work with Sparse Arrays on a GPU

Create Sparse GPU Arrays

You can create a sparse gpuArray either by calling sparse with a gpuArray input, or by calling gpuArray with a sparse input. For example,

x = [0 1 0 0 0; 0 0 0 0 1]
     0     1     0     0     0
     0     0     0     0     1
s = sparse(x)
   (1,2)        1
   (2,5)        1
g = gpuArray(s);   % g is a sparse gpuArray
gt = transpose(g); % gt is a sparse gpuArray
f = full(gt)       % f is a full gpuArray
     0     0
     1     0
     0     0
     0     0
     0     1

Functions That Support Sparse GPU Arrays

Sparse gpuArray objects do not support indexing. Instead, use find to locate nonzero elements of the array and their row and column indices. Then, replace the values you want and construct a new sparse gpuArray.

This tables lists functions support sparse gpuArray objects.

abs
acos
acosd
acosh
acot
acotd
acoth
acsc
acscd
acsch
angle
asec
asecd
asech
asin
asind
asinh
atan
atand
atanh
bicg
bicgstab
ceil
cgs
classUnderlying
conj
cos
cosd
cosh
cospi
cot
cotd
coth
csc
cscd
csch
ctranspose
deg2rad
diag
end
eps
exp
expint
expm1
find
fix
floor
full
gmres
gpuArray.speye
imag
isaUnderlying
isdiag
isempty
isequal
isequaln
isfinite
isfloat
isinteger
islogical
isnumeric
isreal
issparse
istril
istriu
isUnderlyingType
length
log
log2
log10
log1p
lsqr
minus
mtimes
mustBeUnderlyingType
ndims
nextpow2
nnz
nonzeros
norm
numel
nzmax
pcg
plus
qmr
rad2deg
real
reallog
realsqrt
round
sec
secd
sech
sign
sin
sind
sinh
sinpi
size
sparse
spfun
spones
sprandsym
sqrt
sum
tan
tand
tanh
tfqmr
times (.*)
trace
transpose
tril
triu
uminus
underlyingType
uplus 
  

See Also

|

Related Topics