00001 __copyright__ = """ 00002 Copyright 2008 Sean Ross-Ross 00003 """ 00004 __license__ = """ 00005 This file is part of SLIMpy . 00006 00007 SLIMpy is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License as published by 00009 the Free Software Foundation, either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 SLIMpy is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License 00018 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>. 00019 """ 00020 00021 from slimpy_base.utils.Interface import InterfaceType 00022 from inspect import isdatadescriptor 00023 from inspect import isroutine 00024 00025 00026 class LinearOperatorType( InterfaceType ): 00027 interface_methods = { 00028 'H': isdatadescriptor, 00029 'adj' : isroutine, 00030 '__mul__' : isroutine, 00031 "applyop": isroutine, 00032 "domain": isroutine, 00033 "range" : isroutine, 00034 } 00035 00036 LinearOperators = {} 00037 LinearOpFunctions = {} 00038 00039 def __new__( cls, *args ): 00040 if args: 00041 name = args[0] 00042 if isroutine(name): 00043 cls.LinearOpFunctions[name.__name__] = name 00044 return name 00045 00046 oper = InterfaceType.__new__(cls, *args) 00047 00048 00049 if args: 00050 cls.LinearOperators[name] = oper 00051 00052 return oper 00053 00054 @classmethod 00055 def print_opers( cls ): 00056 """ 00057 register.print_opers( ) --> None 00058 00059 print all of the linear operators. 00060 any subclass of the LinearOperator class 00061 is registered. 00062 """ 00063 00064 print "#"*30 00065 print "Linear Operators" 00066 print "#"*30 00067 00068 for name,doc in cls.list_opers(): 00069 print "%(name)s:" %vars() 00070 print "-"*len(name) 00071 print doc 00072 print 00073 00074 print "#"*30 00075 print "Linear Operator Functions" 00076 print "#"*30 00077 00078 for name,doc in cls.list_opers(False): 00079 print "%(name)s:" %vars() 00080 print "-"*len(name) 00081 print doc 00082 print 00083 00084 @classmethod 00085 def list_opers( cls, lt=True ): 00086 """ 00087 list all classes that are subclasses of the LinearOperator 00088 base class. 00089 """ 00090 if lt: 00091 lo = cls.LinearOperators 00092 else: 00093 lo = cls.LinearOpFunctions 00094 00095 keys = lo.keys() 00096 keys.sort() 00097 for name in keys: 00098 item = lo[name] 00099 if item.__doc__: 00100 fill = '\n'+ " "*7 00101 doc = item.__doc__.strip( '\n\t ' ) 00102 doc = [d.strip( '\t ' ) for d in doc.splitlines()] 00103 if len(doc) > 6: 00104 doc = doc[:3] + [" ..."] + doc[-3:] 00105 00106 else: 00107 doc = ["No documentation"] 00108 doc = " "*7 + fill.join( doc ) 00109 yield name,doc 00110 return 00111 00112 is_oper = lambda item: type( type( item ) ) == LinearOperatorType