GPU 上でのスパース配列の処理
スパースな GPU 配列の作成
gpuArray
入力を指定して sparse
を呼び出すか、スパース入力を指定して gpuArray
を呼び出すことで、スパースな gpuArray
を作成できます。以下に例を示します。
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(G); % 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
GPU 配列のインデックス付け
スパースな GPU 配列は、行または列全体のインデックスによる参照のみをサポートします。たとえば、スパース行列 A
の 5 番目の行にアクセスするには、A(5,:)
または A(5,1:end)
を呼び出します。
A = gpuArray.speye(10); A(5,:)
(1,5) 1
full(A(5,:))
0 0 0 0 1 0 0 0 0 0
スパースな GPU 配列の非ゼロ要素を見つけるには、関数 find
を使用します。次に、必要な値を置き換えて、スパースな gpuArray
を新たに作成できます。
A = gpuArray.speye(10); [row,col] = find(A); [row,col]
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
スパースな GPU 配列にインデックスによって値を割り当てることはサポートされていません。
スパースな GPU 配列をサポートする関数
次の表に、スパースな gpuArray
オブジェクトをサポートする関数を示します。
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 mpower mustBeUnderlyingType ndims nextpow2 nnz nonzeros | norm numel nzmax pcg plus power qmr rad2deg real reallog realsqrt round sec secd sech sign sin sind sinh sinpi size sparse spfun spones sprandsym sqrt subsref sum tan tand tanh tfqmr times (.*) trace transpose tril triu uminus underlyingType uplus |