def test_PowerMethod(self): print ("test_BlockOperator") N, M = 200, 300 niter = 10 ig = ImageGeometry(N, M) Id = Identity(ig) G = Gradient(ig) uid = Id.domain_geometry().allocate(ImageGeometry.RANDOM_INT, seed=1) a = LinearOperator.PowerMethod(Id, niter, uid) #b = LinearOperator.PowerMethodNonsquare(Id, niter, uid) b = LinearOperator.PowerMethod(Id, niter) print ("Edo impl", a[0]) print ("None impl", b[0]) #self.assertAlmostEqual(a[0], b[0]) self.assertNumpyArrayAlmostEqual(a[0],b[0],decimal=6) a = LinearOperator.PowerMethod(G, niter, uid) b = LinearOperator.PowerMethod(G, niter) #b = LinearOperator.PowerMethodNonsquare(G, niter, uid) print ("Edo impl", a[0]) #print ("old impl", b[0]) self.assertNumpyArrayAlmostEqual(a[0],b[0],decimal=2)
def test_FiniteDifference(self): print ("test FiniteDifference") ## N, M = 2, 3 ig = ImageGeometry(N, M) Id = Identity(ig) FD = FiniteDiff(ig, direction = 0, bnd_cond = 'Neumann') u = FD.domain_geometry().allocate('random_int') res = FD.domain_geometry().allocate(ImageGeometry.RANDOM_INT) FD.adjoint(u, out=res) w = FD.adjoint(u) self.assertNumpyArrayEqual(res.as_array(), w.as_array()) res = Id.domain_geometry().allocate(ImageGeometry.RANDOM_INT) Id.adjoint(u, out=res) w = Id.adjoint(u) self.assertNumpyArrayEqual(res.as_array(), w.as_array()) self.assertNumpyArrayEqual(u.as_array(), w.as_array()) G = Gradient(ig) u = G.range_geometry().allocate(ImageGeometry.RANDOM_INT) res = G.domain_geometry().allocate() G.adjoint(u, out=res) w = G.adjoint(u) self.assertNumpyArrayEqual(res.as_array(), w.as_array()) u = G.domain_geometry().allocate(ImageGeometry.RANDOM_INT) res = G.range_geometry().allocate() G.direct(u, out=res) w = G.direct(u) self.assertBlockDataContainerEqual(res, w)