forked from PyLops/pylops
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
284 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,8 @@ Basic operators | |
Real | ||
Imag | ||
Conj | ||
ToCupy | ||
|
||
|
||
Smoothing and derivatives | ||
~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
__all__ = ["ToCupy"] | ||
|
||
from typing import Union | ||
|
||
import numpy as np | ||
|
||
from pylops import LinearOperator | ||
from pylops.utils._internal import _value_or_sized_to_tuple | ||
from pylops.utils.backend import to_cupy, to_numpy | ||
from pylops.utils.typing import DTypeLike, InputDimsLike, NDArray | ||
|
||
|
||
class ToCupy(LinearOperator): | ||
r"""Convert to CuPy. | ||
Convert an input array to CuPy in forward mode, | ||
and convert back to NumPy in adjoint mode. | ||
Parameters | ||
---------- | ||
dims : :obj:`list` or :obj:`int` | ||
Number of samples for each dimension | ||
dtype : :obj:`str`, optional | ||
Type of elements in input array. | ||
name : :obj:`str`, optional | ||
Name of operator (to be used by :func:`pylops.utils.describe.describe`) | ||
Attributes | ||
---------- | ||
shape : :obj:`tuple` | ||
Operator shape | ||
explicit : :obj:`bool` | ||
Operator contains a matrix that can be solved explicitly | ||
(``True``) or not (``False``) | ||
Notes | ||
----- | ||
The ToCupy operator is a special operator that does not perform | ||
any transformation on the input arrays other than converting | ||
them from NumPy to CuPy. This operator can be used when one | ||
is interested to create a chain of operators where only one | ||
(or some of them) act on CuPy arrays, whilst other operate | ||
on NumPy arrays. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
dims: Union[int, InputDimsLike], | ||
dtype: DTypeLike = "float64", | ||
name: str = "C", | ||
) -> None: | ||
dims = _value_or_sized_to_tuple(dims) | ||
super().__init__(dtype=np.dtype(dtype), dims=dims, dimsd=dims, name=name) | ||
|
||
def _matvec(self, x: NDArray) -> NDArray: | ||
return to_cupy(x) | ||
|
||
def _rmatvec(self, x: NDArray) -> NDArray: | ||
return to_numpy(x) |
Oops, something went wrong.