|
23 | 23 | from pytensor.tensor import NoneConst
|
24 | 24 | from pytensor.tensor.basic import (
|
25 | 25 | Alloc,
|
26 |
| - AllocDiag, |
27 | 26 | AllocEmpty,
|
28 | 27 | ARange,
|
29 | 28 | Choose,
|
|
92 | 91 | from pytensor.tensor.exceptions import NotScalarConstantError
|
93 | 92 | from pytensor.tensor.math import dense_dot
|
94 | 93 | from pytensor.tensor.math import sum as at_sum
|
95 |
| -from pytensor.tensor.shape import Reshape, Shape, Shape_i, shape_padright, specify_shape |
| 94 | +from pytensor.tensor.shape import Reshape, Shape_i, shape_padright, specify_shape |
96 | 95 | from pytensor.tensor.type import (
|
97 | 96 | TensorType,
|
98 | 97 | bscalar,
|
@@ -3571,7 +3570,6 @@ def test_diag(self):
|
3571 | 3570 | # test vector input
|
3572 | 3571 | x = vector()
|
3573 | 3572 | g = diag(x)
|
3574 |
| - assert isinstance(g.owner.op, AllocDiag) |
3575 | 3573 | f = pytensor.function([x], g)
|
3576 | 3574 | for shp in [5, 0, 1]:
|
3577 | 3575 | m = rng.random(shp).astype(self.floatX)
|
@@ -3654,10 +3652,6 @@ def test_grad_3d(self, offset, axis1, axis2):
|
3654 | 3652 | class TestAllocDiag:
|
3655 | 3653 | # TODO: Separate perform, grad and infer_shape tests
|
3656 | 3654 |
|
3657 |
| - def setup_method(self): |
3658 |
| - self.alloc_diag = AllocDiag |
3659 |
| - self.mode = pytensor.compile.mode.get_default_mode() |
3660 |
| - |
3661 | 3655 | def _generator(self):
|
3662 | 3656 | dims = 4
|
3663 | 3657 | shape = (5,) * dims
|
@@ -3690,34 +3684,28 @@ def test_alloc_diag_values(self):
|
3690 | 3684 | # Test perform
|
3691 | 3685 | if np.maximum(axis1, axis2) > len(test_val.shape):
|
3692 | 3686 | continue
|
3693 |
| - adiag_op = self.alloc_diag(offset=offset, axis1=axis1, axis2=axis2) |
3694 |
| - f = pytensor.function([x], adiag_op(x)) |
3695 |
| - # AllocDiag and extract the diagonal again |
3696 |
| - # to check |
| 3687 | + diag_x = at.alloc_diag(x, offset=offset, axis1=axis1, axis2=axis2) |
| 3688 | + f = pytensor.function([x], diag_x) |
| 3689 | + # alloc_diag and extract the diagonal again to check for correctness |
3697 | 3690 | diag_arr = f(test_val)
|
3698 | 3691 | rediag = np.diagonal(diag_arr, offset=offset, axis1=axis1, axis2=axis2)
|
3699 | 3692 | assert np.all(rediag == test_val)
|
3700 | 3693 |
|
3701 | 3694 | # Test infer_shape
|
3702 |
| - f_shape = pytensor.function([x], adiag_op(x).shape, mode="FAST_RUN") |
| 3695 | + f_shape = pytensor.function([x], diag_x.shape, mode="FAST_RUN") |
3703 | 3696 |
|
3704 | 3697 | output_shape = f_shape(test_val)
|
3705 |
| - assert not any( |
3706 |
| - isinstance(node.op, self.alloc_diag) |
3707 |
| - for node in f_shape.maker.fgraph.toposort() |
3708 |
| - ) |
3709 | 3698 | rediag_shape = np.diagonal(
|
3710 | 3699 | np.ones(output_shape), offset=offset, axis1=axis1, axis2=axis2
|
3711 | 3700 | ).shape
|
3712 | 3701 | assert np.all(rediag_shape == test_val.shape)
|
3713 | 3702 |
|
3714 | 3703 | # Test grad
|
3715 |
| - diag_x = adiag_op(x) |
3716 | 3704 | sum_diag_x = at_sum(diag_x)
|
3717 | 3705 | grad_x = pytensor.grad(sum_diag_x, x)
|
3718 | 3706 | grad_diag_x = pytensor.grad(sum_diag_x, diag_x)
|
3719 |
| - f_grad_x = pytensor.function([x], grad_x, mode=self.mode) |
3720 |
| - f_grad_diag_x = pytensor.function([x], grad_diag_x, mode=self.mode) |
| 3707 | + f_grad_x = pytensor.function([x], grad_x) |
| 3708 | + f_grad_diag_x = pytensor.function([x], grad_diag_x) |
3721 | 3709 | grad_input = f_grad_x(test_val)
|
3722 | 3710 | grad_diag_input = f_grad_diag_x(test_val)
|
3723 | 3711 | true_grad_input = np.diagonal(
|
@@ -3894,20 +3882,6 @@ def test_ExtractDiag(self):
|
3894 | 3882 | atens3_diag = ExtractDiag(1, 2, 0)(atens3)
|
3895 | 3883 | self._compile_and_check([atens3], [atens3_diag], [atens3_val], ExtractDiag)
|
3896 | 3884 |
|
3897 |
| - def test_AllocDiag(self): |
3898 |
| - advec = dvector() |
3899 |
| - advec_val = random(4) |
3900 |
| - self._compile_and_check([advec], [AllocDiag()(advec)], [advec_val], AllocDiag) |
3901 |
| - |
3902 |
| - # Shape |
3903 |
| - # 'opt.Makevector' precludes optimizer from disentangling |
3904 |
| - # elements of shape |
3905 |
| - adtens = tensor3() |
3906 |
| - adtens_val = random(4, 5, 3) |
3907 |
| - self._compile_and_check( |
3908 |
| - [adtens], [Shape()(adtens)], [adtens_val], (MakeVector, Shape) |
3909 |
| - ) |
3910 |
| - |
3911 | 3885 | def test_Split(self):
|
3912 | 3886 | aiscal = iscalar()
|
3913 | 3887 | aivec = ivector()
|
|
0 commit comments