@@ -768,17 +768,20 @@ def __init__(self, encoding, shape):
768
768
size = np .abs (size )
769
769
if self ._data .size % size != 0 :
770
770
raise ValueError (
771
- "cannot reshape encoding of size %d into shape %s"
772
- % (self ._data .size , str (self ._shape ))
771
+ "cannot reshape encoding of size %d into shape %s" ,
772
+ self ._data .size ,
773
+ str (self ._shape ),
773
774
)
775
+
774
776
rem = self ._data .size // size
775
777
self ._shape = tuple (rem if s == - 1 else s for s in self ._shape )
776
778
elif nn > 2 :
777
779
raise ValueError ("shape cannot have more than one -1 value" )
778
780
elif np .prod (self ._shape ) != self ._data .size :
779
781
raise ValueError (
780
- "cannot reshape encoding of size %d into shape %s"
781
- % (self ._data .size , str (self ._shape ))
782
+ "cannot reshape encoding of size %d into shape %s" ,
783
+ self ._data .size ,
784
+ str (self ._shape ),
782
785
)
783
786
784
787
def _from_base_indices (self , base_indices ):
@@ -818,9 +821,11 @@ def __init__(self, base_encoding, perm):
818
821
raise ValueError (f"base_encoding must be an Encoding, got { base_encoding !s} " )
819
822
if len (base_encoding .shape ) != len (perm ):
820
823
raise ValueError (
821
- "base_encoding has %d ndims - cannot transpose with perm %s"
822
- % (base_encoding .ndims , str (perm ))
824
+ "base_encoding has %d ndims - cannot transpose with perm %s" ,
825
+ base_encoding .ndims ,
826
+ str (perm ),
823
827
)
828
+
824
829
super ().__init__ (base_encoding )
825
830
perm = np .array (perm , dtype = np .int64 )
826
831
if not all (i in perm for i in range (base_encoding .ndims )):
@@ -898,7 +903,7 @@ def __init__(self, encoding, axes):
898
903
super ().__init__ (encoding )
899
904
if not all (0 <= a < self ._data .ndims for a in axes ):
900
905
raise ValueError (
901
- "Invalid axes %s for %d-d encoding" % ( str (axes ), self ._data .ndims )
906
+ "Invalid axes %s for %d-d encoding" , str (axes ), self ._data .ndims
902
907
)
903
908
904
909
def _to_base_indices (self , indices ):
0 commit comments