Ticket 1861

This pull request addresses ticket 1861

http://projects.scipy.org/scipy/ticket/1861

All tests pass and memory performance is orders of magnitude better.