0
OUT_DIR = '/media/sf_3dAnalysis/simMatrix/'  
SIM_FILE = 'similarity.npy'

data = np.lib.format.open_memmap(OUT_DIR+SIM_FILE, mode='w+', dtype='float32', shape=(len(filelist),len(filelist)))
del data

So I get the following error message when running this code... mmap.error: [Errno 22] Invalid argument. I really don't understand what I am doing wrong. I am running this in a Linux VM if that's relevant. Also, what's particularly curious is the matrix is created after the code runs, but it still crashes saying the argument is invalid which makes no sense as to why it would be creating the matrix when it says the argument is invalid.

Is there anything special I need to do to get memory mapping to work on a linux machine versus windows and mac? Because it is working fine on my mac and windows machine. I guess I should specify even more, is there some setting or something that needs to be set-up in a virtual machine to have memory mapping working? Because I tried it on a computer running Linux normally, and it worked.

4

2 回答 2

1

我无法使用上面给出的示例复制您的错误。

mmap.error: [Errno 22] Invalid argument是从低级调用 libcmmap例程的错误代码,请参阅http://www.gnu.org/software/libc/manual/html_node/Memory_002dmapped-I_002fO.html

mmap 返回新映射的地址,或 -1 表示错误。

可能的错误包括:

EINVAL 地址不可用,或者给出了不一致的标志。

我猜这是内存不足的情况,因为您试图分配一个太大的块,不适合 VM 虚拟内存空间。

于 2013-07-15T20:48:18.537 回答
1

所以我解决了我的问题。我在虚拟机上创建了矩阵的本地副本。然后我将该副本移至共享文件夹。这是说明这一点的代码。

#create local copy
data = np.memmap(SIM_FILE, dtype='float32', mode='w+', 
          shape=(len(filelist),len(filelist)))
#move local copy to shared folder
os.system('mv' + " ~/Desktop/" + SIM_FILE + " " + OUT_DIR ) 
于 2013-07-16T18:30:59.513 回答