22
33from pylops_gpu import LinearOperator
44from pylops_gpu .signalprocessing import Convolve1D
5+ from pylops_gpu .utils .torch2numpy import torchtype_from_numpytype
56
67
78"""
@@ -39,7 +40,7 @@ class FirstDerivative(LinearOperator):
3940 tocpu : :obj:`tuple`, optional
4041 Move data and model from gpu to cpu after applying ``matvec`` and
4142 ``rmatvec``, respectively (only when ``device='gpu'``)
42- dtype : :obj:`torch.dtype`, optional
43+ dtype : :obj:`torch.dtype` or :obj:`np.dtype` , optional
4344 Type of elements in input array.
4445
4546 Attributes
@@ -63,6 +64,9 @@ class FirstDerivative(LinearOperator):
6364 def __init__ (self , N , dims = None , dir = 0 , sampling = 1. , device = 'cpu' ,
6465 togpu = (False , False ), tocpu = (False , False ),
6566 dtype = torch .float32 ):
67+ # convert dtype to torch.dtype
68+ dtype = torchtype_from_numpytype (dtype )
69+
6670 h = torch .torch .tensor ([0.5 , 0 , - 0.5 ],
6771 dtype = dtype ).to (device ) / sampling
6872 self .device = device
@@ -73,4 +77,4 @@ def __init__(self, N, dims=None, dir=0, sampling=1., device='cpu',
7377 self .explicit = False
7478 self .Op = Convolve1D (N , h , offset = 1 , dims = dims , dir = dir ,
7579 zero_edges = True , device = device ,
76- togpu = togpu , tocpu = tocpu , dtype = dtype )
80+ togpu = togpu , tocpu = tocpu , dtype = self . dtype )
0 commit comments