00001 """
00002 A set of geneal out of core functions
00003 to work on Vectors.
00004 """
00005
00006 __copyright__ = """
00007 Copyright 2008 Sean Ross-Ross
00008 """
00009 __license__ = """
00010 This file is part of SLIMpy .
00011
00012 SLIMpy is free software: you can redistribute it and/or modify
00013 it under the terms of the GNU Lesser General Public License as published by
00014 the Free Software Foundation, either version 3 of the License, or
00015 (at your option) any later version.
00016
00017 SLIMpy is distributed in the hope that it will be useful,
00018 but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00020 GNU Lesser General Public License for more details.
00021
00022 You should have received a copy of the GNU Lesser General Public License
00023 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00024 """
00025
00026
00027 from slimpy_base.Core.Interface.Structure import Structure
00028 from slimpy_base.Core.Interface.node import Source
00029
00030 from slimpy_base.api.functions import slimpy_function_register
00031 from numpy import array, any
00032 from math import floor
00033 from slimpy_base.Core.User.linop.linear_operator import Identity
00034 from slimpy_base.api.linearops.transforms import DiagonalWeight
00035
00036
00037
00038
00039
00040
00041
00042
00043 @slimpy_function_register
00044 def cmplx( real, imag ):
00045 """
00046 cmplx( real, imag ) -> complex vector
00047 create a complex vector from real and imaginary parts
00048 """
00049 struct = Structure( )
00050
00051 cmnd = "cmplx"
00052 return struct.generateNew( real, cmnd, Source, Source( imag.container ) )
00053
00054
00055
00056
00057
00058
00059
00060
00061 @slimpy_function_register
00062 def cat( catlist , axis ):
00063 """
00064 Concatenate datasets catlist in the axis dinention.
00065 cat( axis, catlist ) -> vector
00066 """
00067 struct = Structure( )
00068
00069 cat_array = array(catlist)
00070 if not cat_array.shape:
00071 return catlist
00072 elif cat_array.size == 1:
00073 return catlist.item()
00074 else:
00075 catlist = cat_array.ravel().tolist()
00076 cat1,catlist = catlist[0],catlist[1:]
00077 sourcelist = [ Source(catitem.container) for catitem in catlist ]
00078 cmnd = "cat"
00079 return struct.generateNew( cat1, cmnd, *sourcelist, **{'axis':axis} )
00080
00081
00082
00083
00084
00085
00086
00087
00088 @slimpy_function_register
00089 def clnorm( A ,mode="norm" , angconstr=[0,0] ):
00090 """
00091 clnorm( A ,mode="norm" , angconstr=[0,0] ) -> DiagonalWeight
00092 retruns a diagonal weight operator with domain and range in the vector space of
00093 the domain of A
00094 The weight coresponds to the norms of the coloums of A
00095 """
00096 struct = Structure( )
00097 cmnd = 'fdct2vects'
00098
00099 if A.isadj:
00100 cInSpace = A.range( )
00101 else:
00102 cInSpace = A.domain( )
00103
00104
00105 angconstr
00106 angperwed = 360./ A.kparams['nba']
00107
00108 wedgconstr=[0,0]
00109 for i in range(2):
00110 wedgconstr[i] = floor((90-angconstr[i])/angperwed)
00111
00112
00113 if mode == "zang" and not any(wedgconstr) :
00114 return Identity( A.range() )
00115
00116
00117 command = struct.generate_command( cmnd ,
00118 cInSpace=cInSpace,
00119 mode=mode,
00120 wedgconstr=wedgconstr,
00121 nbs= A.kparams['nbs'],
00122 nba= A.kparams['nba'],
00123 ac = A.kparams['ac'] )
00124
00125
00126 data_container = cInSpace.makeContaner( cmnd )
00127 converter = data_container.get_converter( command )
00128 commpack = converter.convert( None, command )
00129
00130 commpack.target = data_container
00131 commpack.source = None
00132
00133 struct.env['graphmgr'].graphAppend( commpack )
00134
00135 from slimpy_base.Core.User.Structures.serial_vector import Vector
00136 wvec = Vector(data_container)
00137 return DiagonalWeight(wvec.space, wvec)
00138
00139