File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 1212
1313
1414class _typed_list_py_operators :
15+ def __len__ (self ):
16+ raise TypeError (
17+ "Cannot call len(TypedList). Use `.length()` method instead for the symbolic equivalent."
18+ )
19+
1520 def __getitem__ (self , index ):
1621 return getitem (self , index )
1722
18- def __len__ (self ):
19- return length (self )
20-
2123 def append (self , toAppend ):
2224 return append (self , toAppend )
2325
@@ -36,10 +38,13 @@ def reverse(self):
3638 def count (self , elem ):
3739 return count (self , elem )
3840
39- # name "index" is already used by an attribute
41+ # name "index" is claimed as an attribute of PyTensor Variable(s)
4042 def ind (self , elem ):
4143 return index_ (self , elem )
4244
45+ def length (self ):
46+ return length (self )
47+
4348 ttype = property (lambda self : self .type .ttype )
4449 dtype = property (lambda self : self .type .ttype .dtype )
4550 ndim = property (lambda self : self .type .ttype .ndim + 1 )
Original file line number Diff line number Diff line change 1+ import re
2+
13import numpy as np
24import pytest
35import scipy
@@ -551,8 +553,11 @@ def test_interface(self):
551553 mySymbolicMatricesList = TypedListType (
552554 TensorType (pytensor .config .floatX , shape = (None , None ))
553555 )()
554- z = mySymbolicMatricesList .__len__ ()
555-
556+ with pytest .raises (
557+ TypeError , match = re .escape ("Use `.length()` method instead" )
558+ ):
559+ len (mySymbolicMatricesList )
560+ z = mySymbolicMatricesList .length ()
556561 f = pytensor .function ([mySymbolicMatricesList ], z )
557562
558563 x = rand_ranged_matrix (- 1000 , 1000 , [100 , 101 ])
You can’t perform that action at this time.
0 commit comments