|
| 1 | +from pylops import Diagonal as pDiagonal |
| 2 | +from pylops_distributed import LinearOperator |
| 3 | + |
| 4 | + |
| 5 | +class Diagonal(LinearOperator): |
| 6 | + r"""Diagonal operator. |
| 7 | +
|
| 8 | + Applies element-wise multiplication of the input vector with the vector |
| 9 | + ``diag`` in forward and with its complex conjugate in adjoint mode. |
| 10 | +
|
| 11 | + This operator can also broadcast; in this case the input vector is |
| 12 | + reshaped into its dimensions ``dims`` and the element-wise multiplication |
| 13 | + with ``diag`` is perfomed on the direction ``dir``. Note that the |
| 14 | + vector ``diag`` will need to have size equal to ``dims[dir]``. |
| 15 | +
|
| 16 | + Parameters |
| 17 | + ---------- |
| 18 | + diag : :obj:`dask.array.ndarray` |
| 19 | + Vector to be used for element-wise multiplication. |
| 20 | + dims : :obj:`list`, optional |
| 21 | + Number of samples for each dimension |
| 22 | + (``None`` if only one dimension is available) |
| 23 | + dir : :obj:`int`, optional |
| 24 | + Direction along which multiplication is applied. |
| 25 | + compute : :obj:`tuple`, optional |
| 26 | + Compute the outcome of forward and adjoint or simply define the graph |
| 27 | + and return a :obj:`dask.array.array` |
| 28 | + todask : :obj:`tuple`, optional |
| 29 | + Apply :func:`dask.array.from_array` to model and data before applying |
| 30 | + forward and adjoint respectively |
| 31 | + dtype : :obj:`str`, optional |
| 32 | + Type of elements in input array. |
| 33 | +
|
| 34 | + Attributes |
| 35 | + ---------- |
| 36 | + shape : :obj:`tuple` |
| 37 | + Operator shape |
| 38 | + explicit : :obj:`bool` |
| 39 | + Operator contains a matrix that can be solved explicitly (``True``) or |
| 40 | + not (``False``) |
| 41 | +
|
| 42 | + Notes |
| 43 | + ----- |
| 44 | + Refer to :class:`pylops.basicoperators.Diagonal` for implementation |
| 45 | + details. |
| 46 | +
|
| 47 | + """ |
| 48 | + def __init__(self, diag, dims=None, dir=0, |
| 49 | + compute=(False, False), todask=(False, False), |
| 50 | + dtype='float64'): |
| 51 | + Op = pDiagonal(diag, dims=dims, dir=dir, dtype=dtype) |
| 52 | + super().__init__(Op.shape, Op.dtype, Op, explicit=False, |
| 53 | + compute=compute, todask=todask) |
0 commit comments