37
37
import nom .bdezonia .zorbage .algebra .Multiplication ;
38
38
import nom .bdezonia .zorbage .algebra .RealConstants ;
39
39
import nom .bdezonia .zorbage .algebra .SetComplex ;
40
- import nom .bdezonia .zorbage .algebra .StorageConstruction ;
41
40
import nom .bdezonia .zorbage .algebra .Trigonometric ;
42
41
import nom .bdezonia .zorbage .algebra .Unity ;
43
42
import nom .bdezonia .zorbage .data .DimensionedDataSource ;
44
43
import nom .bdezonia .zorbage .data .DimensionedStorage ;
44
+ import nom .bdezonia .zorbage .datasource .FFTDataSource ;
45
45
import nom .bdezonia .zorbage .datasource .IndexedDataSource ;
46
46
import nom .bdezonia .zorbage .datasource .SequencedDataSource ;
47
47
import nom .bdezonia .zorbage .dataview .PlaneView ;
@@ -60,6 +60,7 @@ public class FFT2D {
60
60
private FFT2D () { }
61
61
62
62
/**
63
+ * Do a 2-dimensional fourier transform of 1 plane of a complex DataSource
63
64
*
64
65
* @param <T>
65
66
* @param <U>
@@ -73,30 +74,25 @@ private FFT2D() { }
73
74
* @param otherPositions
74
75
* @return
75
76
*/
76
- @ SuppressWarnings ("unchecked" )
77
77
public static
78
78
<T extends Algebra <T ,U > & Addition <U > & Multiplication <U >,
79
- U extends SetComplex <W >,
79
+ U extends SetComplex <W > & Allocatable < U > ,
80
80
V extends Algebra <V ,W > & Trigonometric <W > & RealConstants <W > &
81
81
Multiplication <W > & Addition <W > & Invertible <W > & Unity <W >,
82
82
W >
83
- DimensionedDataSource <U > compute (T cmplxAlg , V realAlg , DimensionedDataSource <W > realData , int axis0 , int axis1 , IntegerIndex otherPositions )
83
+ DimensionedDataSource <U > compute (T complexAlg , V realAlg , DimensionedDataSource <U > complexData , int axis0 , int axis1 , IntegerIndex otherPositions )
84
84
{
85
- U complexValue = cmplxAlg .construct ();
85
+ U complexValue = complexAlg .construct ();
86
86
87
- W realValue = realAlg .construct ();
88
-
89
- W zero = realAlg .construct ();
90
-
91
87
// grab the plane of data the user is interested in
92
88
93
- PlaneView <W > view = new PlaneView <W >( realData , axis0 , axis1 );
89
+ PlaneView <U > view = new PlaneView <U >( complexData , axis0 , axis1 );
94
90
95
91
for (int i = 0 ; i < otherPositions .numDimensions (); i ++) {
96
92
view .setPositionValue (i , otherPositions .get (i ));
97
93
}
98
94
99
- DimensionedDataSource <W > theData = view .copyPlane (realValue );
95
+ DimensionedDataSource <U > theData = view .copyPlane (complexValue );
100
96
101
97
// calc some important variables
102
98
@@ -108,25 +104,23 @@ DimensionedDataSource<U> compute(T cmplxAlg, V realAlg, DimensionedDataSource<W>
108
104
109
105
// create power of two square planes for calculations
110
106
111
- DimensionedDataSource <U > inputPlane = DimensionedStorage .allocate (( Allocatable ) complexValue , new long [] {sz ,sz });
107
+ DimensionedDataSource <U > inputPlane = DimensionedStorage .allocate (complexValue , new long [] {sz ,sz });
112
108
113
- DimensionedDataSource <U > tmpPlane = DimensionedStorage .allocate (( Allocatable ) complexValue , new long [] {sz ,sz });
109
+ DimensionedDataSource <U > tmpPlane = DimensionedStorage .allocate (complexValue , new long [] {sz ,sz });
114
110
115
- DimensionedDataSource <U > outputPlane = DimensionedStorage .allocate (( Allocatable ) complexValue , new long [] {sz ,sz });
111
+ DimensionedDataSource <U > outputPlane = DimensionedStorage .allocate (complexValue , new long [] {sz ,sz });
116
112
117
113
// Copy the rectangular input image into the square plane defined for it.
118
114
// The other (padded) values are zero.
119
115
120
- TwoDView <W > realVw = new TwoDView <>(theData );
116
+ TwoDView <U > complexVw1 = new TwoDView <>(theData );
121
117
122
- TwoDView <U > complexVw = new TwoDView <>(inputPlane );
118
+ TwoDView <U > complexVw2 = new TwoDView <>(inputPlane );
123
119
124
120
for (long y = 0 ; y < rows ; y ++) {
125
121
for (long x = 0 ; x < cols ; x ++) {
126
- realVw .get (x , y , realValue );
127
- complexValue .setR (realValue );
128
- complexValue .setI (zero );
129
- complexVw .set (x , y , complexValue );
122
+ complexVw1 .get (x , y , complexValue );
123
+ complexVw2 .set (x , y , complexValue );
130
124
}
131
125
}
132
126
@@ -138,15 +132,15 @@ DimensionedDataSource<U> compute(T cmplxAlg, V realAlg, DimensionedDataSource<W>
138
132
139
133
IndexedDataSource <U > inCol = new SequencedDataSource <>(inputPlane .rawData (), c , sz , sz );
140
134
141
- IndexedDataSource <U > inPiped = new FixedSizeZeroPaddedDataSource <T ,U >(cmplxAlg , inCol , sz );
135
+ IndexedDataSource <U > inPiped = new FFTDataSource <T ,U >(complexAlg , inCol , sz );
142
136
143
137
// setup the padded tmp piped to place FFT results in
144
138
145
139
IndexedDataSource <U > tmpCol = new SequencedDataSource <>(tmpPlane .rawData (), c , sz , sz );
146
140
147
141
// do the fft into output col
148
142
149
- FFT .compute (cmplxAlg , realAlg , inPiped , tmpCol );
143
+ FFT .compute (complexAlg , realAlg , inPiped , tmpCol );
150
144
}
151
145
152
146
@@ -158,92 +152,17 @@ DimensionedDataSource<U> compute(T cmplxAlg, V realAlg, DimensionedDataSource<W>
158
152
159
153
IndexedDataSource <U > tmpRow = new SequencedDataSource <>(tmpPlane .rawData (), r *sz , 1 , sz );
160
154
161
- IndexedDataSource <U > tmpPiped = new FixedSizeZeroPaddedDataSource <T ,U >(cmplxAlg , tmpRow , sz );
155
+ IndexedDataSource <U > tmpPiped = new FFTDataSource <T ,U >(complexAlg , tmpRow , sz );
162
156
163
157
// setup the padded output piped to place FFT results in
164
158
165
159
IndexedDataSource <U > outRow = new SequencedDataSource <>(outputPlane .rawData (), r *sz , 1 , sz );
166
160
167
161
// do the fft into output row
168
162
169
- FFT .compute (cmplxAlg , realAlg , tmpPiped , outRow );
163
+ FFT .compute (complexAlg , realAlg , tmpPiped , outRow );
170
164
}
171
165
172
166
return outputPlane ;
173
167
}
174
-
175
- private static class FixedSizeZeroPaddedDataSource <M extends Algebra <M ,N >, N >
176
- implements IndexedDataSource <N >
177
- {
178
- final M alg ;
179
- final IndexedDataSource <N > data ;
180
- final long paddedDataSize ;
181
- final long dataSize ;
182
-
183
- FixedSizeZeroPaddedDataSource (M alg , IndexedDataSource <N > ds , long powerOfTwoLimit ) {
184
-
185
- if (powerOfTwoLimit <= 0 )
186
- throw new IllegalArgumentException ("power of two limit must b 1 or greater" );
187
-
188
- if (powerOfTwoLimit < ds .size ())
189
- throw new IllegalArgumentException ("size of source not contained by size limit of piped" );
190
-
191
- if (FFT .enclosingPowerOf2 (powerOfTwoLimit ) != powerOfTwoLimit )
192
- throw new IllegalArgumentException ("Provided powerOfTwoLimit is not a power of two" );
193
-
194
- this .alg = alg ;
195
-
196
- this .data = ds ;
197
-
198
- this .paddedDataSize = powerOfTwoLimit ;
199
-
200
- this .dataSize = data .size ();
201
- }
202
-
203
- @ Override
204
- public IndexedDataSource <N > duplicate () {
205
-
206
- return new FixedSizeZeroPaddedDataSource <>(alg , data , paddedDataSize );
207
- }
208
-
209
- @ Override
210
- public StorageConstruction storageType () {
211
-
212
- return data .storageType ();
213
- }
214
-
215
- @ Override
216
- public void set (long index , N value ) {
217
-
218
- if (index >= 0 && index < dataSize ) {
219
-
220
- data .set (index , value );
221
- }
222
- }
223
-
224
- @ Override
225
- public void get (long index , N value ) {
226
-
227
- if (index >= 0 && index < dataSize ) {
228
-
229
- data .get (index , value );
230
- }
231
- else {
232
-
233
- alg .zero ().call (value );
234
- }
235
- }
236
-
237
- @ Override
238
- public long size () {
239
-
240
- return paddedDataSize ;
241
- }
242
-
243
- @ Override
244
- public boolean accessWithOneThread () {
245
-
246
- return data .accessWithOneThread ();
247
- }
248
- }
249
168
}
0 commit comments