16 #define MAX_USHORT 65535.0f 23 for (
int i=0; i<24; i++) {
24 copy(spinor[i], in[idx*24+i]);
25 spinor[i] *= norm[idx];
33 for (
int i=0; i<24; i++) {
34 float tmp = fabs(spinor[i]);
35 if (tmp > max) max =
tmp;
39 for (
int i=0; i<24; i++)
copy(out[idx*24+i], spinor[i]/max);
45 for (
int i=0; i<12; i++) {
47 ucopy(mag,((ushort*)in)[idx*24+i*2+0]);
49 copy(phase,in[idx*24+i*2+1]);
51 spinor[2*i+0] = mag*
cos(phase);
52 spinor[2*i+1] = mag*
sin(phase);
60 for (
int i=0; i<12; i++) {
61 float tmp =
sqrt(spinor[2*i+0]*spinor[2*i+0] + spinor[2*i+1]*spinor[2*i+1]);
62 if (tmp > max) max =
tmp;
66 for (
int i=0; i<12; i++) {
67 float phase =
atan2(spinor[2*i+1], spinor[2*i+0]) / M_PI;
68 float mag =
sqrt(spinor[2*i+0]*spinor[2*i+0] + spinor[2*i+1]*spinor[2*i+1]) / max;
70 ucopy(((ushort*)out)[idx*24+i*2+0], mag);
71 copy(out[idx*24+i*2+1], phase);
77 for (
int j=0; j<N; j++) {
79 for (
int i=0; i<24; i++) spinor[i] = in[j*24+i];
86 for (
int j=0; j<N; j++) {
89 for (
int i=0; i<24; i++) out[j*24+i] = spinor[i];
95 for (
int j=0; j<N; j++) {
97 for (
int i=0; i<24; i++) spinor[i] = in[j*24+i];
104 for (
int j=0; j<N; j++) {
107 for (
int i=0; i<24; i++) out[j*24+i] = spinor[i];
113 for (
int j=0; j<N; j++) {
114 for (
int i=0; i<24; i++) {
120 double l2(
float *a,
float *b,
int N) {
123 for (
int j=0; j<N; j++) {
126 for (
int i=0; i<24; i++) {
127 dif += a[j*24+i]*a[j*24+i] - b[j*24+i]*b[j*24+i];
128 nrm += a[j*24+i]*a[j*24+i];
130 rtn +=
sqrt(fabs(dif)/nrm);
139 short *old_half = (
short*)
safe_malloc(24*N*
sizeof(
short));
140 float *old_norm = (
float*)
safe_malloc(N*
sizeof(
float));
141 float *old_recon = (
float*)
safe_malloc(24*N*
sizeof(
float));
142 short *new_half = (
short*)
safe_malloc(24*N*
sizeof(
short));
143 float *new_norm = (
float*)
safe_malloc(N*
sizeof(
float));
144 float *new_recon = (
float*)
safe_malloc(24*N*
sizeof(
float));
146 for (
float power=0.0; power<2.0; power+=0.1) {
155 printf(
"pow=%e, L2 spinor deviation: old = %e, new = %e, ratio = %e\n",
156 power,
l2(ref,old_recon,N),
l2(ref,new_recon,N),
157 l2(ref,old_recon,N) /
l2(ref,new_recon,N));
160 for (
int j=0; j<N; j++) {
161 for (
int i=0; i<12; i++) {
162 printf(
"power=%4.2f i=%d ref=(%e,%e) old=(%e,%e), new=(%e,%e)\n",
163 power, i, ref[j*24+i*2+0], ref[j*24+i*2+1],
164 old_recon[j*24+i*2+0], old_recon[j*24+i*2+1],
165 new_recon[j*24+i*2+0], new_recon[j*24+i*2+1]);
void newCopyToHalf(short *out, float *norm, float *in, int N)
__host__ __device__ ValueType norm(const complex< ValueType > &z)
Returns the magnitude of z squared.
void ucopy(float &a, const ushort &b)
__host__ __device__ ValueType sqrt(ValueType x)
cudaColorSpinorField * tmp
void new_load_half(float spinor[24], short *in, float *norm, int idx)
__host__ __device__ void copy(T1 &a, const T2 &b)
double l2(float *a, float *b, int N)
void newCopyToFloat(float *out, short *in, float *norm, int N)
void insertNoise(float *field, int N, float power)
__host__ __device__ ValueType sin(ValueType x)
__host__ __device__ ValueType atan2(ValueType x, ValueType y)
__host__ __device__ ValueType pow(ValueType x, ExponentType e)
Provides precision abstractions and defines the register precision given the storage precision using ...
void new_save_half(float spinor[24], short *out, float *norm, int idx)
#define safe_malloc(size)
void oldCopyToFloat(float *out, short *in, float *norm, int N)
void old_save_half(float spinor[24], short *out, float *norm, int idx)
cpuColorSpinorField * out
cpuColorSpinorField * ref
void old_load_half(float spinor[24], short *in, float *norm, int idx)
__host__ __device__ ValueType cos(ValueType x)
void oldCopyToHalf(short *out, float *norm, float *in, int N)
cpuColorSpinorField * spinor