Simple Matrix class

Paul McGuire ptmcg at austin.rr.com
Tue Jan 23 19:03:44 EST 2007


On Jan 23, 4:05 pm, Casey Hawthorne <caseyhHAMMER_T... at istar.ca>
wrote:
> Do you calcalate the matrix inversion, when you don't need to?
>

No, the inversion is only calculated on the first call to inverse(),
and memoized so that subsequent calls return the cached value
immediately.  Since the Matrix class is mutable, the cache is
invalidated if any of the matrix elements are updated.  So after
changing a matrix element, the inversion would be recalculated at the
next call to inverse().

Hope that clears things up.  You can also do your own experiments,
including adding verbose logging to the memoizing decorators - an
example is included in the source code.  Also the footprint is quite
small, just one Python source file, about 600-700 lines of code, and
all Python, so 100% portable.

-- Paul




More information about the Python-list mailing list