Skip to content

Commit eae806f

Browse files
committed
minor: fixed some error messages
1 parent e27faa0 commit eae806f

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

pylops/avo/poststack.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,12 @@ def _PoststackLinearModelling(
9494
D = ncp.diag(0.5 * ncp.ones(nt0 - 1, dtype=dtype), k=1) - ncp.diag(
9595
0.5 * ncp.ones(nt0 - 1, dtype=dtype), -1
9696
)
97-
# D[0] = D[-1] = 0.
9897
D = inplace_set(ncp.array(0.0), D, 0)
9998
D = inplace_set(ncp.array(0.0), D, -1)
10099
else:
101100
D = ncp.diag(ncp.ones(nt0 - 1, dtype=dtype), k=1) - ncp.diag(
102101
ncp.ones(nt0, dtype=dtype), k=0
103102
)
104-
# D[-1] = 0.
105103
D = inplace_set(ncp.array(0.0), D, -1)
106104

107105
# Create wavelet operator

pylops/jaxoperator.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ def _rmatvecad(self, x: JaxType, y: JaxType) -> JaxType:
5050
Parameters
5151
----------
5252
x : :obj:`jaxlib.xla_extension.ArrayImpl`
53-
Input array
53+
Input array for forward
5454
y : :obj:`jaxlib.xla_extension.ArrayImpl`
55-
Output array (where to store the
56-
Vector-Jacobian product)
55+
Input array for adjoint
5756
5857
Returns
59-
----------
60-
y : :obj:`jaxlib.xla_extension.ArrayImpl`
58+
-------
59+
xadj : :obj:`jaxlib.xla_extension.ArrayImpl`
6160
Output array
6261
6362
"""
6463
_, f_vjp = jax.vjp(self._matvec, x)
65-
return jax.jit(f_vjp)(y)[0]
64+
xadj = jax.jit(f_vjp)(y)[0]
65+
return xadj
6666

6767
def rmatvecad(self, x: JaxType, y: JaxType) -> JaxType:
6868
"""Adjoint matrix-vector multiplication with AD
@@ -84,7 +84,9 @@ def rmatvecad(self, x: JaxType, y: JaxType) -> JaxType:
8484
M, N = self.shape
8585

8686
if x.shape != (M,) and x.shape != (M, 1):
87-
raise ValueError("dimension mismatch")
87+
raise ValueError(
88+
f"Dimension mismatch. Got {x.shape}, but expected {(M, 1)} or {(M,)}."
89+
)
8890

8991
y = self._rmatvecad(x, y)
9092

@@ -93,5 +95,8 @@ def rmatvecad(self, x: JaxType, y: JaxType) -> JaxType:
9395
elif x.ndim == 2:
9496
y = y.reshape(N, 1)
9597
else:
96-
raise ValueError("invalid shape returned by user-defined rmatvecad()")
98+
raise ValueError(
99+
f"Invalid shape returned by user-defined rmatvecad(). "
100+
f"Expected 2-d ndarray or matrix, not {x.ndim}-d ndarray"
101+
)
97102
return y

pylops/linearoperator.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,9 @@ def matvec(self, x: NDArray) -> NDArray:
508508
M, N = self.shape
509509

510510
if x.shape != (N,) and x.shape != (N, 1):
511-
raise ValueError("dimension mismatch")
511+
raise ValueError(
512+
f"Dimension mismatch. Got {x.shape}, but expected {(M, 1)} or {(M,)}."
513+
)
512514

513515
y = self._matvec(x)
514516

@@ -517,7 +519,7 @@ def matvec(self, x: NDArray) -> NDArray:
517519
elif x.ndim == 2:
518520
y = y.reshape(M, 1)
519521
else:
520-
raise ValueError("invalid shape returned by user-defined matvec()")
522+
raise ValueError("Invalid shape returned by user-defined matvec()")
521523
return y
522524

523525
@count(forward=False)
@@ -542,7 +544,9 @@ def rmatvec(self, x: NDArray) -> NDArray:
542544
M, N = self.shape
543545

544546
if x.shape != (M,) and x.shape != (M, 1):
545-
raise ValueError("dimension mismatch")
547+
raise ValueError(
548+
f"Dimension mismatch. Got {x.shape}, but expected {(M, 1)} or {(M,)}."
549+
)
546550

547551
y = self._rmatvec(x)
548552

@@ -551,7 +555,7 @@ def rmatvec(self, x: NDArray) -> NDArray:
551555
elif x.ndim == 2:
552556
y = y.reshape(N, 1)
553557
else:
554-
raise ValueError("invalid shape returned by user-defined rmatvec()")
558+
raise ValueError("Invalid shape returned by user-defined rmatvec()")
555559
return y
556560

557561
@count(forward=True, matmat=True)
@@ -574,9 +578,9 @@ def matmat(self, X: NDArray) -> NDArray:
574578
575579
"""
576580
if X.ndim != 2:
577-
raise ValueError("expected 2-d ndarray or matrix, " "not %d-d" % X.ndim)
581+
raise ValueError(f"Expected 2-d ndarray or matrix, not {X.ndim}-d ndarray")
578582
if X.shape[0] != self.shape[1]:
579-
raise ValueError("dimension mismatch: %r, %r" % (self.shape, X.shape))
583+
raise ValueError(f"Dimension mismatch: {self.shape}, {X.shape}")
580584
Y = self._matmat(X)
581585
return Y
582586

@@ -600,9 +604,9 @@ def rmatmat(self, X: NDArray) -> NDArray:
600604
601605
"""
602606
if X.ndim != 2:
603-
raise ValueError("expected 2-d ndarray or matrix, " "not %d-d" % X.ndim)
607+
raise ValueError(f"Expected 2-d ndarray or matrix, not {X.ndim}-d ndarray")
604608
if X.shape[0] != self.shape[0]:
605-
raise ValueError("dimension mismatch: %r, %r" % (self.shape, X.shape))
609+
raise ValueError(f"Dimension mismatch: {self.shape}, {X.shape}")
606610
Y = self._rmatmat(X)
607611
return Y
608612

0 commit comments

Comments
 (0)