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.AugmentedBase import AugmentBase
00022 from slimpy_base.User.AumentedMatrix.AugVector import AugVector
00023 from slimpy_base.Core.Interface.PSpace import PSpace
00024 from numpy import all, ndarray
00025 from slimpy_base.Core.Interface.Structure import Structure
00026
00027
00028
00029 class MetaSpace( AugmentBase ):
00030 """
00031 """
00032 _contained_type = PSpace
00033
00034
00035 def _get_meta(self):
00036 if not hasattr(self, '_meta_space' ):
00037 self._meta_space = None
00038 return self._meta_space
00039
00040 def _set_meta(self,val):
00041 self._meta_space = val
00042
00043 meta = property(_get_meta, _set_meta )
00044
00045 def has_key( self, k ):
00046 raise NotImplementedError
00047
00048 def __contains__( self, obj ):
00049 """
00050 Test if a vector is in this space
00051 """
00052 pkw_obj = self.__pk_expannder__( obj )
00053 boo_array = self.__attr_func__( "__contains__", pkw_obj )
00054 return all(boo_array)
00055
00056
00057 def getParameters( self ):
00058 """
00059 Get parameter instance contained within class
00060 """
00061 raise NotImplementedError
00062
00063 def makeContaner(self, command=None, tmp=None):
00064
00065 pkw_obj = self.__pk_expannder__( command=command,tmp=tmp )
00066 container_array = self.__attr_func__("makeContaner", pkw_obj)
00067 return container_array.view( ndarray )
00068
00069
00070 def testCommand( self, cmd_tag, *args, **kargs ):
00071 """
00072 returns the reulting space from applying the command
00073 but does not add the command to the graph
00074 """
00075
00076 """
00077 returns the reulting space from applying the command
00078 but does not add the command to the graph
00079 """
00080 new_space = Structure.testCommand( self, cmd_tag, *args, **kargs )
00081 assert new_space is not None
00082
00083 return new_space
00084
00085 def newSpace( self, *d, **keys ):
00086 """
00087 Returns a new space with changed keys
00088 """
00089 raise NotImplementedError
00090
00091
00092
00093
00094 def create( self, out=0, istmp=True ):
00095 """
00096 Create a vector within this vectorspace
00097 """
00098 pkw_obj = self.__pk_expannder__( out=out, istmp=istmp )
00099 container_array = self.__attr_func__("create", pkw_obj)
00100 augvec = container_array.view( AugVector )
00101 augvec.meta = self.meta
00102 return augvec
00103
00104 def noise( self ):
00105 """
00106 Create a vector within this vectorspace
00107 """
00108 pkw_obj = self.__pk_expannder__( )
00109 container_array = self.__attr_func__("noise", pkw_obj)
00110 augvec = container_array.view( AugVector )
00111 augvec.meta = self.meta
00112 return augvec
00113
00114
00115 def zeros( self ):
00116 """
00117 Create a vector of zeros within this vectorspace
00118 """
00119 return self.create()
00120
00121 def ones( self ):
00122 """
00123 Create a vector of ones within this vectorspace
00124 """
00125 return self.create( out=1 )
00126
00127 def isReal( self ):
00128 pkw_obj = self.__pk_expannder__( )
00129 bool_array = self.__attr_func__("isReal", pkw_obj)
00130
00131 return all(bool_array)
00132
00133
00134 def isComplex( self ):
00135 pkw_obj = self.__pk_expannder__( )
00136 bool_array = self.__attr_func__("isComplex", pkw_obj)
00137
00138 return all(bool_array)
00139
00140 def isInt( self ):
00141 pkw_obj = self.__pk_expannder__( )
00142 bool_array = self.__attr_func__("isInt", pkw_obj)
00143
00144 return all(bool_array)
00145
00146 def get_local_sizes( self ):
00147
00148 pkw_obj = self.__pk_expannder__( )
00149 size_array = self.__attr_func__("get_size", pkw_obj)
00150 size_array = size_array.view( ndarray ).astype( int )
00151
00152 return size_array
00153
00154 def get_size( self ):
00155 """
00156 retuns the total number of elements in the augmented vector
00157 """
00158 size = self.get_local_sizes( )
00159
00160 return size.sum()
00161
00162 def coalesce(self):
00163 slist = self.ravel().tolist()
00164 return PSpace.union( *slist )
00165
00166 def _get_plugin(self):
00167 return self[0].plugin
00168
00169 plugin = property( _get_plugin )
00170
00171 def copy(self):
00172 pkw_obj = self.__pk_expannder__( )
00173 copy_array = self.__attr_func__("copy", pkw_obj )
00174 if self.meta is not None:
00175 copy_array.meta = self.meta.copy()
00176
00177 return copy_array
00178
00179