Ejemplo n.º 1
0
    def test_SymmetrisedGradientOperator3b(self):
        ###########################################################################
        # 3D geometry no channels
        #ig3 = ImageGeometry(N, M, K)
        Grad3 = GradientOperator(self.ig3, correlation='Space')

        E3 = SymmetrisedGradientOperator(Grad3.range_geometry())
        numpy.random.seed(1)
        u3 = E3.domain_geometry().allocate('random')
        w3 = E3.range_geometry().allocate('random', symmetry=True)
        #
        lhs3 = E3.direct(u3).dot(w3)
        rhs3 = u3.dot(E3.adjoint(w3))
        # with numpy 1.11 and py 3.5 decimal = 3
        decimal = 4
        npv = version.parse(numpy.version.version)
        if npv.major == 1 and npv.minor == 11:
            print("########## SETTING decimal to 3 ###########")
            decimal = 3
        numpy.testing.assert_almost_equal(lhs3, rhs3, decimal=decimal)
        # self.assertAlmostEqual(lhs3, rhs3,  )
        print("*******", lhs3, rhs3, abs((rhs3 - lhs3) / rhs3), 1.5 * 10**(-4),
              abs((rhs3 - lhs3) / rhs3) < 1.5 * 10**(-4))
        self.assertTrue(
            LinearOperator.dot_test(E3,
                                    range_init=w3,
                                    domain_init=u3,
                                    decimal=decimal))
    def test_SymmetrisedGradientOperator2(self):
        ###########################################################################
        # 2D geometry with channels
        # ig2 = ImageGeometry(N, M, channels = C)
        Grad2 = GradientOperator(self.ig2, correlation='Space')

        E2 = SymmetrisedGradientOperator(Grad2.range_geometry())
        numpy.random.seed(1)
        u2 = E2.domain_geometry().allocate('random')
        w2 = E2.range_geometry().allocate('random', symmetry=True)
        #
        lhs2 = E2.direct(u2).dot(w2)
        rhs2 = u2.dot(E2.adjoint(w2))

        numpy.testing.assert_allclose(lhs2, rhs2, rtol=1e-3)
    def test_SymmetrisedGradientOperator1b(self):
        ###########################################################################
        ## Symmetrized GradientOperator Tests
        print("Test SymmetrisedGradientOperator")
        ###########################################################################
        # 2D geometry no channels
        # ig = ImageGeometry(N, M)
        Grad = GradientOperator(self.ig)

        E1 = SymmetrisedGradientOperator(Grad.range_geometry())
        numpy.random.seed(1)
        u1 = E1.domain_geometry().allocate('random')
        w1 = E1.range_geometry().allocate('random', symmetry=True)

        lhs = E1.direct(u1).dot(w1)
        rhs = u1.dot(E1.adjoint(w1))
        print("lhs {} rhs {}".format(lhs, rhs))
        # self.assertAlmostEqual(lhs, rhs)
        numpy.testing.assert_allclose(lhs, rhs, rtol=1e-3)
    def test_SymmetrisedGradientOperator3b(self):
        ###########################################################################
        # 3D geometry no channels
        #ig3 = ImageGeometry(N, M, K)
        Grad3 = GradientOperator(self.ig3, correlation='Space')

        E3 = SymmetrisedGradientOperator(Grad3.range_geometry())
        numpy.random.seed(1)
        u3 = E3.domain_geometry().allocate('random')
        w3 = E3.range_geometry().allocate('random', symmetry=True)
        #
        lhs3 = E3.direct(u3).dot(w3)
        rhs3 = u3.dot(E3.adjoint(w3))

        numpy.testing.assert_almost_equal(lhs3, rhs3, decimal=3)
        print("*******", lhs3, rhs3, abs((rhs3 - lhs3) / rhs3), 1.5 * 10**(-4),
              abs((rhs3 - lhs3) / rhs3) < 1.5 * 10**(-4))
        self.assertTrue(
            LinearOperator.dot_test(E3,
                                    range_init=w3,
                                    domain_init=u3,
                                    decimal=3))