예제 #1
0
 def test_grad_nonnegative_axis_3d(self):
     data = self.rng.random((2, 3, 4)).astype(aesara.config.floatX)
     utt.verify_grad(lambda x: sort(x, 0), [data])
     data = self.rng.random((2, 3, 4)).astype(aesara.config.floatX)
     utt.verify_grad(lambda x: sort(x, 1), [data])
     data = self.rng.random((2, 3, 4)).astype(aesara.config.floatX)
     utt.verify_grad(lambda x: sort(x, 2), [data])
예제 #2
0
 def test_grad_negative_axis_3d(self):
     data = np.random.rand(2, 3, 4).astype(aesara.config.floatX)
     utt.verify_grad(lambda x: sort(x, -1), [data])
     data = np.random.rand(2, 3, 4).astype(aesara.config.floatX)
     utt.verify_grad(lambda x: sort(x, -2), [data])
     data = np.random.rand(2, 3, 4).astype(aesara.config.floatX)
     utt.verify_grad(lambda x: sort(x, -3), [data])
예제 #3
0
 def test_grad_negative_axis_4d(self):
     data = self.rng.random((2, 3, 4, 2)).astype(aesara.config.floatX)
     utt.verify_grad(lambda x: sort(x, -1), [data])
     data = self.rng.random((2, 3, 4, 2)).astype(aesara.config.floatX)
     utt.verify_grad(lambda x: sort(x, -2), [data])
     data = self.rng.random((2, 3, 4, 2)).astype(aesara.config.floatX)
     utt.verify_grad(lambda x: sort(x, -3), [data])
     data = self.rng.random((2, 3, 4, 2)).astype(aesara.config.floatX)
     utt.verify_grad(lambda x: sort(x, -4), [data])
예제 #4
0
    def test_grad_none_axis(self):
        data = self.rng.random((10)).astype(aesara.config.floatX)
        utt.verify_grad(lambda x: sort(x, None), [data])
        utt.verify_grad(lambda x: sort(x, 0), [data])

        data = self.rng.random((2, 3)).astype(aesara.config.floatX)
        utt.verify_grad(lambda x: sort(x, None), [data])
        data = self.rng.random((2, 3, 4)).astype(aesara.config.floatX)
        utt.verify_grad(lambda x: sort(x, None), [data])
예제 #5
0
 def test_grad_nonnegative_axis_4d(self):
     data = np.random.rand(2, 3, 4, 2).astype(aesara.config.floatX)
     utt.verify_grad(lambda x: sort(x, 0), [data])
     data = np.random.rand(2, 3, 4, 2).astype(aesara.config.floatX)
     utt.verify_grad(lambda x: sort(x, 1), [data])
     data = np.random.rand(2, 3, 4, 2).astype(aesara.config.floatX)
     utt.verify_grad(lambda x: sort(x, 2), [data])
     data = np.random.rand(2, 3, 4, 2).astype(aesara.config.floatX)
     utt.verify_grad(lambda x: sort(x, 3), [data])
예제 #6
0
 def test_sort(self):
     x = matrix()
     self._compile_and_check(
         [x],
         [sort(x)],
         [np.random.randn(10, 40).astype(aesara.config.floatX)],
         SortOp,
     )
     self._compile_and_check(
         [x],
         [sort(x, axis=None)],
         [np.random.randn(10, 40).astype(aesara.config.floatX)],
         SortOp,
     )
예제 #7
0
 def test_None(self):
     a = dmatrix()
     l = sort(a, None)
     f = aesara.function([a], l)
     gv = f(self.m_val)
     gt = np.sort(self.m_val, None)
     utt.assert_allclose(gv, gt)
예제 #8
0
 def test3(self):
     a = dvector()
     w2 = sort(a)
     f = aesara.function([a], w2)
     gv = f(self.v_val)
     gt = np.sort(self.v_val)
     utt.assert_allclose(gv, gt)
예제 #9
0
 def test4(self):
     a = dmatrix()
     axis = scalar()
     l = sort(a, axis, "mergesort")
     f = aesara.function([a, axis], l)
     for axis_val in 0, 1:
         gv = f(self.m_val, axis_val)
         gt = np.sort(self.m_val, axis_val)
         utt.assert_allclose(gv, gt)
예제 #10
0
 def test2(self):
     a = dmatrix()
     axis = scalar()
     w = sort(a, axis)
     f = aesara.function([a, axis], w)
     for axis_val in 0, 1:
         gv = f(self.m_val, axis_val)
         gt = np.sort(self.m_val, axis_val)
         utt.assert_allclose(gv, gt)
예제 #11
0
 def test_sort(self):
     x = matrix()
     self._compile_and_check(
         [x],
         [sort(x)],
         [
             self.rng.standard_normal(size=(10, 40)).astype(
                 aesara.config.floatX)
         ],
         SortOp,
     )
     self._compile_and_check(
         [x],
         [sort(x, axis=None)],
         [
             self.rng.standard_normal(size=(10, 40)).astype(
                 aesara.config.floatX)
         ],
         SortOp,
     )
예제 #12
0
 def test1(self):
     a = dmatrix()
     w = sort(a)
     f = aesara.function([a], w)
     utt.assert_allclose(f(self.m_val), np.sort(self.m_val))