13 void factorize(
int n,
int *nfactor,
int **factor);
17 std::complex<double>
omega(
int i,
int n){
18 std::complex<double>
imag(0,1);
19 return exp(-2.*i*(M_PI/n)*imag);
26 std::complex<double> * data;
30 for (int64_t i=0; i<
np; i++){
31 data[i] =
omega((idx[i]/n)*(idx[i]%n), n);
33 DFT.
write(np, idx, data);
43 std::complex<double> * data;
47 for (int64_t i=0; i<
np; i++){
48 if (idx[i]<3) data[i] = std::complex<double>(1,0);
49 else data[i] =
omega(1,n);
51 T.
write(np, idx, data);
58 void fft(
Vector< std::complex<double> > & v,
int n){
61 std::complex<double> * data;
72 assert(nfact == logn);
76 v.get_local_data(&np, &idx, &data);
77 V.
write(np, idx, data);
84 for (
int i=0; i<nfact; i++){
86 rev_inds[i]=
'a'+nfact-i-1;
91 V[rev_inds] = V[inds];
92 for (
int i=0; i<nfact; i++){
105 for (
int i=0; i<nfact; i++){
122 char inds_T[2] = {
'a', inds[i]};
123 S[inds] = T[inds_T]*S_old[inds+1];
131 memcpy(inds_in, inds, nfact*
sizeof(
char));
133 inds_DFT[0] = inds[i];
135 V[inds] = DFT[inds_DFT]*V[inds_in];
140 v.write(np, idx, data);
160 da[
"i"] = DFT[
"ij"]*a[
"j"];
169 std::complex<double> dnrm;
171 s[
""] += da[
"i"]*da[
"i"];
173 bool pass = fabs(dnrm.real()) <= 1.E-6 && fabs(dnrm.imag()) <= 1.E-6;
177 printf(
"{ FFT = DFT } passed \n");
179 printf(
"{ FFT = DFT } failed \n");
189 char ** itr = std::find(begin, end, option);
190 if (itr != end && ++itr != end){
197 int main(
int argc,
char ** argv){
199 int const in_num = argc;
200 char ** input_str = argv;
202 MPI_Init(&argc, &argv);
203 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
204 MPI_Comm_size(MPI_COMM_WORLD, &np);
207 n = atoi(
getCmdOption(input_str, input_str+in_num,
"-n"));
212 World dw(argc, argv);
215 printf(
"Running FFT on random dimension %d vector\n",n);
Matrix class which encapsulates a 2D tensor.
Matrix< std::complex< double > > twiddle_matrix(int n, World &wrld)
Vector class which encapsulates a 1D tensor.
an instance of the CTF library (world) on a MPI communicator
Scalar class which encapsulates a 0D tensor.
int rank
rank of local processor
Matrix< std::complex< double > > DFT_matrix(int n, World &wrld)
def exp(init_x, out=None, where=True, casting='same_kind', order='F', dtype=None, subok=True)
void fft(Vector< std::complex< double > > &v, int n)
void get_local_data(int64_t *npair, int64_t **global_idx, dtype **data, bool nonzeros_only=false, bool unpack_sym=false) const
Gives the global indices and values associated with the local data.
int main(int argc, char **argv)
char * getCmdOption(char **begin, char **end, const std::string &option)
an instance of a tensor within a CTF world
std::complex< double > omega(int i, int n)
void factorize(int n, int *nfactor, int **factor)
computes the size of a tensor in packed symmetric layout
void write(int64_t npair, int64_t const *global_idx, dtype const *data)
writes in values associated with any set of indices The sparse data is defined in coordinate format...