64位体系结构中的32位OS:计算差异?

时间:2018-07-26 15:58:19

标签: python raspberry-pi 32bit-64bit

我目前正在使用python 3,特别是我正在尝试使用librosa模块在Raspberry pi 3模型B(带有自定义linux发行版32位)中计算mel过滤的频谱图。用于计算的代码,数据和参数与我在PC上使用的代码,数据和参数完全相同(Ubuntu 14.04 64位)。乍一看,我坚信这是运行在开发板上的librosa模块的一个错误,因此开始检查这些功能是否提供与PC相同的结果。为此,我调试了“ melspectogram”功能(Librosa的一部分)的代码。代码如下:

def melspectrogram(y=None, sr=22050, S=None, n_fft=2048, hop_length=512,
                   power=2.0, **kwargs):

    S, n_fft = _spectrogram(y=y, S=S, n_fft=n_fft, hop_length=hop_length,
                            power=power)

    # Build a Mel filter
    mel_basis = filters.mel(sr, n_fft, **kwargs)

    return np.dot(mel_basis, S)

函数“ _spectrogram”和“ filters.mel()”在Raspberry中给出正确的结果。问题似乎出在numpy点积中,它为某些索引返回了完全错误的结果。这是PC和开发板之间所有差异的调试视图。

###### DEBUG START-END: 206-223
                           PC                    BOARD
DIFFERENCE: (48, 11) 0.2191838420044883 != 0.21918384200448832
DIFFERENCE: (48, 15) 19.153408522395306 != 19.15340852239531
DIFFERENCE: (48, 17) 5.670882080544281 != 5.670882080544282
DIFFERENCE: (48, 24) 10.492875862139803 != 10.492875862139805
DIFFERENCE: (48, 25) 12.302969461756339 != 12.30296946175634
DIFFERENCE: (48, 26) 27.631040740403733 != 27.63104074040373
DIFFERENCE: (48, 29) 5.139375749153835 != 5.139375749153836
DIFFERENCE: (48, 34) 7.724733224346115 != 7.7247332243461155
DIFFERENCE: (48, 40) 0.09762231547647067 != 0.09762231547647066
DIFFERENCE: (49, 4) 0.011647182215426476 != 0.023294364430852952
DIFFERENCE: (49, 5) 0.011647182215426476 != 0.023294364430852952
DIFFERENCE: (49, 6) 0.011647182215426476 != 0.023294364430852952
DIFFERENCE: (49, 7) 0.011647182215426476 != 0.023294364430852952
DIFFERENCE: (49, 8) 0.011647182215426476 != 0.023294364430852952
DIFFERENCE: (49, 9) 0.024662982979241885 != 0.03631016519466836
DIFFERENCE: (49, 10) 0.011647182215426476 != 1736.0081098705543
DIFFERENCE: (49, 11) 0.011647182215426476 != 192.99921646614675
DIFFERENCE: (49, 12) 1.2357100597784794 != 1835.7802873745509
DIFFERENCE: (50, 4) 0.01162755916968538 != 0.02325511833937076
DIFFERENCE: (50, 5) 0.01162755916968538 != 0.02325511833937076
DIFFERENCE: (50, 6) 0.01162755916968538 != 0.02325511833937076
DIFFERENCE: (50, 7) 0.01162755916968538 != 0.02325511833937076
DIFFERENCE: (50, 8) 0.01162755916968538 != 0.02325511833937076
DIFFERENCE: (50, 9) 0.05210700691405087 != 333.83850661974526
DIFFERENCE: (50, 10) 0.021008006026422096 != 3965.2472056464244
DIFFERENCE: (50, 11) 0.10780954139916578 != 1530.5278140594276
DIFFERENCE: (50, 12) 0.41251995176336065 != 606.056179725736
DIFFERENCE: (51, 4) 0.011622992280708504 != 0.023245984561417007
DIFFERENCE: (51, 5) 0.011622992280708504 != 0.023245984561417007
DIFFERENCE: (51, 6) 0.011622992280708504 != 69.0566858320545
DIFFERENCE: (51, 7) 0.011622992280708504 != 825.1101267685075
DIFFERENCE: (51, 8) 0.011622992280708504 != 83.02070759794061
DIFFERENCE: (51, 9) 0.011622992280708504 != 931.8205273506092
DIFFERENCE: (51, 10) 0.4501778264666223 != 623.5746140044275
DIFFERENCE: (51, 11) 0.042509683378604 != 1987.8635720924942
DIFFERENCE: (51, 12) 1.884975416295644 != 450.9067305393012
DIFFERENCE: (52, 4) 0.01157539610226416 != 0.02315079220452832
DIFFERENCE: (52, 5) 0.01157539610226416 != 0.02315079220452832
DIFFERENCE: (52, 6) 0.01157539610226416 != 15.369480003003801
DIFFERENCE: (52, 7) 0.01157539610226416 != 183.44230139508068
DIFFERENCE: (52, 8) 0.01157539610226416 != 22.103013355309322
DIFFERENCE: (52, 9) 0.01157539610226416 != 16.947300443667636
DIFFERENCE: (52, 10) 0.7210348336411665 != 0.7326102297434307
DIFFERENCE: (52, 11) 0.07624676888597205 != 38.69928692732359
DIFFERENCE: (52, 12) 1.227613362577455 != 146.59676772956414
DIFFERENCE: (59, 4) 0.011639905409540543 != 0.023279810819081086
DIFFERENCE: (59, 5) 0.011639905409540543 != 0.023279810819081086
DIFFERENCE: (59, 6) 0.011639905409540543 != 0.023279810819081086
DIFFERENCE: (59, 7) 0.011639905409540543 != 0.023279810819081086
DIFFERENCE: (59, 8) 0.011639905409540543 != 0.023279810819081086
DIFFERENCE: (59, 9) 0.015804205007430926 != 0.02744411041697147
DIFFERENCE: (59, 10) 0.011639905409540543 != 4.896282342021101
DIFFERENCE: (59, 11) 0.024309464524604488 != 3.1951156889432926
DIFFERENCE: (59, 12) 0.014833562550355634 != 6.938331348819726

用于操作的矩阵为60x129和129x49。然后,我只提取了矩阵的一部分(特别是S的第8列以及mel_basis的第48和49行),这些是结果:

DIFFERENCE: (0, 0) 0.011617925176483229 != 0.011617925176483227
DIFFERENCE: (1, 0) 0.011647182215426474 != 0.011647182215426476

然后再次尝试使用mel_basis行49和50,相同的s:

DIFFERENCE: (0, 0) 0.011647182215426474 != 0.011647182215426476
DIFFERENCE: (1, 0) 0.011627559169685383 != 0.01162755916968538

通常,如果我们进行较少的计算,则误差似乎较小。

最后,仅检查一下,我采用了Raspberry计算的结构S和mel_basis,并在PC中计算了点积。结果是正确的。它使我认为这与硬件有关,也许与浮点有关,即使这很奇怪,因为ARM Cortex A53完全符合IEEE 754标准。 32位操作系统可以发挥作用吗?

1 个答案:

答案 0 :(得分:0)

有很多可能的问题:

在PC上,这取决于程序使用哪种浮点硬件。本机x87使用内部80位扩展浮点数,并且如果在每次操作后都未转换并存储结果,则会导致某些差异。

Python解释器可以使用float数学的不同实现。如果使用相同的编译器但使用不同的编译选项来编译相同的Python解释器,则结果甚至可能稍有不同。