/src/fftw3/rdft/dht-r2hc.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2003, 2007-14 Matteo Frigo |
3 | | * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology |
4 | | * |
5 | | * This program is free software; you can redistribute it and/or modify |
6 | | * it under the terms of the GNU General Public License as published by |
7 | | * the Free Software Foundation; either version 2 of the License, or |
8 | | * (at your option) any later version. |
9 | | * |
10 | | * This program is distributed in the hope that it will be useful, |
11 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | * GNU General Public License for more details. |
14 | | * |
15 | | * You should have received a copy of the GNU General Public License |
16 | | * along with this program; if not, write to the Free Software |
17 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
18 | | * |
19 | | */ |
20 | | |
21 | | |
22 | | /* Solve a DHT problem (Discrete Hartley Transform) via post-processing |
23 | | of an R2HC problem. */ |
24 | | |
25 | | #include "rdft/rdft.h" |
26 | | |
27 | | typedef struct { |
28 | | solver super; |
29 | | } S; |
30 | | |
31 | | typedef struct { |
32 | | plan_rdft super; |
33 | | plan *cld; |
34 | | INT os; |
35 | | INT n; |
36 | | } P; |
37 | | |
38 | | static void apply(const plan *ego_, R *I, R *O) |
39 | 0 | { |
40 | 0 | const P *ego = (const P *) ego_; |
41 | 0 | INT os = ego->os; |
42 | 0 | INT i, n = ego->n; |
43 | |
|
44 | 0 | { |
45 | 0 | plan_rdft *cld = (plan_rdft *) ego->cld; |
46 | 0 | cld->apply((plan *) cld, I, O); |
47 | 0 | } |
48 | |
|
49 | 0 | for (i = 1; i < n - i; ++i) { |
50 | 0 | E a, b; |
51 | 0 | a = O[os * i]; |
52 | 0 | b = O[os * (n - i)]; |
53 | 0 | #if FFT_SIGN == -1 |
54 | 0 | O[os * i] = a - b; |
55 | 0 | O[os * (n - i)] = a + b; |
56 | | #else |
57 | | O[os * i] = a + b; |
58 | | O[os * (n - i)] = a - b; |
59 | | #endif |
60 | 0 | } |
61 | 0 | } |
62 | | |
63 | | static void awake(plan *ego_, enum wakefulness wakefulness) |
64 | 0 | { |
65 | 0 | P *ego = (P *) ego_; |
66 | 0 | X(plan_awake)(ego->cld, wakefulness); |
67 | 0 | } |
68 | | |
69 | | static void destroy(plan *ego_) |
70 | 0 | { |
71 | 0 | P *ego = (P *) ego_; |
72 | 0 | X(plan_destroy_internal)(ego->cld); |
73 | 0 | } |
74 | | |
75 | | static void print(const plan *ego_, printer *p) |
76 | 0 | { |
77 | 0 | const P *ego = (const P *) ego_; |
78 | 0 | p->print(p, "(dht-r2hc-%D%(%p%))", ego->n, ego->cld); |
79 | 0 | } |
80 | | |
81 | | static int applicable0(const problem *p_, const planner *plnr) |
82 | 0 | { |
83 | 0 | const problem_rdft *p = (const problem_rdft *) p_; |
84 | 0 | return (1 |
85 | 0 | && !NO_DHT_R2HCP(plnr) |
86 | 0 | && p->sz->rnk == 1 |
87 | 0 | && p->vecsz->rnk == 0 |
88 | 0 | && p->kind[0] == DHT |
89 | 0 | ); |
90 | 0 | } |
91 | | |
92 | | static int applicable(const solver *ego, const problem *p, const planner *plnr) |
93 | 341 | { |
94 | 341 | UNUSED(ego); |
95 | 341 | return (!NO_SLOWP(plnr) && applicable0(p, plnr)); |
96 | 341 | } |
97 | | |
98 | | static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr) |
99 | 341 | { |
100 | 341 | P *pln; |
101 | 341 | const problem_rdft *p; |
102 | 341 | plan *cld; |
103 | | |
104 | 341 | static const plan_adt padt = { |
105 | 341 | X(rdft_solve), awake, print, destroy |
106 | 341 | }; |
107 | | |
108 | 341 | if (!applicable(ego_, p_, plnr)) |
109 | 341 | return (plan *)0; |
110 | | |
111 | 0 | p = (const problem_rdft *) p_; |
112 | | |
113 | | /* NO_DHT_R2HC stops infinite loops with rdft-dht.c */ |
114 | 0 | cld = X(mkplan_f_d)(plnr, |
115 | 0 | X(mkproblem_rdft_1)(p->sz, p->vecsz, |
116 | 0 | p->I, p->O, R2HC), |
117 | 0 | NO_DHT_R2HC, 0, 0); |
118 | 0 | if (!cld) return (plan *)0; |
119 | | |
120 | 0 | pln = MKPLAN_RDFT(P, &padt, apply); |
121 | |
|
122 | 0 | pln->n = p->sz->dims[0].n; |
123 | 0 | pln->os = p->sz->dims[0].os; |
124 | 0 | pln->cld = cld; |
125 | | |
126 | 0 | pln->super.super.ops = cld->ops; |
127 | 0 | pln->super.super.ops.other += 4 * ((pln->n - 1)/2); |
128 | 0 | pln->super.super.ops.add += 2 * ((pln->n - 1)/2); |
129 | |
|
130 | 0 | return &(pln->super.super); |
131 | 0 | } |
132 | | |
133 | | /* constructor */ |
134 | | static solver *mksolver(void) |
135 | 1 | { |
136 | 1 | static const solver_adt sadt = { PROBLEM_RDFT, mkplan, 0 }; |
137 | 1 | S *slv = MKSOLVER(S, &sadt); |
138 | 1 | return &(slv->super); |
139 | 1 | } |
140 | | |
141 | | void X(dht_r2hc_register)(planner *p) |
142 | 1 | { |
143 | 1 | REGISTER_SOLVER(p, mksolver()); |
144 | 1 | } |