summaryrefslogtreecommitdiffstats
path: root/tests/python
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <wjp@usecode.org>2019-03-29 21:21:29 +0100
committerWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2019-09-25 14:10:08 +0200
commit3cf63d335ebe392a8c77f0c90395c18150647aeb (patch)
tree60a96bfe45c62aa9e57c1c5751e72d3794934845 /tests/python
parent87715885f3b4a80693493e37aa8293899a6b987e (diff)
downloadastra-3cf63d335ebe392a8c77f0c90395c18150647aeb.tar.gz
astra-3cf63d335ebe392a8c77f0c90395c18150647aeb.tar.bz2
astra-3cf63d335ebe392a8c77f0c90395c18150647aeb.tar.xz
astra-3cf63d335ebe392a8c77f0c90395c18150647aeb.zip
Adjust adjoint to line integral scaling
Diffstat (limited to 'tests/python')
-rw-r--r--tests/python/test_line2d.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/python/test_line2d.py b/tests/python/test_line2d.py
index 4c3d174..8b6e200 100644
--- a/tests/python/test_line2d.py
+++ b/tests/python/test_line2d.py
@@ -586,10 +586,66 @@ class Test2DKernel(unittest.TestCase):
else:
raise RuntimeError("Unsupported projector")
+ def single_test_adjoint(self, type, proj_type):
+ shape = np.random.randint(*range2d, size=2)
+ if FLEXVOL:
+ if not NONSQUARE:
+ pixsize = np.array([0.5, 0.5]) + np.random.random()
+ else:
+ pixsize = 0.5 + np.random.random(size=2)
+ origin = 10 * np.random.random(size=2)
+ else:
+ pixsize = (1.,1.)
+ origin = (0.,0.)
+ vg = astra.create_vol_geom(shape[1], shape[0],
+ origin[0] - 0.5 * shape[0] * pixsize[0],
+ origin[0] + 0.5 * shape[0] * pixsize[0],
+ origin[1] - 0.5 * shape[1] * pixsize[1],
+ origin[1] + 0.5 * shape[1] * pixsize[1])
+
+ if type == 'parallel':
+ pg = gen_random_geometry_parallel()
+ projector_id = astra.create_projector(proj_type, pg, vg)
+ elif type == 'parallel_vec':
+ pg = gen_random_geometry_parallel_vec()
+ projector_id = astra.create_projector(proj_type, pg, vg)
+ elif type == 'fanflat':
+ pg = gen_random_geometry_fanflat()
+ projector_id = astra.create_projector(proj_type_to_fan(proj_type), pg, vg)
+ elif type == 'fanflat_vec':
+ pg = gen_random_geometry_fanflat_vec()
+ projector_id = astra.create_projector(proj_type_to_fan(proj_type), pg, vg)
+
+ for i in range(5):
+ X = np.random.random((shape[1], shape[0]))
+ Y = np.random.random(astra.geom_size(pg))
+
+ sinogram_id, fX = astra.create_sino(X, projector_id)
+ bp_id, fTY = astra.create_backprojection(Y, projector_id)
+
+ astra.data2d.delete(sinogram_id)
+ astra.data2d.delete(bp_id)
+
+ da = np.dot(fX.ravel(), Y.ravel())
+ db = np.dot(X.ravel(), fTY.ravel())
+ m = np.abs(da - db)
+ TOL = 1e-3 if 'cuda' not in proj_type else 1e-1
+ if m / da >= TOL:
+ print(vg)
+ print(pg)
+ print(m/da, da/db, da, db)
+ self.assertTrue(m / da < TOL)
+ astra.projector.delete(projector_id)
+
+
def multi_test(self, type, proj_type):
np.random.seed(seed)
for _ in range(nloops):
self.single_test(type, proj_type)
+ def multi_test_adjoint(self, type, proj_type):
+ np.random.seed(seed)
+ for _ in range(nloops):
+ self.single_test_adjoint(type, proj_type)
__combinations = { 'parallel': [ 'line', 'linear', 'distance_driven', 'strip', 'cuda' ],
'parallel_vec': [ 'line', 'linear', 'distance_driven', 'strip', 'cuda' ],
@@ -600,7 +656,10 @@ for k, l in __combinations.items():
for v in l:
def f(k,v):
return lambda self: self.multi_test(k, v)
+ def f_adj(k,v):
+ return lambda self: self.multi_test_adjoint(k, v)
setattr(Test2DKernel, 'test_' + k + '_' + v, f(k,v))
+ setattr(Test2DKernel, 'test_' + k + '_' + v + '_adjoint', f_adj(k,v))
if __name__ == '__main__':
unittest.main()