Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 013aae0d authored by hhakim's avatar hhakim
Browse files

Add general indexing support to pyfaust LazyLinearOp2

parent 7ba6a066
Branches
Tags
No related merge requests found
...@@ -995,15 +995,15 @@ class LazyLinearOp2(LinearOperator): ...@@ -995,15 +995,15 @@ class LazyLinearOp2(LinearOperator):
# TODO: refactor with create_from_funcs (in ctor) # TODO: refactor with create_from_funcs (in ctor)
lambdas['T'] = lambda: lopT lambdas['T'] = lambda: lopT
lambdas['H'] = lambda: lopH lambdas['H'] = lambda: lopH
lambdas['slice'] = lambda indices: LazyLinearOp2._slice_lambda(lop, lambdas['slice'] = lambda indices: LazyLinearOp2._index_lambda(lop,
indices)() indices)()
lambdasT['T'] = lambda: lop lambdasT['T'] = lambda: lop
lambdasT['H'] = lambda: lopC lambdasT['H'] = lambda: lopC
lambdasT['slice'] = lambda indices: LazyLinearOp2._slice_lambda(lopT, lambdasT['slice'] = lambda indices: LazyLinearOp2._index_lambda(lopT,
indices)() indices)()
lambdasH['T'] = lambda: lopC lambdasH['T'] = lambda: lopC
lambdasH['H'] = lambda: lop lambdasH['H'] = lambda: lop
lambdasH['slice'] = lambda indices: LazyLinearOp2._slice_lambda(lopH, lambdasH['slice'] = lambda indices: LazyLinearOp2._index_lambda(lopH,
indices)() indices)()
return lop return lop
...@@ -1043,15 +1043,15 @@ class LazyLinearOp2(LinearOperator): ...@@ -1043,15 +1043,15 @@ class LazyLinearOp2(LinearOperator):
lambdas['T'] = lambda: lopT lambdas['T'] = lambda: lopT
lambdas['H'] = lambda: lopH lambdas['H'] = lambda: lopH
lambdas['slice'] = lambda indices: LazyLinearOp2._slice_lambda(lop, lambdas['slice'] = lambda indices: LazyLinearOp2._index_lambda(lop,
indices)() indices)()
lambdasT['T'] = lambda: lop lambdasT['T'] = lambda: lop
lambdasT['H'] = lambda: lopC lambdasT['H'] = lambda: lopC
lambdasT['slice'] = lambda indices: LazyLinearOp2._slice_lambda(lopT, lambdasT['slice'] = lambda indices: LazyLinearOp2._index_lambda(lopT,
indices)() indices)()
lambdasH['T'] = lambda: lopC lambdasH['T'] = lambda: lopC
lambdasH['H'] = lambda: lop lambdasH['H'] = lambda: lop
lambdasH['slice'] = lambda indices: LazyLinearOp2._slice_lambda(lopH, lambdasH['slice'] = lambda indices: LazyLinearOp2._index_lambda(lopH,
indices)() indices)()
return lop return lop
...@@ -1060,13 +1060,12 @@ class LazyLinearOp2(LinearOperator): ...@@ -1060,13 +1060,12 @@ class LazyLinearOp2(LinearOperator):
raise TypeError(attr+' is not supported by the root object of this' raise TypeError(attr+' is not supported by the root object of this'
' LazyLinearOp') ' LazyLinearOp')
def _slice_lambda(lop, indices): def _index_lambda(lop, indices):
#TODO: handle indices[0] or indices[1] == ':' ?
from scipy.sparse import eye as seye from scipy.sparse import eye as seye
s = lambda: \ s = lambda: \
LazyLinearOp2.create_from_op(seye(lop.shape[0], LazyLinearOp2.create_from_op(seye(lop.shape[0],
format='csr')[indices[0]]) \ format='csr')[indices[0]]) \
@ lop @ LazyLinearOp2.create_from_op(seye(lop.shape[1], format='csr')[:, indices[1]]) @ lop @ LazyLinearOp2.create_from_op(seye(lop.shape[1], format='csr')[:, indices[1]])
return s return s
@property @property
...@@ -1454,8 +1453,7 @@ class LazyLinearOp2(LinearOperator): ...@@ -1454,8 +1453,7 @@ class LazyLinearOp2(LinearOperator):
isinstance(indices[0], slice): isinstance(indices[0], slice):
return self._slice(indices) return self._slice(indices)
else: else:
raise Exception('Other __getitem__ call than slicing and item' return self._slice(indices)
' access is not yet supported')
def _newshape_getitem(self, indices): def _newshape_getitem(self, indices):
empty_lop_except = Exception("Cannot create an empty LazyLinearOp.") empty_lop_except = Exception("Cannot create an empty LazyLinearOp.")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment