1classdef nfftTestcaseCheckDelegate
2  %UNTITLED3 Summary of this class goes here
3  %   Detailed explanation goes here
4
5  properties
6    name = '';
7  end
8
9  methods
10    function h = nfftTestcaseCheckDelegate(name)
11      h.name = name;
12    end
13
14    function plan = prepare(h, plan, f, f_hat)
15      switch h.name
16        case 'trafo'
17          if isnumeric(plan)
18            nfft_set_f_hat(plan, f_hat);
19          else
20            if plan.d > 1
21              N = plan.N(:)';
22              f_hat = reshape(f_hat, N(end:-1:1));
23              f_hat = permute(f_hat, plan.d:-1:1);
24              f_hat = f_hat(:);
25            end
26            plan.fhat = f_hat;
27          end
28        case 'adjoint'
29          if isnumeric(plan)
30            nfft_set_f(plan, f);
31          else
32            plan.f = f;
33          end
34        otherwise
35          error('Unknown check: %s', h.name);
36      end
37    end
38
39    function result = compare(h, plan, f, f_hat)
40      if isnumeric(plan)
41        plan_f = nfft_get_f(plan);
42        plan_f_hat = nfft_get_f_hat(plan);
43      else
44        plan_f = plan.f;
45        plan_f_hat = plan.fhat;
46       	if plan.d > 1
47          N = plan.N(:)';
48          plan_f_hat = reshape(plan_f_hat, N);
49          plan_f_hat = permute(plan_f_hat, plan.d:-1:1);
50          plan_f_hat = plan_f_hat(:);
51	      end
52      end
53      switch h.name
54        case 'trafo'
55          numerator = max(abs(f - plan_f));
56          denominator = sum(abs(plan_f_hat));
57        case 'adjoint'
58          numerator = max(abs(f_hat - plan_f_hat));
59          denominator = sum(abs(plan_f));
60        otherwise
61          error('Unknown check: %s', h.name);
62      end
63
64      if numerator == 0
65        result = 0;
66      else
67        result = numerator / denominator;
68      end
69    end
70
71  end
72
73end
74
75