7

以下简单的四行代码在我的 Python 2.6.6 / NumPy 1.7.0 / MKL 10.3.6 设置中产生了内存泄漏:

import numpy as np

t = np.random.rand(10,10)
while True:
  t = t / np.trace(t)

每次操作,使用的内存都会增长 10x10 矩阵的大小。但是,当我使用 NumPy 1.4.1/ATLAS 设置时,没有这样的行为。

我读过 MKL 不一定会自动释放内存,所以我想这就是爆炸的原因。有没有一种简单的方法来修改 NumPy(在编译之前或之后),这样这个四行代码就可以正常工作了?

np.show_config() 的输出

numpy 1.7.0

lapack_opt_info:
    libraries = ['mkl_rt', 'pthread']
    library_dirs = ['$MKLPATH/lib/intel64']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['$MKLPATH/include']
blas_opt_info:
    libraries = ['mkl_rt', 'pthread']
    library_dirs = ['$MKLPATH/lib/intel64']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['$MKLPATH/include']
lapack_mkl_info:
    libraries = ['mkl_rt', 'pthread']
    library_dirs = ['$MKLPATH/lib/intel64']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['$MKLPATH/include']
blas_mkl_info:
    libraries = ['mkl_rt', 'pthread']
    library_dirs = ['$MKLPATH/lib/intel64']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['$MKLPATH/include']
mkl_info:
    libraries = ['mkl_rt', 'pthread']
    library_dirs = ['$MKLPATH/lib/intel64']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['$MKLPATH/include']
4

1 回答 1

8

这确实是一个 NumPy 的错误,它已经知道了几个月,并在这里讨论过;它将在 1.7.1 中修复。修复是item_selection.c 中的这个不错的单行。添加此行并重新编译后,一切正常。

于 2013-03-04T00:28:24.357 回答