# $Id: __init__.py,v 1.11 2001/08/26 12:40:43 hzhu Exp $
"""
MatPy : Matrix package for python, with visualization.
The default operators are matrixwise.
The tilde operators are elementwise.
To get started, type:
from MatPy.interact import *
"""
__all__ = ["Scalar", "Matrix", "Tensor", "gplot", "formats",
"efuncs", "mfuncs", "Stats", "DynSys"]
#------------------------------------------------------------------
# Special values
"""
According to discussions on comp.lang.python, there is no universal way to
treat NaN, but the following codes work on Windows (NT and 98), Solaris (2.7
with gcc) and Linux (RH6.1 with egcs).
Supposedly it should work on any machine using IEEE arithmetics.
An alternative that sometimes works is
NaN = math.exp(1000) / math.exp(1000)
It core dumps on Tru64 Unix on Compaq Alpha [Solution: When using DEC
(Compaq) compiler to build Python try using -ieee switch].
The OpenVMS port of python uses VAX-format math, which has less exponent
range than IEEE. Behavior on VAX discussed at
http://www.deja.com/[ST_rn=ps]/getdoc.xp?AN=640022415&fmt=text
On FreeBSD (v3.5-Stable) this core dumps as well, as does:
Nan = math.exp(1000)/math.exp(1000)
"""
Inf = inf = 1e300**2
NaN = nan = inf - inf
class Nothing:
def __getattr__(self, name): return nothing
def __setattr__(self, name, value): return nothing
def __call__(self, *args, **kwds): return nothing
def __str__(self): return ""
def __repr__(self): return "nothing"
def __coerce__(self, other): return None
nothing = Nothing()
#------------------------------------------------------------------
from MatPy import formats
"""I guess formats.repr? should not be imported into local scope (although
that would be quicker) because that would not allow dynamical changes of
formats in calling programs"""
class MatrixType:
"class MatrixType : base class for Matrix - only defines repr and str"
def __repr__(self):
if self.typecode == 'l': return formats.reprI(self.data)
elif self.typecode == 'd': return formats.reprF(self.data)
elif self.typecode == 'D': return formats.reprC(self.data)
else: raise TypeError, "typecode =" + self.typecode
def __str__(self):
if self.typecode == 'l': return formats.strI(self.data)
elif self.typecode == 'd': return formats.strF(self.data)
elif self.typecode == 'D': return formats.strC(self.data)
else: raise TypeError, "typecode =" + self.typecode
_int = type(1)
_long = type(1L)
_float = type(1.0)
_complex = type(1j)
class ScalarType:
"class ScalarType : base class for Scalar - only defines repr"
def __repr__(self):
if type(self.data) == _int: return formats.shortI(self.data)
if type(self.data) == _long: return formats.shortI(self.data)
if type(self.data) == _float: return formats.shortF(self.data)
if type(self.data) == _complex: return formats.shortC(self.data)
else: raise TypeError, "typecode =" + self.typecode
|