1

我在 x32 win xp 上使用 python x32

有时程序在线失败

fp = np.memmap('C:/memmap_test', dtype='float32', mode='w+', shape=(rows,cols))

错误memmap.py

Traceback (most recent call last):
    fp = np.memmap('C:/memmap_test', dtype='float32', mode='w+', shape=(rows,cols))   File "C:\Python27\lib\site-packages\numpy\core\memmap.py", line 253, in __new__
    mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=start)
OverflowError: cannot fit 'long' into an index-sized integer

所以我假设数组的大小有限制,那么数组 maxN = rows*cols 的最大大小是多少?

1. python x32 win x64 和 2. python x64 win x64 也是相同的问题。

更新:

#create array
rows= 250000
cols= 1000
fA= np.memmap('A.npy', dtype='float32', mode='w+', shape=(rows,cols))
# fA1= np.memmap('A1.npy', dtype='float32', mode='w+', shape=(rows,cols)) # can't create another one big memmap
print fA.nbytes/1024/1024 # 953 mb

所以似乎还有另一个限制,不仅对于单个内存映射数组 <2Gb。

还输出@Paul 提供的测试

working with 30000000 elements
number bytes required 0.240000 GB
works
working with 300000000 elements
number bytes required 2.400000 GB
OverflowError("cannot fit 'long' into an index-sized integer",)
working with 3000000000 elements
number bytes required 24.000000 GB
IOError(28, 'No space left on device')
working with 30000000000 elements
number bytes required 240.000000 GB
IOError(28, 'No space left on device')
working with 300000000000 elements
number bytes required 2400.000000 GB
IOError(28, 'No space left on device')
working with 3000000000000 elements
number bytes required 24000.000000 GB
IOError(22, 'Invalid argument')
4

1 回答 1

2

以下是有关此主题的一些讨论:内存映射文件可以有多大?为什么 Python 的 mmap 不能处理大文件

对于以下测试,我使用以下代码:

baseNumber = 3000000L

for powers in arange(1,7):
  l1 = baseNumber*10**powers
  print('working with %d elements'%(l1))
  print('number bytes required %f GB'%(l1*8/1e9))
  try:
    fp = numpy.memmap('test.map',dtype='float64', mode='w+',shape=(1,l1))
    #works 
    print('works')
    del fp
  except Exception as e:
    print(repr(e))

python x32 on windows x32 32位windows,文件大小限制在2-3GB左右。因此,由于操作系统限制,任何大于此文件大小的窗口都无法创建。我无权访问 x32 位机器,但在文件大小限制达到后命令将失败

windows x64上的python x32

在这种情况下,由于 python 是 32 位,我们似乎无法达到 win64 允许的文件大小。

%run -i scratch.py

python x32 win x64
working with 30000000 elements
number bytes required 0.240000 GB
works
working with 300000000 elements
number bytes required 2.400000 GB
OverflowError("cannot fit 'long' into an index-sized integer",)
working with 3000000000 elements
number bytes required 24.000000 GB
OverflowError("cannot fit 'long' into an index-sized integer",)
working with 30000000000 elements
number bytes required 240.000000 GB
IOError(28, 'No space left on device')
working with 300000000000 elements
number bytes required 2400.000000 GB
IOError(28, 'No space left on device')
working with 3000000000000 elements
number bytes required 24000.000000 GB
IOError(22, 'Invalid argument')

windows x64上的python x64

在这种情况下,我们最初受到磁盘大小的限制,但是一旦我们的数组/字节大小足够大,就会出现一些溢出

%run -i scratch.py
working with 30000000 elements
number bytes required 0.240000 GB
works
working with 300000000 elements
number bytes required 2.400000 GB
works
working with 3000000000 elements
number bytes required 24.000000 GB
works
working with 30000000000 elements
number bytes required 240.000000 GB
IOError(28, 'No space left on device')
working with 300000000000 elements
number bytes required 2400.000000 GB
IOError(28, 'No space left on device')
working with 3000000000000 elements
number bytes required 24000.000000 GB
IOError(22, 'Invalid argument')

总结:您的阵列将失败的精确点将取决于 Windows x64 最初的磁盘大小

pythonx32 windows x64 最初我们有您看到的类型错误,然后是磁盘大小限制,但在某些时候会引发无效参数错误

pythonx64 windows x64 最初我们有磁盘大小限制,但在某些时候会引发其他错误。
有趣的是,这些错误似乎与 2 64 大小问题无关,因为 3000000000000*8 < 2 64 与这些错误在 win32 上表现出来的方式相同。

可能是如果磁盘足够大,那么我们将看不到无效参数错误,并且我们可以达到 2**64 限制,尽管我没有足够大的磁盘来测试这个:)

于 2013-10-23T12:30:17.397 回答