def _calc(self, data, ret_obj, **kwargs):
self._inst_als = _AlsCvxopt(**kwargs)
try:
# Get the subarray shape
shp = data.shape[0:-2]
total_num = _np.array(shp).prod()
# Iterate over the sub-array -- super slick way of doing it
for num, idx in enumerate(_np.ndindex(shp)):
print('Detrended iteration {} / {}'.format(num+1, total_num))
# Imaginary portion set
if self.use_imag and _np.iscomplexobj(data):
if self.rng is None:
ret_obj[idx] -= 1j*self._inst_als.calculate(data[idx].imag)
else:
ret_obj[idx][..., self.rng] -= 1j*self._inst_als.calculate(data[idx][..., self.rng].imag)
else: # Real portion set or real object
if self.rng is None:
ret_obj[idx] -= self._inst_als.calculate(data[idx].real)
else:
ret_obj[idx][..., self.rng] -= self._inst_als.calculate(data[idx][..., self.rng].real)
except:
return False
else:
# print(self._inst_als.__dict__)
return True
评论列表
文章目录