Skip to content

Commit

Permalink
Merge pull request #284 from cako/reduce-warnings
Browse files Browse the repository at this point in the history
Reduce warnings
  • Loading branch information
mrava87 authored Dec 31, 2021
2 parents 566456d + 8bdd3bb commit 1fc3a69
Show file tree
Hide file tree
Showing 23 changed files with 61 additions and 45 deletions.
4 changes: 2 additions & 2 deletions examples/plot_derivative.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@
# derivatives
nx, nz = 60, 40

horlayers = np.cumsum(np.random.uniform(2, 10, 20).astype(np.int))
horlayers = np.cumsum(np.random.uniform(2, 10, 20).astype(int))
horlayers = horlayers[horlayers < nz // 2]
nhorlayers = len(horlayers)

vertlayers = np.cumsum(np.random.uniform(2, 20, 10).astype(np.int))
vertlayers = np.cumsum(np.random.uniform(2, 20, 10).astype(int))
vertlayers = vertlayers[vertlayers < nx]
nvertlayers = len(vertlayers)

Expand Down
6 changes: 3 additions & 3 deletions examples/plot_tvreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
perc_subsampling = 0.6
nxsub = int(np.round(ny * nx * perc_subsampling))
iava = np.sort(np.random.permutation(np.arange(ny * nx))[:nxsub])
Rop = pylops.Restriction(ny * nx, iava, dtype=np.complex)
Rop = pylops.Restriction(ny * nx, iava, dtype=np.complex128)
Fop = pylops.signalprocessing.FFT2D(dims=(ny, nx))

n = np.random.normal(0, 0.0, (ny, nx))
Expand Down Expand Up @@ -148,10 +148,10 @@

Dop = [
pylops.FirstDerivative(
ny * nx, dims=(ny, nx), dir=0, edge=False, kind="backward", dtype=np.complex
ny * nx, dims=(ny, nx), dir=0, edge=False, kind="backward", dtype=np.complex128
),
pylops.FirstDerivative(
ny * nx, dims=(ny, nx), dir=1, edge=False, kind="backward", dtype=np.complex
ny * nx, dims=(ny, nx), dir=1, edge=False, kind="backward", dtype=np.complex128
),
]

Expand Down
4 changes: 2 additions & 2 deletions pylops/basicoperators/BlockDiag.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class BlockDiag(LinearOperator):

def __init__(self, ops, nproc=1, dtype=None):
self.ops = ops
mops = np.zeros(len(ops), dtype=np.int)
nops = np.zeros(len(ops), dtype=np.int)
mops = np.zeros(len(ops), dtype=int)
nops = np.zeros(len(ops), dtype=int)
for iop, oper in enumerate(ops):
if not isinstance(oper, (LinearOperator, spLinearOperator)):
self.ops[iop] = MatrixMult(oper, dtype=oper.dtype)
Expand Down
2 changes: 1 addition & 1 deletion pylops/basicoperators/HStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class HStack(LinearOperator):

def __init__(self, ops, nproc=1, dtype=None):
self.ops = ops
mops = np.zeros(len(ops), dtype=np.int)
mops = np.zeros(len(ops), dtype=int)
for iop, oper in enumerate(ops):
if not isinstance(oper, (LinearOperator, spLinearOperator)):
self.ops[iop] = MatrixMult(oper, dtype=oper.dtype)
Expand Down
2 changes: 1 addition & 1 deletion pylops/basicoperators/MatrixMult.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, A, dims=None, dtype="float64"):
if isinstance(dims, int):
dims = (dims,)
self.reshape = True
self.dims = np.array(dims, dtype=np.int)
self.dims = np.array(dims, dtype=int)
self.reshapedims = [
np.insert([np.prod(self.dims)], 0, self.A.shape[1]),
np.insert([np.prod(self.dims)], 0, self.A.shape[0]),
Expand Down
2 changes: 1 addition & 1 deletion pylops/basicoperators/Restriction.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def _compute_iavamask(dims, dir, iava, ncp):
"""Compute restriction mask when using cupy arrays"""
otherdims = np.array(dims)
otherdims = np.delete(otherdims, dir)
iavamask = ncp.zeros(dims[dir], dtype=np.int)
iavamask = ncp.zeros(dims[dir], dtype=int)
iavamask[iava] = 1
iavamask = ncp.moveaxis(
ncp.broadcast_to(iavamask, list(otherdims) + [dims[dir]]), -1, dir
Expand Down
4 changes: 2 additions & 2 deletions pylops/basicoperators/Spread.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def _matvec_numpy(self, x):
indices = self.fh(ix0, it)
mask = np.argwhere(~np.isnan(indices))
if mask.size > 0:
indices = (indices[mask]).astype(np.int)
indices = (indices[mask]).astype(int)
if not self.interp:
y[mask, indices] += x[ix0, it]
else:
Expand All @@ -210,7 +210,7 @@ def _rmatvec_numpy(self, x):
indices = self.fh(ix0, it)
mask = np.argwhere(~np.isnan(indices))
if mask.size > 0:
indices = (indices[mask]).astype(np.int)
indices = (indices[mask]).astype(int)
if not self.interp:
y[ix0, it] = np.sum(x[mask, indices])
else:
Expand Down
2 changes: 1 addition & 1 deletion pylops/basicoperators/Sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, dims, dir, dtype="float64"):
self.dims_d = list(dims).copy()
self.dims_d.pop(dir)
# array of ones with dims of model in dir for np.tile in adjoint mode
self.tile = np.ones(len(dims), dtype=np.int)
self.tile = np.ones(len(dims), dtype=int)
self.tile[dir] = self.dims[dir]
self.dtype = np.dtype(dtype)
self.shape = (np.prod(self.dims_d), np.prod(dims))
Expand Down
6 changes: 3 additions & 3 deletions pylops/basicoperators/Transpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def __init__(self, dims, axes, dtype="float64"):
raise ValueError("axes must contain each direction once")

# find out how axes should be transposed in adjoint mode
self.axesd = np.zeros(ndims, dtype=np.int)
self.dimsd = np.zeros(ndims, dtype=np.int)
self.axesd[self.axes] = np.arange(ndims, dtype=np.int)
self.axesd = np.zeros(ndims, dtype=int)
self.dimsd = np.zeros(ndims, dtype=int)
self.axesd[self.axes] = np.arange(ndims, dtype=int)
self.dimsd[self.axesd] = self.dims
self.axesd = list(self.axesd)

Expand Down
2 changes: 1 addition & 1 deletion pylops/basicoperators/VStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class VStack(LinearOperator):

def __init__(self, ops, nproc=1, dtype=None):
self.ops = ops
nops = np.zeros(len(self.ops), dtype=np.int)
nops = np.zeros(len(self.ops), dtype=int)
for iop, oper in enumerate(ops):
if not isinstance(oper, (LinearOperator, spLinearOperator)):
self.ops[iop] = MatrixMult(oper, dtype=oper.dtype)
Expand Down
18 changes: 12 additions & 6 deletions pylops/signalprocessing/Bilinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ def __init__(self, iava, dims, dtype="float64"):
self.dimsd = [len(iava[1])] + list(dims[2:])

# find indices and weights
self.iava_t = ncp.floor(iava[0]).astype(np.int)
self.iava_t = ncp.floor(iava[0]).astype(int)
self.iava_b = self.iava_t + 1
self.weights_tb = iava[0] - self.iava_t
self.iava_l = ncp.floor(iava[1]).astype(np.int)
self.iava_l = ncp.floor(iava[1]).astype(int)
self.iava_r = self.iava_l + 1
self.weights_lr = iava[1] - self.iava_l

Expand Down Expand Up @@ -123,14 +123,20 @@ def _rmatvec(self, x):
y = ncp.zeros(self.dims, dtype=self.dtype)
ncp_add_at(
y,
[self.iava_t, self.iava_l],
tuple([self.iava_t, self.iava_l]),
x * (1 - self.weights_tb) * (1 - self.weights_lr),
)
ncp_add_at(
y, [self.iava_t, self.iava_r], x * (1 - self.weights_tb) * self.weights_lr
y,
tuple([self.iava_t, self.iava_r]),
x * (1 - self.weights_tb) * self.weights_lr,
)
ncp_add_at(
y,
tuple([self.iava_b, self.iava_l]),
x * self.weights_tb * (1 - self.weights_lr),
)
ncp_add_at(
y, [self.iava_b, self.iava_l], x * self.weights_tb * (1 - self.weights_lr)
y, tuple([self.iava_b, self.iava_r]), x * self.weights_tb * self.weights_lr
)
ncp_add_at(y, [self.iava_b, self.iava_r], x * self.weights_tb * self.weights_lr)
return y.ravel()
6 changes: 3 additions & 3 deletions pylops/signalprocessing/ConvolveND.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def __init__(

# padding
if offset is None:
offset = np.zeros(self.h.ndim, dtype=np.int)
offset = np.zeros(self.h.ndim, dtype=int)
else:
offset = np.array(offset, dtype=np.int)
offset = np.array(offset, dtype=int)
self.offset = 2 * (self.nh // 2 - offset)
pad = [(0, 0) for _ in range(self.h.ndim)]
dopad = False
Expand All @@ -83,7 +83,7 @@ def __init__(

# find out which directions are used for convolution and define offsets
if len(dims) != len(self.nh):
dimsh = np.ones(len(dims), dtype=np.int)
dimsh = np.ones(len(dims), dtype=int)
for idir, dir in enumerate(self.dirs):
dimsh[dir] = self.nh[idir]
self.h = self.h.reshape(dimsh)
Expand Down
8 changes: 4 additions & 4 deletions pylops/signalprocessing/Interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _checkunique(iava):

def _nearestinterp(M, iava, dims=None, dir=0, dtype="float64"):
"""Nearest neighbour interpolation."""
iava = np.round(iava).astype(np.int)
iava = np.round(iava).astype(int)
_checkunique(iava)
return Restriction(M, iava, dims=dims, dir=dir, dtype=dtype), iava

Expand All @@ -27,7 +27,7 @@ def _linearinterp(M, iava, dims=None, dir=0, dtype="float64"):
ncp = get_array_module(iava)

if np.issubdtype(iava.dtype, np.integer):
iava = iava.astype(np.float)
iava = iava.astype(np.float64)
if dims is None:
lastsample = M
dimsd = None
Expand All @@ -49,7 +49,7 @@ def _linearinterp(M, iava, dims=None, dir=0, dtype="float64"):
_checkunique(iava)

# find indices and weights
iva_l = ncp.floor(iava).astype(np.int)
iva_l = ncp.floor(iava).astype(int)
iva_r = iva_l + 1
weights = iava - iva_l

Expand Down Expand Up @@ -84,7 +84,7 @@ def _sincinterp(M, iava, dims=None, dir=0, dtype="float64"):

# create Transpose operator that brings dir to first dimension
if dir > 0:
axes = np.arange(len(dims), dtype=np.int)
axes = np.arange(len(dims), dtype=int)
axes = np.roll(axes, -dir)
dimsd = list(dims)
dimsd[dir] = len(iava)
Expand Down
2 changes: 1 addition & 1 deletion pylops/signalprocessing/Radon2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _indices_2d(f, x, px, t, nt, interp=True):
xscan = (tdecscan >= 0) & (tdecscan < nt)
else:
xscan = (tdecscan >= 0) & (tdecscan < nt - 1)
tscan = tdecscan[xscan].astype(np.int)
tscan = tdecscan[xscan].astype(int)
if interp:
dtscan = tdecscan[xscan] - tscan
else:
Expand Down
2 changes: 1 addition & 1 deletion pylops/signalprocessing/Radon3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _indices_3d(f, y, x, py, px, t, nt, interp=True):
sscan = (tdecscan >= 0) & (tdecscan < nt)
else:
sscan = (tdecscan >= 0) & (tdecscan < nt - 1)
tscan = tdecscan[sscan].astype(np.int)
tscan = tdecscan[sscan].astype(int)
if interp:
dtscan = tdecscan[sscan] - tscan
else:
Expand Down
2 changes: 1 addition & 1 deletion pylops/signalprocessing/Sliding2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _slidingsteps(ntr, nwin, nover):
if nwin > ntr:
raise ValueError("nwin=%d is bigger than ntr=%d..." % (nwin, ntr))
step = nwin - nover
starts = np.arange(0, ntr - nwin + 1, step, dtype=np.int)
starts = np.arange(0, ntr - nwin + 1, step, dtype=int)
ends = starts + nwin
return starts, ends

Expand Down
4 changes: 2 additions & 2 deletions pylops/waveeqprocessing/marchenko.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def apply_onepoint(
"""
# Create window
trav_off = trav - self.toff
trav_off = np.round(trav_off / self.dt).astype(np.int)
trav_off = np.round(trav_off / self.dt).astype(int)

w = np.zeros((self.nr, self.nt), dtype=self.dtype)
for ir in range(self.nr):
Expand Down Expand Up @@ -561,7 +561,7 @@ def apply_multiplepoints(

# Create window
trav_off = trav - self.toff
trav_off = np.round(trav_off / self.dt).astype(np.int)
trav_off = np.round(trav_off / self.dt).astype(int)

w = np.zeros((self.nr, nvs, self.nt), dtype=self.dtype)
for ir in range(self.nr):
Expand Down
14 changes: 12 additions & 2 deletions pylops/waveeqprocessing/mdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,20 @@ def _MDC(
logging.warning("nfmax set equal to ceil[(nt+1)/2=%d]" % nfmax)

Fop = _FFT(
dims=(nt, nr, nv), dir=0, real=True, fftshift=twosided, dtype=rdtype, **args_FFT
dims=(nt, nr, nv),
dir=0,
real=True,
ifftshift_before=twosided,
dtype=rdtype,
**args_FFT
)
F1op = _FFT(
dims=(nt, ns, nv), dir=0, real=True, fftshift=False, dtype=rdtype, **args_FFT1
dims=(nt, ns, nv),
dir=0,
real=True,
ifftshift_before=False,
dtype=rdtype,
**args_FFT1
)

# create Identity operator to extract only relevant frequencies
Expand Down
4 changes: 2 additions & 2 deletions pytests/test_linearoperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_eigs(par):
def test_conj(par):
"""Complex conjugation operator"""
M = 1j * np.ones((par["ny"], par["nx"]))
Op = MatrixMult(M, dtype=np.complex)
Op = MatrixMult(M, dtype=np.complex128)
Opconj = Op.conj()

x = np.arange(par["nx"]) + par["imag"] * np.arange(par["nx"])
Expand Down Expand Up @@ -170,7 +170,7 @@ def test_realimag(par):
M = np.random.normal(0, 1, (par["ny"], par["nx"])) + 1j * np.random.normal(
0, 1, (par["ny"], par["nx"])
)
Op = MatrixMult(M, dtype=np.complex)
Op = MatrixMult(M, dtype=np.complex128)

Opr = Op.toreal()
Opi = Op.toimag()
Expand Down
6 changes: 3 additions & 3 deletions tutorials/ctscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ def radoncurve(x, r, theta):
# modelling operator both in a least-squares sense and using TV-reg.
Dop = [
pylops.FirstDerivative(
ny * nx, dims=(nx, ny), dir=0, edge=True, kind="backward", dtype=np.float
ny * nx, dims=(nx, ny), dir=0, edge=True, kind="backward", dtype=np.float64
),
pylops.FirstDerivative(
ny * nx, dims=(nx, ny), dir=1, edge=True, kind="backward", dtype=np.float
ny * nx, dims=(nx, ny), dir=1, edge=True, kind="backward", dtype=np.float64
),
]
D2op = pylops.Laplacian(dims=(nx, ny), edge=True, dtype=np.float)
D2op = pylops.Laplacian(dims=(nx, ny), edge=True, dtype=np.float64)

# L2
xinv_sm = pylops.optimization.leastsquares.RegularizedInversion(
Expand Down
2 changes: 1 addition & 1 deletion tutorials/deghosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
off = 0.035
direct_off = direct + off
win = np.zeros((nt, nr))
iwin = np.round(direct_off / dt).astype(np.int)
iwin = np.round(direct_off / dt).astype(int)
for i in range(nr):
win[iwin[i] :, i] = 1

Expand Down
2 changes: 1 addition & 1 deletion tutorials/realcomplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
Ar = np.random.normal(0, 1, (n, n))
Ai = np.random.normal(0, 1, (n, n))
A = Ar + 1j * Ai
Aop = pylops.MatrixMult(A, dtype=np.complex)
Aop = pylops.MatrixMult(A, dtype=np.complex128)
y = Aop @ x

###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion tutorials/wavefielddecomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
# obliquity factor
[Kx, F] = np.meshgrid(FFTop.f1, FFTop.f2, indexing="ij")
k = F / vel_sep
Kz = np.sqrt((k ** 2 - Kx ** 2).astype(np.complex))
Kz = np.sqrt((k ** 2 - Kx ** 2).astype(np.complex128))
Kz[np.isnan(Kz)] = 0
OBL = rho_sep * (np.abs(F) / Kz)
OBL[Kz == 0] = 0
Expand Down

0 comments on commit 1fc3a69

Please sign in to comment.