sawcordwell / pymdptoolbox

Markov Decision Process (MDP) Toolbox for Python
BSD 3-Clause "New" or "Revised" License
518 stars 252 forks source link

Absolute difference is unnecessarily space-inefficient #21

Open bissias opened 6 years ago

bissias commented 6 years ago

https://github.com/sawcordwell/pymdptoolbox/blob/7c96789cc80e280437005c12065cf70266c11636/src/mdptoolbox/util.py#L159

Due to either a bug or feature in numpy (I'm running numpy 1.14.0 and python 3.5.2), the above line returns a matrix of differences instead of a vector. This results in a memory error for relatively small vectors (in my case matrix.shape = (97200, 97200) and I have 40GB RAM). I think the fix is easy, just force the second term to be a proper column vector:

(_np.abs(matrix.sum(axis=1) - _np.ones((matrix.shape[0],1))))
bissias commented 6 years ago

The same change should also be made to line 156.