Skip to content

Commit 46073dd

Browse files
committed
fix the tests
1 parent 9fdbb1f commit 46073dd

File tree

2 files changed

+1
-110
lines changed

2 files changed

+1
-110
lines changed

tests/test_data.py

Lines changed: 1 addition & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
# limitations under the License.
1414

1515
import io
16-
import itertools as it
1716

1817
from os import path
1918

20-
import cloudpickle
2119
import numpy as np
2220
import pytensor
2321
import pytensor.tensor as pt
@@ -29,7 +27,7 @@
2927
import pymc as pm
3028

3129
from pymc.data import MinibatchOp
32-
from pymc.pytensorf import GeneratorOp, floatX
30+
from pymc.pytensorf import floatX
3331

3432

3533
class TestData:
@@ -495,83 +493,6 @@ def integers_ndim(ndim):
495493
i += 1
496494

497495

498-
@pytest.mark.usefixtures("strict_float32")
499-
class TestGenerator:
500-
def test_basic(self):
501-
generator = pm.GeneratorAdapter(integers())
502-
gop = GeneratorOp(generator)()
503-
assert gop.tag.test_value == np.float32(0)
504-
f = pytensor.function([], gop)
505-
assert f() == np.float32(0)
506-
assert f() == np.float32(1)
507-
for _ in range(2, 100):
508-
f()
509-
assert f() == np.float32(100)
510-
511-
def test_ndim(self):
512-
for ndim in range(10):
513-
res = list(it.islice(integers_ndim(ndim), 0, 2))
514-
generator = pm.GeneratorAdapter(integers_ndim(ndim))
515-
gop = GeneratorOp(generator)()
516-
f = pytensor.function([], gop)
517-
assert ndim == res[0].ndim
518-
np.testing.assert_equal(f(), res[0])
519-
np.testing.assert_equal(f(), res[1])
520-
521-
def test_cloning_available(self):
522-
gop = pm.generator(integers())
523-
res = gop**2
524-
shared = pytensor.shared(pm.floatX(10))
525-
res1 = pytensor.clone_replace(res, {gop: shared})
526-
f = pytensor.function([], res1)
527-
assert f() == np.float32(100)
528-
529-
def test_default_value(self):
530-
def gen():
531-
for i in range(2):
532-
yield pm.floatX(np.ones((10, 10)) * i)
533-
534-
gop = pm.generator(gen(), np.ones((10, 10)) * 10)
535-
f = pytensor.function([], gop)
536-
np.testing.assert_equal(np.ones((10, 10)) * 0, f())
537-
np.testing.assert_equal(np.ones((10, 10)) * 1, f())
538-
np.testing.assert_equal(np.ones((10, 10)) * 10, f())
539-
with pytest.raises(ValueError):
540-
gop.set_default(1)
541-
542-
def test_set_gen_and_exc(self):
543-
def gen():
544-
for i in range(2):
545-
yield pm.floatX(np.ones((10, 10)) * i)
546-
547-
gop = pm.generator(gen())
548-
f = pytensor.function([], gop)
549-
np.testing.assert_equal(np.ones((10, 10)) * 0, f())
550-
np.testing.assert_equal(np.ones((10, 10)) * 1, f())
551-
with pytest.raises(StopIteration):
552-
f()
553-
gop.set_gen(gen())
554-
np.testing.assert_equal(np.ones((10, 10)) * 0, f())
555-
np.testing.assert_equal(np.ones((10, 10)) * 1, f())
556-
557-
def test_pickling(self, datagen):
558-
gen = pm.generator(datagen)
559-
cloudpickle.loads(cloudpickle.dumps(gen))
560-
bad_gen = pm.generator(integers())
561-
with pytest.raises(TypeError):
562-
cloudpickle.dumps(bad_gen)
563-
564-
def test_gen_cloning_with_shape_change(self, datagen):
565-
gen = pm.generator(datagen)
566-
gen_r = pt.random.normal(size=gen.shape).T
567-
X = gen.dot(gen_r)
568-
res, _ = pytensor.scan(lambda x: x.sum(), X, n_steps=X.shape[0])
569-
assert res.eval().shape == (50,)
570-
shared = pytensor.shared(datagen.data.astype(gen.dtype))
571-
res2 = pytensor.clone_replace(res, {gen: shared**2})
572-
assert res2.eval().shape == (1000,)
573-
574-
575496
def gen1():
576497
i = 0
577498
while True:

tests/test_pytensorf.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from pytensor.graph.basic import Variable, equal_computations
2828
from pytensor.tensor.random.basic import normal, uniform
2929
from pytensor.tensor.subtensor import AdvancedIncSubtensor
30-
from pytensor.tensor.variable import TensorVariable
3130

3231
import pymc as pm
3332

@@ -37,19 +36,16 @@
3736
from pymc.exceptions import NotConstantValueError
3837
from pymc.logprob.utils import ParameterValueError
3938
from pymc.pytensorf import (
40-
GeneratorOp,
4139
collect_default_updates,
4240
compile,
4341
constant_fold,
4442
convert_data,
45-
convert_generator_data,
4643
extract_obs_data,
4744
hessian,
4845
hessian_diag,
4946
replace_rng_nodes,
5047
replace_vars_in_graphs,
5148
reseed_rngs,
52-
smarttypeX,
5349
walk_model,
5450
)
5551
from pymc.vartypes import int_types
@@ -265,32 +261,6 @@ def test_convert_data(input_dtype):
265261
assert pytensor_output.dtype == intX
266262

267263

268-
@pytest.mark.parametrize("input_dtype", ["int32", "int64", "float32", "float64"])
269-
def test_convert_generator_data(input_dtype):
270-
# Create a generator object producing NumPy arrays with the intended dtype.
271-
# This is required to infer the correct dtype.
272-
square_generator = (np.array([i**2], dtype=input_dtype) for i in range(100))
273-
274-
# Output is NOT wrapped with `pm.floatX`/`intX`,
275-
# but produced from calling a special Op.
276-
with pytest.warns(DeprecationWarning, match="get in touch"):
277-
result = convert_generator_data(square_generator)
278-
apply = result.owner
279-
op = apply.op
280-
# Make sure the returned object is a PyTensor TensorVariable
281-
assert isinstance(result, TensorVariable)
282-
assert isinstance(op, GeneratorOp), f"It's a {type(apply)}"
283-
# There are no inputs - because it generates...
284-
assert apply.inputs == []
285-
286-
# Evaluation results should have the correct* dtype!
287-
# (*intX/floatX will be enforced!)
288-
evaled = result.eval()
289-
expected_dtype = smarttypeX(np.array(1, dtype=input_dtype)).dtype
290-
assert result.type.dtype == expected_dtype
291-
assert evaled.dtype == np.dtype(expected_dtype)
292-
293-
294264
def test_pandas_to_array_pandas_index():
295265
data = pd.Index([1, 2, 3])
296266
result = convert_data(data)

0 commit comments

Comments
 (0)