@@ -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