【发布时间】:2018-03-21 22:39:29
【问题描述】:
给定矩阵A 和B,热带乘积被定义为通常的矩阵乘积,乘法换成加法,加法换成minimum。也就是说,它返回一个新矩阵C,这样,
C_ij = minimum(A_ij, B_ij, A_i1 + B_1j, A_i2 + B_12,..., A_im + B_mj)
给定图g 的底层邻接矩阵A_g,关于热带积的nth“幂”表示最多在n 步骤中可达的节点之间的连接。也就是说,如果节点i 和j 由m<=n 边分隔,则C_ij = (A**n)_ij 的值是m。
一般来说,给定一些带有N 节点的图。图的直径最多只能是N;并且,给定一个直径为k、A**n = A**k 的图,所有n>k 和矩阵D_ij = A**k 称为“距离矩阵”条目,表示图中所有节点之间的距离。
我在教堂里写了一个热带积函数,我想写一个函数,它接受一个邻接矩阵并返回结果距离矩阵。我尝试了以下方法无济于事。非常感谢您提供克服这些错误的指导!
proc tropicLimit(A:[] real,B:[] real) {
var R = tropic(A,B);
if A == R {
return A;
} else {
tropicLimit(R,B);
}
}
这引发了域不匹配错误,因此我进行了以下编辑:
proc tropicLimit(A:[] real,B:[] real) {
var R = tropic(A,B);
if A.domain == R.domain {
if && reduce (A == R) {
return R;
} else {
tropicLimit(R,B);
}
} else {
tropicLimit(R,B);
}
}
抛出
src/MatrixOps.chpl:602: error: control reaches end of function that returns a value
proc tropicLimit(A:[] real,B:[] real) {
var R = tropic(A,B);
if A.domain == R.domain {
if && reduce (A == R) { // Line 605 is this one
} else {
tropicLimit(R,B);
}
} else {
tropicLimit(R,B);
}
return R;
}
让我回到这个错误
src/MatrixOps.chpl:605: error: halt reached - Sparse arrays can't be zippered with anything other than their domains and sibling arrays (CS layout)
我也尝试使用带有break 条件的for 循环,但这也不起作用
proc tropicLimit(B:[] real) {
var R = tropic(B,B);
for n in B.domain.dim(2) {
var S = tropic(R,B);
if S.domain != R.domain {
R = S; // Intended to just reassign the handle "R" to the contents of "S" i.o.w. destructive update of R
} else {
break;
}
}
return R;
}
有什么建议吗?
【问题讨论】:
标签: graph sparse-matrix hpc convergence chapel