필터 지우기
필터 지우기

kron on distributed arrays ?

조회 수: 2 (최근 30일)
Hugo
Hugo 2014년 2월 3일
답변: Hugo 2014년 2월 5일
Hi everyone, I need to perform Kronecker products on (sparse) distributed arrays however the kron function is unfortunately not handled. I tried to edit the Matlab function and it appears that only the last line:
K = sparse(ik,jk,bsxfun(@times,sb,sa.'),ma*mb,na*nb);
produces an issue within an spdm loop
Any clue about how to overcome this? The error message is:
Error detected on lab(s) 1 2.
Caused by:
Error using codistributed/sparse>iCallSparseImpl (line 122)
Operands to the || and && operators must be convertible to logical scalar values.
Operands to the || and && operators must be convertible to logical scalar values.
Error using codistributed/sparse>iCallSparseImpl (line 122)
Operands to the || and && operators must be convertible to logical scalar values.
Operands to the || and && operators must be convertible to logical scalar values.
--
Thanks in advance
  댓글 수: 2
Walter Roberson
Walter Roberson 2014년 2월 4일
When you use kron, are you doing no-trivial multiplications with it, or are you using it for its "replicate" behavior, where one of the arrays has only 0 and 1 entries ?
Hugo
Hugo 2014년 2월 4일
I'm actually using kron as a tensor product not to replicate.

댓글을 달려면 로그인하십시오.

채택된 답변

Hugo
Hugo 2014년 2월 4일
The following code seems to work like a charm producing a distributed output:
S = speye(10);
S = distributed(S);
[i,j,s] = find(S);
[m,n] = size(S);
S = sparse(i,j,s,m,n);
whos
While this one (from kron function) doesn't:
A=speye(10);
B=speye(10);
A=distributed(A);
B=distributed(B);
[ma,na] = size(A);
[mb,nb] = size(B);
[ia,ja,sa] = find(A);
[ib,jb,sb] = find(B);
ia = ia(:); ja = ja(:); sa = sa(:);
ib = ib(:); jb = jb(:); sb = sb(:);
ik = bsxfun(@plus, mb*(ia-1).', ib);
jk = bsxfun(@plus, nb*(ja-1).', jb);
sk = bsxfun(@times,sb,sa.');
whos
K = sparse(ik,jk,sk,ma*mb,na*nb);
Altough the inputs to sparse in both case are of the same nature somethiong I'm really missing here.
  댓글 수: 3
Hugo
Hugo 2014년 2월 5일
편집: Hugo 2014년 2월 5일
That's a good clue indeed, thanks. So the question is why distributed array don't accept such input to sparse ?
Walter Roberson
Walter Roberson 2014년 2월 5일
If, hypothetically, the code had something like,
if ~any(ColIdx) && ~any(RowIdx)
then that would work for vectors because the any() would reduce the vectors to scalars, but it would fail for 2D arrays because you would be left with vectors connected by &&
You would need to look at codistributed/sparse>iCallSparseImpl (line 122) to see what the actual code is; I do not have that toolbox. The documentation for sparse() does say "vectors" in the positions.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Hugo
Hugo 2014년 2월 5일
I managed to overcome the issue rewriting the kron function which body reads
[ma,na] = size(A);
[mb,nb] = size(B);
[ia,ja,sa] = find(A);
[ib,jb,sb] = find(B);
ia = ia(:); ja = ja(:); sa = sa(:);
ib = ib(:); jb = jb(:); sb = sb(:);
ik = bsxfun(@plus, mb*(ia-1).', ib);
jk = bsxfun(@plus, nb*(ja-1).', jb);
sk = bsxfun(@times,sb,sa.');
ik=reshape(ik,numel(ik),1); % added
jk=reshape(jk,numel(jk),1); % added
sk=reshape(sk,numel(sk),1); % added
K = sparse(ik,jk,sk,ma*mb,na*nb);
To summarize matrix input to sparse is handled for regular data but not for distributed ones.
Special thank to Walter that noticed about the matrix nature of ik, jk and sk

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by