SciPy offers a large zoo of algorithms which exploit the possibility to pass a so called LinearOperator, which only provides methods for forward and backward transforms together with some simple properties like a datatype and shape parameters. This is exactly what we can provide for a specific instance of a fastmat Matrix. To this end, each fastmat Matrix has the (read only) property scipyLinearOperator, which provides a SciPy Linear operator realizing the transform specified by the fastmat object.
This allows to combine fastmat and SciPy in the most efficient manner possible. Here, fastmat provides the simple and efficient description of a huge variety of linear operators, which can then be used neatly and trouble free in SciPy.
Examples
Solve a system of linear equations with preconditioning, where the preconditioner can also be provided as a LinearOperator. See the attached file for a comparison. The file also outlines how crappy our own conjugate gradient method actually is.
Take Home Message
We should now mainly stick to defining the transforms and use the new SciPy interface if we want to run these algorithms, since these are very nicely tested and very performant.
Motivation
SciPy offers a large zoo of algorithms which exploit the possibility to pass a so called LinearOperator, which only provides methods for forward and backward transforms together with some simple properties like a datatype and shape parameters. This is exactly what we can provide for a specific instance of a fastmat Matrix. To this end, each fastmat Matrix has the (read only) property scipyLinearOperator, which provides a SciPy Linear operator realizing the transform specified by the fastmat object.
This allows to combine fastmat and SciPy in the most efficient manner possible. Here, fastmat provides the simple and efficient description of a huge variety of linear operators, which can then be used neatly and trouble free in SciPy.
Examples
Solve a system of linear equations with preconditioning, where the preconditioner can also be provided as a LinearOperator. See the attached file for a comparison. The file also outlines how crappy our own conjugate gradient method actually is.
Take Home Message
We should now mainly stick to defining the transforms and use the new SciPy interface if we want to run these algorithms, since these are very nicely tested and very performant.