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])
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])
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])
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])
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])
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, )
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)
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)
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)
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)
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, )
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))