“新耶鲁”的细节稀疏矩阵格式?
有一些用 Fortran 编写的 Netlib 代码,可对稀疏矩阵执行转置和乘法。该库支持 Bank-Smith(某种程度上)、“旧耶鲁”和“新耶鲁”格式。
不幸的是,我无法找到有关“新耶鲁”的更多细节。我实现了我认为与论文中给出的描述相匹配的内容,我可以适当地获取和设置条目。
但结果不正确,让我想知道我是否实现了与论文中的描述相匹配但不是 Fortran 代码所期望的东西。
所以有几个问题:
行长度应该包括对角线条目吗?例如,如果您有M=[1,1;0,1]
,它似乎应该看起来像这样:
IJA = [3,4,4,1]
A = [1,1,X,1] // where X=NULL
似乎如果对角线条目包含在行长度中,您会得到类似这样的结果:
IJA = [3,5,6,1]
A = [1,1,X,1]
这没有多大意义,因为 IJA[2]=6
应该是IJA/A 阵列,但它就是论文所说的内容。
矩阵应该使用从 1 开始的索引吗?
毕竟是 Fortran 代码。也许我的 IJA 和 A 应该看起来像这样:
IJA = [4,5,5,2]
A = [1,1,X,1] // still X=NULL
我还缺少什么吗?
是的,这很模糊,但我把它扔在那里,以防以前弄乱过这段代码的人想要自愿提供任何其他信息。其他人可以随意忽略最后一个问题。
我知道这些问题可能看起来相当微不足道,但我想也许一些 Fortran 人员可以为我提供一些见解。我不习惯在基于 1 的系统中思考,尽管我已经使用 f2c
将代码转换为 C,但它仍然像 Fortran 那样编写。
There's some Netlib code written in Fortran which performs transposes and multiplication on sparse matrices. The library works with Bank-Smith (sort of), "old Yale", and "new Yale" formats.
Unfortunately, I haven't been able to find much detail on "new Yale." I implemented what I think matches the description given in the paper, and I can get and set entries appropriately.
But the results are not correct, leading me to wonder if I've implemented something which matches the description in the paper but is not what the Fortran code expects.
So a couple of questions:
Should row lengths include diagonal entries? e.g., if you have M=[1,1;0,1]
, it seems that it should look like this:
IJA = [3,4,4,1]
A = [1,1,X,1] // where X=NULL
It seems that if diagonal entries are included in row lengths, you'd get something like this:
IJA = [3,5,6,1]
A = [1,1,X,1]
That doesn't make much sense because IJA[2]=6
should be the size of the IJA/A arrays, but it is what the paper seems to say.
Should the matrices use 1-based indexing?
It is Fortran code after all. Perhaps instead my IJA and A should look like this:
IJA = [4,5,5,2]
A = [1,1,X,1] // still X=NULL
Is there anything else I'm missing?
Yes, that's vague, but I throw that out there in case someone who has messed with this code before would like to volunteer any additional information. Anyone else can feel free to ignore this last question.
I know these questions may seem rather trivial, but I thought perhaps some Fortran folks could provide me with some insight. I'm not used to thinking in a one-based system, and though I've converted the code to C using f2c
, it's still written like Fortran.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不明白你是如何从那篇论文中推导出这些向量的。首先是旧耶鲁格式:
然后,
A
以行形式包含 M 的所有非零值:A = [7,16,-12]
,
IA
存储每行第一个元素在A
中的位置,JA
存储A
中所有值的列索引:新格式:
A
首先具有对角线值,然后是零,然后是剩余的非零元素(我已将|
澄清对角线和非对角线之间的分离):IA
和JA
合并在IJA
中,但据我从论文中可以看出,您需要考虑 A 的新排序(我已放置|
来澄清IA
和JA
之间的分离):因此,应用于您的情况
M = [1, 1;0,1]
,我得到第一行的第一个元素是
A
中的第一个元素,第二行的第一个元素是A
中的第二个元素,然后我输入3
因为他们说的长度一行由IA(I)-IA(I+1)
确定,因此我确保差值是1
。接下来是非零非对角元素的列索引,即2
。I can't see how you deduced those vectors from that paper. First the Old Yale format:
Then,
A
contains all non-zero values of M in row-form:A = [7,16,-12]
and
IA
stores the position inA
of the first elements of each row, andJA
stores the column indices of all the values inA
:New format:
A
has diagonal values first, a zero and then the remaining non-zero elements (I have put|
to clarify the seperation between diagonal and non-diagonal) :IA
andJA
are combined inIJA
, but as far as I can tell from the paper you need to take into account the new ordering of A (I have put|
to clarify the seperation betweenIA
andJA
):So, applied to your case
M = [1,1;0,1]
, I getfirst element of the first row is the first in
A
and the first element of the second row is the second inA
, then I put3
since they say the length of a row is determined byIA(I)-IA(I+1)
, so I make sure the difference is1
. Then the column indices of the non-zero non-diagonal elements follow, and that is2
.因此,首先,SMMP 论文中给出的参考文献可能不是正确的一个。我查看了(裁判)昨晚从图书馆来的。它似乎给出了“旧耶鲁”格式。它在第 49-50 页确实提到,对角线可以与矩阵的其余部分分开——但没有提到 IJA 向量。
我能够找到 1992 年版的 C 中的数字食谱,第 78-79 页。
当然,不能保证这是 Netlib 的 SMMP 库接受的格式。
NR 似乎 IA 给出的位置是相对于 IJA 的,而不是相对于 JA 的。 IA 部分的最后一个位置给出的不是 IJA 和 A 向量的大小,而是 size-1,因为向量的索引从 1 开始(根据 Fortran 标准)。
行长度不包括非零对角线条目。
So, first of all, the reference given in the SMMP paper is possibly not the correct one. I checked it out (the ref) from the library last night. It appears to give the "old Yale" format. It does mention, on pp. 49-50, that the diagonal can be separated out from the rest of the matrix -- but doesn't so much as mention an IJA vector.
I was able to find the format described in the 1992 edition of Numerical Recipes in C on pp. 78-79.
Of course, there is no guarantee that this is the format accepted by the SMMP library from Netlib.
NR seems to have IA giving positions relative to IJA, not relative to JA. The last position in the IA portion gives not the size of the IJA and A vectors, but
size-1
, because the vectors are indexed starting at 1 (per Fortran standard).Row lengths do not include non-zero diagonal entries.