Пример #1
0
 def get_subset(self, to_select):
     assert to_select.size > 0
     d = self.__dict__
     new_data = copy.deepcopy(self)
     for key, value in d.items():
         if array_functions.is_matrix(value) and value.shape[0] == self.n:
             setattr(new_data, key, value[to_select])
         elif hasattr(value, 'deepcopy'):
             setattr(new_data, key, value.deepcopy())
         else:
             setattr(new_data, key, value)
     return new_data
Пример #2
0
 def get_subset(self,to_select):
     assert to_select.size > 0
     d = self.__dict__
     new_data = copy.deepcopy(self)
     for key,value in d.items():
         if array_functions.is_matrix(value) and value.shape[0] == self.n:
             setattr(new_data,key,value[to_select])
         elif hasattr(value,'deepcopy'):
             setattr(new_data,key,value.deepcopy())
         else:
             setattr(new_data,key,value)
     return new_data
Пример #3
0
 def permute(self, permutation):
     d = self.__dict__
     for key, value in d.items():
         if array_functions.is_matrix(value) and value.shape[0] == self.n:
             if value.ndim == 1:
                 value = value[permutation]
             elif value.ndim == 2:
                 value = value[permutation, :]
             else:
                 assert False
             setattr(self, key, value)
         else:
             #print key
             pass
     pass
Пример #4
0
 def permute(self,permutation):
     d = self.__dict__
     for key,value in d.items():
         if array_functions.is_matrix(value) and value.shape[0] == self.n:
             if value.ndim == 1:
                 value = value[permutation]
             elif value.ndim == 2:
                 value = value[permutation,:]
             else:
                 assert False
             setattr(self,key,value)
         else:
             #print key
             pass
     pass
Пример #5
0
 def combine(self, o):
     d = self.__dict__
     n = self.n
     for key, v_self in d.items():
         v_o = getattr(o, key, None)
         if v_o is None:
             continue
         #What should we do when o.key is not None but self.key isn't?
         assert v_self is not None
         if array_functions.is_matrix(v_self) and v_self.shape[0] == n:
             if v_self.ndim == 1:
                 value = array_functions.append_rows(v_self, v_o)
             elif v_self.ndim == 2:
                 value = array_functions.append_rows(v_self, v_o)
                 if value.ndim == 1:
                     value = np.expand_dims(value, 1)
             else:
                 assert False
             setattr(self, key, value)
Пример #6
0
 def combine(self, o):
     d = self.__dict__
     n = self.n
     for key, v_self in d.items():
         v_o = getattr(o, key, None)
         if v_o is None:
             continue
         #What should we do when o.key is not None but self.key isn't?
         assert v_self is not None
         if array_functions.is_matrix(v_self) and v_self.shape[0] == n:
             if v_self.ndim == 1:
                 value = array_functions.append_rows(v_self, v_o)
             elif v_self.ndim == 2:
                 value = array_functions.append_rows(v_self, v_o)
                 if value.ndim == 1:
                     value = np.expand_dims(value, 1)
             else:
                 assert False
             setattr(self, key, value)