sparseMatrix.py :  » Development » PySparse » pysparse-1.1 » Lib » 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 » Development » PySparse 
PySparse » pysparse 1.1 » Lib » sparseMatrix.py
#!/usr/bin/env python

## -*-Pyth-*-
 # ###################################################################
 #  FiPy - Python-based finite volume PDE solver
 # 
 #  FILE: "sparseMatrix.py"
 #                                    created: 11/10/03 {3:15:38 PM} 
 #                                last update: 1/3/07 {3:03:32 PM} 
 #  Author: Jonathan Guyer <guyer@nist.gov>
 #  Author: Daniel Wheeler <daniel.wheeler@nist.gov>
 #  Author: James Warren   <jwarren@nist.gov>
 #  Author: Maxsim Gibiansky <maxsim.gibiansky@nist.gov>
 #    mail: NIST
 #     www: http://www.ctcms.nist.gov/fipy/
 #  
 # ========================================================================
 # This software was developed at the National Institute of Standards
 # and Technology by employees of the Federal Government in the course
 # of their official duties.  Pursuant to title 17 Section 105 of the
 # United States Code this software is not subject to copyright
 # protection and is in the public domain.  FiPy is an experimental
 # system.  NIST assumes no responsibility whatsoever for its use by
 # other parties, and makes no guarantees, expressed or implied, about
 # its quality, reliability, or any other characteristic.  We would
 # appreciate acknowledgement if the software is used.
 # 
 # This software can be redistributed and/or modified freely
 # provided that any derivative works bear some notice that they are
 # derived from it, and any modified versions bear some notice that
 # they have been modified.
 # ========================================================================
 #  
 #  Description: 
 # 
 #  History
 # 
 #  modified   by  rev reason
 #  ---------- --- --- -----------
 #  2003-11-10 JEG 1.0 original
 #  2006-06-12 MLG 1.0 made abstract
 # ###################################################################
 ##

__docformat__ = 'restructuredtext'

import numpy

class SparseMatrix:
    
    """
    .. attention:: This class is abstract. Always create one of its subclasses.
    """

    def __init__(self, size=None, bandwidth=0, matrix=None, sizeHint=None):
        pass

    __array_priority__ = 100.0    

    def getMatrix(self):
        pass

    def __array_wrap(self, arr, context=None):
        if context is None:
            return arr
        else: 
            return NotImplemented
    
    def copy(self):
        pass
        
    def __getitem__(self, index):
        pass
        
    def __str__(self):
        s = ""
        cellWidth = 11
        shape = self.getShape()
        for i in range(shape[0]):
            for j in range(shape[1]):
                v = self[i,j]
                if v == 0:
                    s += "---".center(cellWidth)
                else:
                    exp = numpy.log(abs(v))
                    if abs(exp) <= 4:
                        if exp < 0:
                            s += ("%9.6f" % v).ljust(cellWidth)
                        else:
                            s += ("%9.*f" % (6,v)).ljust(cellWidth)
                    else:
                        s += ("%9.2e" % v).ljust(cellWidth)
            s += "\n"
        return s[:-1]
            
    def __repr__(self):
        return repr(self.matrix)
        
    def __setitem__(self, index, value):
        pass
        
    def __add__(self, other):
        pass
        
    __radd__ = __add__

    def __iadd__(self, other):
        pass

    def __sub__(self, other):
        pass

    # Ask about this rsub
    def __rsub__(self, other):
        return -(__sub__(self, other))
        
        
    def __isub__(self, other):
        pass
        
    def __mul__(self, other):
        pass
            
    def __rmul__(self, other):
        pass
            
    def __neg__(self):
        return self * -1
        
    def __pos__(self):
        return self
        
##     def __eq__(self,other):
##   return self.matrix.__eq__(other._getMatrix())

    def getShape(self):
        pass
        
##     def transpose(self):
##         pass

    def put(self, vector, id1, id2):
        pass

    def putDiagonal(self, vector):
        pass

    def take(self, id1, id2):
        pass

    def takeDiagonal(self):
        pass

    def addAt(self, vector, id1, id2):
        pass

    def addAtDiagonal(self, vector):
        pass

    def getNumpyArray(self):
        pass

    def exportMmf(self, filename):
        pass
        
##     def __array__(self):
##      shape = self._getShape()
##      indices = numpy.indices(shape)
##         numMatrix = self.take(indices[0].ravel(), indices[1].ravel())
##      return numpy.reshape(numMatrix, shape)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.