pylops
pylops copied to clipboard
Feature: Add ABC abstractmethod to LinearOperator
Motivation
Following the discussion in https://github.com/PyLops/pylops/pull/363 we should consider also doing the same for linear operator
Solution
Decorate _matvect and _rmatvect with @abstractmethod
Currently, adding @abstractmethod to these methods results in the following error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Input In [7], in <cell line: 1>()
----> 1 Dop.H
File /opt/anaconda3/envs/pylops/lib/python3.9/site-packages/scipy/sparse/linalg/_interface.py:484, in LinearOperator.adjoint(self)
470 def adjoint(self):
471 """Hermitian adjoint.
472
473 Returns the Hermitian adjoint of self, aka the Hermitian
(...)
482 Hermitian adjoint of self.
483 """
--> 484 return self._adjoint()
File ~/Desktop/KAUST/OpenSource/pylops/pylops/LinearOperator.py:345, in LinearOperator._adjoint(self)
344 def _adjoint(self):
--> 345 Op = aslinearoperator(super()._adjoint())
346 self._copy_attributes(Op, exclude=["dims", "dimsd", "name"])
347 Op.dims = self.dimsd
File ~/Desktop/KAUST/OpenSource/pylops/pylops/LinearOperator.py:1286, in aslinearoperator(Op)
1284 return Op
1285 else:
-> 1286 return LinearOperator(Op)
File /opt/anaconda3/envs/pylops/lib/python3.9/site-packages/scipy/sparse/linalg/_interface.py:147, in LinearOperator.__new__(cls, *args, **kwargs)
145 return super(LinearOperator, cls).__new__(_CustomLinearOperator)
146 else:
--> 147 obj = super(LinearOperator, cls).__new__(cls)
149 if (type(obj)._matvec == LinearOperator._matvec
150 and type(obj)._matmat == LinearOperator._matmat):
151 warnings.warn("LinearOperator subclass should implement"
152 " at least one of _matvec and _matmat.",
153 category=RuntimeWarning, stacklevel=2)
TypeError: Can't instantiate abstract class LinearOperator with abstract methods _matvec, _rmatvec
If this issue is still not solved, would like to work on it @mrava87
Sure, we haven’t looked into this yet. I’ll assign to you :)