MIDAPACK - MIcrowave Data Analysis PACKage  1.1b
Parallel software tools for high performance CMB DA analysis
toeplitz_rshp.c
Go to the documentation of this file.
1 
73 #include "toeplitz.h"
74 
75 // r1.1 - Frederic Dauvergne (APC)
76 // This is the reshaping routines to build the optimal data structure when
77 // needed. The index functions find the right index number of the data location
78 // for a choosen transformation.
79 
80 
81 int fctid_mat2vect(int i, int id0, int n, int lambda) {
82  int I, J, i_out;
83  int distcorrmin = lambda - 1;
84  int rfirst = id0 % n;
85 
86  if (i == -1) return (-1);
87 
88 
89  I = (i + rfirst) % (n + distcorrmin);
90  J = (i + rfirst) / (n + distcorrmin);
91 
92  if (I < n) i_out = I - rfirst + J * n;
93  else
94  i_out = -1; // not defined. value is zero.
95 
96 
97  return i_out;
98 }
99 
100 
101 int fctid_mat2vect_inv(int i, int id0, int n, int lambda) {
102  int I, J, i_out;
103  int distcorrmin = lambda - 1;
104  int rfirst = id0 % n;
105 
106  if (i == -1) i_out = -1; // not defined. value is zero.
107 
108  I = (i + rfirst) % (n);
109  J = (i + rfirst) / (n);
110 
111  i_out = I - rfirst + J * (n + distcorrmin);
112 
113  return i_out;
114 }
115 
116 
117 int fctid_concatcol(int i, int id0, int n, int m, int l, int lconc, int lambda,
118  int *nocol, int nbcol) {
119  int I, J, i_out;
120  int distcorrmin = lambda - 1;
121  int rfirst = id0 % n;
122 
123  if (i == -1) return (-1);
124 
125  if (i >= lconc) return (-2); // this indice not define. It shouldn't be used
126 
127  I = (i + rfirst) % (n);
128  J = (i + rfirst) / (n);
129 
130  i_out = I - rfirst + nocol[J] * (n);
131 
132 
133  return i_out;
134 }
135 
136 
137 int fctid_concatcol_inv(int i, int id0, int n, int m, int l, int lconc,
138  int lambda, int *nocol_inv, int nbcol) {
139  int I, J, i_out;
140  int distcorrmin = lambda - 1;
141  int rfirst = id0 % n;
142 
143  if (i == -1) return (-1);
144 
145  if (i >= l) return (-2); // this indice not define. It shouldn't be used
146 
147  I = (i + rfirst) % (n);
148  J = (i + rfirst) / (n);
149 
150  if (nocol_inv[J] == (-1)) i_out = -1;
151  else
152  i_out = I - rfirst + nocol_inv[J] * (n);
153 
154 
155  return i_out;
156 }
157 
158 
159 int fctid_vect2nfftblock(int i, int v1_size, int fft_size, int nfft,
160  int lambda) {
161 
162  int I, J, i_out;
163  int distcorrmin = lambda - 1;
164 
165  if (i == -1) return (-1);
166 
167  I = (i) % (fft_size);
168  J = (i) / (fft_size);
169 
170  i_out = (I - distcorrmin) + J * (fft_size - 2 * distcorrmin);
171 
172  if (i_out < 0 || i_out >= v1_size) i_out = -1;
173 
174 
175  return i_out;
176 }
177 
178 
179 int is_needconcat(int *nocol, int nbcol) {
180  int i;
181  int ip = nocol[0];
182  for (i = 1; i < nbcol; i++) {
183  if (nocol[i] != (ip + i)) return 1;
184  }
185 
186 
187  return 0;
188 }
189 
190 
191 int fctid_vect2nfftblock_inv(int i, int v1_size, int fft_size, int nfft,
192  int lambda) {
193 
194  int I, J, i_out;
195  int distcorrmin = lambda - 1;
196 
197  if (i < 0 || i >= v1_size) return (-2);
198 
199  I = (i) % (fft_size - 2 * distcorrmin);
200  J = (i) / (fft_size - 2 * distcorrmin);
201 
202  i_out = (I + distcorrmin) + J * (fft_size);
203 
204  return i_out;
205 }
206 
207 
208 int define_rshp_size(int flag_format_rshp, int fft_size, int nfft, int v1_size,
209  int vedge_size, int *nrshp, int *mrshp, int *lrshp) {
210 
211  if (flag_format_rshp == 2) {
212  *nrshp = fft_size;
213  *mrshp = nfft;
214  *lrshp = (*nrshp) * (*mrshp);
215  } else if (flag_format_rshp == 1) {
216  *nrshp = v1_size;
217  *mrshp = 1;
218  *lrshp = (*nrshp) * (*mrshp);
219  } else if (flag_format_rshp
220  == 0) { // this case appear only if flag_shortcut_nbcol_eq_1==0
221  *nrshp = vedge_size;
222  *mrshp = 1;
223  *lrshp = vedge_size;
224  } else { // error not a good flag_format_rshp
225  }
226 
227  return 0;
228 }
229 
230 
231 int build_nocol_inv(int *nocol, int nbcol,
232  int m) // ncol_inv to define as parameters
233 {
234  int i;
235  int *nocol_inv;
236  nocol_inv = (int *) calloc(m, sizeof(double));
237 
238  for (i = 0; i < m; i++) nocol_inv[i] = -1;
239  for (i = 0; i < nbcol; i++) nocol_inv[nocol[i]] = i;
240 
241 
242  return 0;
243 }
244 
245 
246 int build_reshape(double *Vin, int *nocol, int nbcol, int lconc, int n, int m,
247  int id0, int l, int lambda, int nfft, double *Vrshp,
248  int nrshp, int mrshp, int lrshp, int flag_format_rshp) {
249 
250  int i;
251  int rfirst = id0 % n;
252  int i_out1, i_out2, i_out3;
253  int distcorrmin = lambda - 1;
254 
255  int v1_size;
256  int fft_size;
257 
258  int idf = id0 + l - 1;
259  int lconc0;
260 
261  FILE *file;
262  file = stdout;
263 
264  v1_size = lconc + (distcorrmin) * (nbcol - 1);
265  fft_size = ceil(1.0 * v1_size / nfft) + 2 * distcorrmin;
266 
267  // used transformation
268  if (VERBOSE) {
269  fprintf(file, "fctid_concatcol: \t %d\n",
270  (is_needconcat(nocol, nbcol) == 1));
271  fprintf(file, "fctid_mat2vect: \t %d\n", (nbcol > 1));
272  fprintf(file, "fctid_vect2nfftblock \t %d\n", (nfft > 1));
273  }
274 
275 
276  for (i = 0; i < lrshp; i++) {
277 
278  if (nfft > 1)
279  i_out1 = fctid_vect2nfftblock(i, v1_size, fft_size, nfft, lambda);
280  else
281  i_out1 = i;
282 
283  if (nbcol > 1) i_out2 = fctid_mat2vect(i_out1, rfirst, n, lambda);
284  else
285  i_out2 = i_out1;
286 
287  if (is_needconcat(nocol, nbcol) == 1)
288  i_out3 = fctid_concatcol(i_out2, id0, n, m, l, lconc, lambda, nocol,
289  nbcol);
290  else
291  i_out3 = i_out2;
292 
293 
294  if (i_out3 == -1) Vrshp[i] = 0;
295  else
296  Vrshp[i] = Vin[i_out3];
297 
298  } // end for
299 
300 
301  return 0;
302 }
303 
304 
305 int extract_result(double *Vout, int *nocol, int nbcol, int lconc, int n, int m,
306  int id0, int l, int lambda, int nfft, double *Vrshp,
307  int nrshp, int mrshp, int lrshp, int flag_format_rshp) {
308 
309  int i;
310  int rfirst = id0 % n;
311  int i_out1, i_out2, i_out3;
312  int i_in1;
313  int distcorrmin = lambda - 1;
314 
315  int v1_size;
316  int fft_size;
317 
318  FILE *file;
319  file = stdout;
320 
321  v1_size = lconc + (distcorrmin) * (nbcol - 1);
322  fft_size = ceil(1.0 * v1_size / nfft) + 2 * distcorrmin;
323 
324  // used transformation
325  if (VERBOSE) {
326  fprintf(file, "fctid_concatcol: \t %d\n",
327  (is_needconcat(nocol, nbcol) == 1));
328  fprintf(file, "fctid_mat2vect: \t %d\n", (nbcol > 1));
329  fprintf(file, "fctid_vect2nfftblock \t %d\n", (nfft > 1));
330  }
331 
332  int lcol;
333  int j, k;
334 
335  for (i = 0; i < lconc; i++) {
336 
337  if (is_needconcat(nocol, nbcol) == 1)
338  i_in1 = fctid_concatcol(i, id0, n, m, l, lconc, lambda, nocol,
339  nbcol);
340  else
341  i_in1 = i;
342 
343  if (nbcol > 1) i_out2 = fctid_mat2vect_inv(i, rfirst, n, lambda);
344  else
345  i_out2 = i_out1;
346 
347  if (nfft > 1)
348  i_out3 = fctid_vect2nfftblock_inv(i_out2, v1_size, fft_size, nfft,
349  lambda);
350  else
351  i_out3 = i_out2;
352 
353  if (i_out3 == -1) Vout[i] = -1;
354  else if (i_out3 == -2)
355  Vout[i] = -2;
356  else
357  Vout[i_in1] = Vrshp[i_out3];
358  }
359 
360 
361  return 0;
362 }
int VERBOSE
Verbose mode.
Definition: toeplitz.c:113
int build_reshape(double *Vin, int *nocol, int nbcol, int lconc, int n, int m, int id0, int l, int lambda, int nfft, double *Vrshp, int nrshp, int mrshp, int lrshp, int flag_format_rshp)
int define_rshp_size(int flag_format_rshp, int fft_size, int nfft, int v1_size, int vedge_size, int *nrshp, int *mrshp, int *lrshp)
int is_needconcat(int *nocol, int nbcol)
int build_nocol_inv(int *nocol, int nbcol, int m)
int fctid_vect2nfftblock_inv(int i, int v1_size, int fft_size, int nfft, int lambda)
int fctid_concatcol_inv(int i, int id0, int n, int m, int l, int lconc, int lambda, int *nocol_inv, int nbcol)
int fctid_concatcol(int i, int id0, int n, int m, int l, int lconc, int lambda, int *nocol, int nbcol)
int extract_result(double *Vout, int *nocol, int nbcol, int lconc, int n, int m, int id0, int l, int lambda, int nfft, double *Vrshp, int nrshp, int mrshp, int lrshp, int flag_format_rshp)
int fctid_mat2vect(int i, int id0, int n, int lambda)
Definition: toeplitz_rshp.c:81
int fctid_vect2nfftblock(int i, int v1_size, int fft_size, int nfft, int lambda)
int fctid_mat2vect_inv(int i, int id0, int n, int lambda)