<commit_before>use FFTW;

proc printcmp(x, y) {
	var err = max reduce abs(x-y);
	writeln(err);
}


/* Read in the data and set up the domains appropriately */
param ndim : int = 1;
var dims : ndim*int(32); 
var D : domain(ndim);
// Define ranges here
var rD,cD,reD,imD : domain(ndim,int,true); 
var A,B,goodA,goodB : [D] fftw_complex;
{
	var f = open("arr1d.dat",iomode.r).reader(kind=iokind.little);
	for ii in 1..ndim {
		f.read(dims(ii));
	}
	D = 0.. #dims(1);
	for (r,c) in goodA {
		f.read(r);
		c = 0;
	}
	for (r,c) in goodB {
		f.read(r); f.read(c);
	}
	f.close();
}
// Set up domains based on dimension size
var first : ndim*int;
if (ndim==1) {
	// Domains for real FFT
	rD = 0.. #(2*(dims(1)/2 + 1)); // Padding to do in place transforms
	cD = 0.. #(dims(1)/2 + 1);
	// Define domains to extract the real and imaginary parts
	reD = rD[0..(2*(dims(1)/2)+1) by 2]; // Padding to do in place transforms
	imD = rD[1..(2*(dims(1)/2) + 1) by 2]; // Padding to do in place transforms
	first=(0,);
}

// FFTW does not normalize inverse transform, set up norm
var norm = * reduce dims;


// FFT testing here
var fwd = plan_dft_1d(dims, A[first],B[first],FFTW_FORWARD,FFTW_ESTIMATE);
var rev = plan_dft_1d(dims, B[first],A[first],FFTW_BACKWARD,FFTW_ESTIMATE);
// Test forward and reverse transform
A = goodA;
execute(fwd);
printcmp(B,goodB);
execute(rev);
A /= norm; 
printcmp(A,goodA);
destroy_plan(fwd);
destroy_plan(rev);

// Test in-place transforms
fwd = plan_dft_1d(dims,A[first],A[first],FFTW_FORWARD,FFTW_ESTIMATE);
rev = plan_dft_1d(dims,A[first],A[first],FFTW_BACKWARD,FFTW_ESTIMATE);<commit_msg>Make more general<commit_after>use FFTW;

proc printcmp(x, y) {
	var err = max reduce abs(x-y);
	writeln(err);
}


/* Read in the data and set up the domains appropriately */
param ndim : int = 1;
var dims : ndim*int(32); 
var D : domain(ndim);
// Define ranges here
var rD,cD,reD,imD : domain(ndim,int,true); 
var A,B,goodA,goodB : [D] fftw_complex;
{
	var f = open("arr1d.dat",iomode.r).reader(kind=iokind.little);
	for ii in 1..ndim {
		f.read(dims(ii));
	}
	D = 0.. #dims(ndim);
	for (r,c) in goodA {
		f.read(r);
		c = 0;
	}
	for (r,c) in goodB {
		f.read(r); f.read(c);
	}
	f.close();
}
// Set up domains based on dimension size
var first : ndim*int;
if (ndim==1) {
	// Domains for real FFT
	rD = 0.. #(2*(dims(ndim)/2 + 1)); // Padding to do in place transforms
	cD = 0.. #(dims(ndim)/2 + 1);
	// Define domains to extract the real and imaginary parts
	reD = rD[0..(2*(dims(ndim)/2)+1) by 2]; // Padding to do in place transforms
	imD = rD[1..(2*(dims(ndim)/2) + 1) by 2]; // Padding to do in place transforms
	first=(0,);
}

// FFTW does not normalize inverse transform, set up norm
var norm = * reduce dims;


// FFT testing here
var fwd = plan_dft_1d(dims, A[first],B[first],FFTW_FORWARD,FFTW_ESTIMATE);
var rev = plan_dft_1d(dims, B[first],A[first],FFTW_BACKWARD,FFTW_ESTIMATE);
// Test forward and reverse transform
A = goodA;
execute(fwd);
printcmp(B,goodB);
execute(rev);
A /= norm; 
printcmp(A,goodA);
destroy_plan(fwd);
destroy_plan(rev);

// Test in-place transforms
fwd = plan_dft_1d(dims,A[first],A[first],FFTW_FORWARD,FFTW_ESTIMATE);
rev = plan_dft_1d(dims,A[first],A[first],FFTW_BACKWARD,FFTW_ESTIMATE);
{'fraction_non_alphanumeric': 0.17280891917002167, 'fraction_numerical': 0.02013007122948281, 'mean_word_length': 4.168, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5505424', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1387, 'n_words': 347}