以下简单的四行代码在我的 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']