__init__.py :  » Math » Matrix-package-for-Python » MatPy-0.4.0 » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Math » Matrix package for Python 
Matrix package for Python » MatPy 0.4.0 » __init__.py
# $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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.