 
 
 //			cudaMemcpy(&d_data[index], &data[index], sizeof(cufftComplex), cudaMemcpyHostToDevice);
-			cudaMemcpy(d_data, data, sizeof(cufftComplex) * SIDE * SHORT_SIDE, cudaMemcpyHostToDevice);
+//			cudaMemcpy(d_data, data, sizeof(cufftComplex) * SIDE * SHORT_SIDE, cudaMemcpyHostToDevice);
+			cudaMemcpy2D(d_data, sizeof(cufftComplex) * SIDE, data, sizeof(cufftComplex) * SIDE, SHORT_SIDE / 2 * sizeof(cufftComplex), SHORT_SIDE / 2, cudaMemcpyHostToDevice);
+			cudaMemcpy2D(&d_data[SIDE - SHORT_SIDE / 2], sizeof(cufftComplex) * SIDE, &data[SHORT_SIDE / 2], sizeof(cufftComplex) * SIDE, SHORT_SIDE / 2 * sizeof(cufftComplex), SHORT_SIDE / 2, cudaMemcpyHostToDevice);
+
+			cudaMemcpy2D(&d_data[(SIDE - SHORT_SIDE / 2) * SIDE], sizeof(cufftComplex) * SIDE, &data[SHORT_SIDE / 2 * SIDE], sizeof(cufftComplex) * SIDE, SHORT_SIDE / 2 * sizeof(cufftComplex), SHORT_SIDE / 2, cudaMemcpyHostToDevice);
+			cudaMemcpy2D(&d_data[(SIDE - SHORT_SIDE / 2) * (SIDE + 1)], sizeof(cufftComplex) * SIDE, &data[SHORT_SIDE / 2 * SIDE + SHORT_SIDE / 2], sizeof(cufftComplex) * SIDE, SHORT_SIDE / 2 * sizeof(cufftComplex), SHORT_SIDE / 2, cudaMemcpyHostToDevice);
 
 			cufftExecC2C(plan, d_data, d_pattern, CUFFT_FORWARD);
 			double newLikelihood = thrust::transform_reduce(thrust::make_zip_iterator(thrust::make_tuple(t_truePattern, t_mask, t_pattern)),
                                          thrust::make_zip_iterator(thrust::make_tuple(&t_truePattern[SIDE * SIDE], &t_mask[SIDE * SIDE], &t_pattern[SIDE * SIDE])), likelihooder,
-					 (double) 0, thrust::plus<double>()) + 34154. * SIDE * SIDE;
+					 (double) 0, thrust::plus<double>()) + 34154. * 2 * SIDE * SIDE;
 			if (newLikelihood > oldLikelihood)
 			{
 //				printf("FORCED ACCEPT: x: %d, y: %d - %f at %lf : %f %lf %lf %d\n", x, y, val, angle, newLikelihood, nowsum, nowsum - basesum + basesum * factor * factor, iter);

double __device__ likelihood(int count, int mask, cufftComplex val)
{	
	if (!mask) return 0;
	double val2 = val.x * val.x + val.y * val.y;
	double term = 0;
/*	if (val2 < 1e-9)
	{
		term = -val.x * val.x;val2 = 1e-9;
	}
	else*/
	{
		term += log(val2) * count - val2;
	}

//	term -= val.y * val.y;
	return term;



int SIDE = 256;
int SHORT_SIDE = 24;

#include <cufft.h>
#include <thrust/device_vector.h>
