提交 69567532 authored 作者: Ricardo Vieira's avatar Ricardo Vieira 提交者: Ricardo Vieira

len(TypedList) cannot be symbolic

上级 7ccde642
......@@ -12,12 +12,14 @@ from pytensor.typed_list.type import TypedListType
class _typed_list_py_operators:
def __len__(self):
raise TypeError(
"Cannot call len(TypedList). Use `.length()` method instead for the symbolic equivalent."
)
def __getitem__(self, index):
return getitem(self, index)
def __len__(self):
return length(self)
def append(self, toAppend):
return append(self, toAppend)
......@@ -36,10 +38,13 @@ class _typed_list_py_operators:
def count(self, elem):
return count(self, elem)
# name "index" is already used by an attribute
# name "index" is claimed as an attribute of PyTensor Variable(s)
def ind(self, elem):
return index_(self, elem)
def length(self):
return length(self)
ttype = property(lambda self: self.type.ttype)
dtype = property(lambda self: self.type.ttype.dtype)
ndim = property(lambda self: self.type.ttype.ndim + 1)
......
import re
import numpy as np
import pytest
import scipy
......@@ -551,8 +553,11 @@ class TestLength:
mySymbolicMatricesList = TypedListType(
TensorType(pytensor.config.floatX, shape=(None, None))
)()
z = mySymbolicMatricesList.__len__()
with pytest.raises(
TypeError, match=re.escape("Use `.length()` method instead")
):
len(mySymbolicMatricesList)
z = mySymbolicMatricesList.length()
f = pytensor.function([mySymbolicMatricesList], z)
x = rand_ranged_matrix(-1000, 1000, [100, 101])
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论