3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
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 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
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.
21 #include <gsl/gsl_errno.h>
22 #include <gsl/gsl_fft_complex.h>
24 #include "factorize.h"
27 fft_complex_factorize (const size_t n,
31 const size_t complex_subtransforms[] =
32 {7, 6, 5, 4, 3, 2, 0};
34 /* other factors can be added here if their transform modules are
35 implemented. The end of the list is marked by 0. */
37 int status = fft_factorize (n, complex_subtransforms, nf, factors);
42 fft_halfcomplex_factorize (const size_t n,
46 const size_t halfcomplex_subtransforms[] =
49 int status = fft_factorize (n, halfcomplex_subtransforms, nf, factors);
54 fft_real_factorize (const size_t n,
58 const size_t real_subtransforms[] =
61 int status = fft_factorize (n, real_subtransforms, nf, factors);
67 fft_factorize (const size_t n,
68 const size_t implemented_subtransforms[],
80 GSL_ERROR ("length n must be positive integer", GSL_EDOM);
90 /* deal with the implemented factors first */
92 while (implemented_subtransforms[i] && ntest != 1)
94 factor = implemented_subtransforms[i];
95 while ((ntest % factor) == 0)
97 ntest = ntest / factor;
104 /* deal with any other even prime factors (there is only one) */
108 while ((ntest % factor) == 0 && (ntest != 1))
110 ntest = ntest / factor;
111 factors[nf] = factor;
115 /* deal with any other odd prime factors */
121 while ((ntest % factor) != 0)
125 ntest = ntest / factor;
126 factors[nf] = factor;
130 /* check that the factorization is correct */
134 for (i = 0; i < nf; i++)
136 product *= factors[i];
141 GSL_ERROR ("factorization failed", GSL_ESANITY);
152 fft_binary_logn (const size_t n)
155 size_t binary_logn = 0 ;
164 ntest = (1 << binary_logn) ;
168 return -1 ; /* n is not a power of 2 */