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.User.AumentedMatrix.AugOperator import AugOperator
00022 from slimpy_base.Core.User.linop.LinearOperatorType import LinearOperatorType
00023 from itertools import izip
00024 from numpy import diag
00025
00026
00027
00028
00029
00030
00031 @LinearOperatorType
00032 def Diag( A, length=0 ):
00033 """
00034 D = Diag( A [, length] )
00035 create a diagonal operator from A if length is non zero a must be a list,
00036 and will return a len(A) x len(A) matrix otherwize will return a length x
00037 length size operator with copies of A along the diagonal.
00038 """
00039
00040 if length:
00041 A_list = [A]*length
00042 else:
00043 A_list = A
00044
00045 return diag( A_list ).view( AugOperator )
00046
00047
00048
00049 @LinearOperatorType
00050 def From_sapce( cls , inspace, *params, **kparams):
00051 """
00052 D = From_sapce( oper_class, meta_space, ... )
00053 create a diagonal Operator from meta (in/out) spaces
00054 """
00055
00056
00057
00058
00059
00060
00061
00062
00063 pkw_obj = inspace.__pk_expannder__( *params, **kparams )
00064 zipper = izip( inspace.ravel(), pkw_obj)
00065
00066 oper_list = [ cls( ispc, *p, **wk) for ispc,(p,wk) in zipper ]
00067
00068 OP = Diag( oper_list )
00069 OP.meta = inspace.meta
00070 return OP
00071