Commit dd360cef authored by Matthew Tam's avatar Matthew Tam
Browse files

replaced occurances of 'xrange' with 'range' since the command was renamed in python3.

parent c64f9d14
......@@ -126,12 +126,12 @@ class RAAR(Algorithm):
tmp_change = (scipy.linalg.norm(u-tmp_u,'fro')/normM)**2;
tmp_gap = (scipy.linalg.norm(tmp3-tmp2,'fro')/normM)**2;
elif Nz == 1:
for j in xrange(dim):
for j in range(dim):
tmp_change += (scipy.linalg.norm(u[:,:,j]-tmp_u[:,:,j],'fro')/normM)**2;
tmp_gap += (scipy.linalg.norm(tmp3[:,:,j]-tmp2[:,:,j])/normM,'fro')**2;
else:
for j in xrange(dim):
for k in xrange(Nz):
for j in range(dim):
for k in range(Nz):
tmp_change += (scipy.linalg.norm(u[:,:,k,j]-tmp_u[:,:,k,j],'fro')/normM)**2;
tmp_gap += (scipy.linalg.norm(tmp3[:,:,k,j]-tmp2[:,:,k,j],'fro')/normM)**2;
......@@ -245,12 +245,12 @@ class HPR(Algorithm):
tmp_change = (scipy.linalg.norm(u-tmp_u,'fro')/normM)**2;
tmp_gap = (scipy.linalg.norm(tmp3-tmp2,'fro')/normM)**2;
elif Nz == 1:
for j in xrange(dim):
for j in range(dim):
tmp_change += (scipy.linalg.norm(u[:,:,j]-tmp_u[:,:,j],'fro')/normM)**2;
tmp_gap += (scipy.linalg.norm(tmp3[:,:,j]-tmp2[:,:,j])/normM,'fro')**2;
else:
for j in xrange(dim):
for k in xrange(Nz):
for j in range(dim):
for k in range(Nz):
tmp_change += (scipy.linalg.norm(u[:,:,k,j]-tmp_u[:,:,k,j],'fro')/normM)**2;
tmp_gap += (scipy.linalg.norm(tmp3[:,:,k,j]-tmp2[:,:,k,j],'fro')/normM)**2;
......@@ -344,12 +344,12 @@ class AP(Algorithm):
tmp_change = (scipy.linalg.norm(u-tmp_u,'fro')/normM)**2;
tmp_gap = (scipy.linalg.norm(tmp1-tmp_u,'fro')/normM)**2;
elif Nz == 1:
for j in xrange(dim):
for j in range(dim):
tmp_change += (scipy.linalg.norm(u[:,:,j]-tmp_u[:,:,j],'fro')/normM)**2;
tmp_gap += (scipy.linalg.norm(tmp1[:,:,j]-tmp_u[:,:,j])/normM,'fro')**2;
else:
for j in xrange(dim):
for k in xrange(Nz):
for j in range(dim):
for k in range(Nz):
tmp_change += (scipy.linalg.norm(u[:,:,k,j]-tmp_u[:,:,k,j],'fro')/normM)**2;
tmp_gap += (scipy.linalg.norm(tmp1[:,:,k,j]-tmp_u[:,:,k,j],'fro')/normM)**2;
change[iters] = math.sqrt(tmp_change);
......
......@@ -35,15 +35,15 @@ def go():
('sequential','sequential'),('parallel','sequential')];
algorithms = ['PALM','PALMregPhiPtwise','Rodenburg','Thibault'];
for i in xrange(6):
for i in range(6):
config['block_rows'] = blocking_sizes[i];
config['block_cols'] = blocking_sizes[i];
for j in xrange(4):
for j in range(4):
config['between_blocks_scheme'] = blocking_schemes[j][0];
config['within_blocks_scheme'] = blocking_schemes[j][1];
for k in xrange(4):
for k in range(4):
config['ptychography_prox'] = algorithms[k];
problem = BenchmarkPtychography(config);
......
......@@ -111,11 +111,11 @@ class P_diag(ProxOperator):
tmp = numpy.sum(u,axis=0,dtype=u.dtype);
elif p == 1:
tmp = numpy.zeros((n,m),dtype=u.dtype);
for k in xrange(K):
for k in range(K):
tmp += u[:,:,k];
else:
tmp = numpy.zeros((n,m,p),dtype=u.dtype);
for k in xrange(K):
for k in range(K):
tmp += u[:,:,:,k];
tmp /= K;
......@@ -126,12 +126,12 @@ class P_diag(ProxOperator):
return numpy.dot(numpy.ones((K,1),dtype=u.dtype),tmp);
elif p == 1:
u_diag = numpy.empty((n,m,K),dtype=u.dtype);
for k in xrange(K):
for k in range(K):
u_diag[:,:,k] = tmp;
return u_diag;
else:
u_diag = numpy.empty((n,m,p,K),dtype=u.dtype);
for k in xrange(K):
for k in range(K):
u_diag[:,:,:,k] = tmp;
return u_diag;
......@@ -182,19 +182,19 @@ class P_parallel(ProxOperator):
if m == 1:
u_parallel = numpy.empty((K,n),dtype=u.dtype);
for k in xrange(K):
for k in range(K):
u_parallel[k,:] = proj[k].work(u[k,:]);
elif n == 1:
u_parallel = numpy.empty((m,K),dtype=u.dtype);
for k in xrange(K):
for k in range(K):
u_parallel[:,k] = proj[k].work(u[:,k]);
elif p == 1:
u_parallel = numpy.empty((n,m,K),dtype=u.dtype);
for k in xrange(K):
for k in range(K):
u_parallel[:,:,k] = proj[k].work(u[:,:,k]);
else:
u_parallel = numpy.empty((n,m,p,K),dtype=u.dtype);
for k in xrange(K):
for k in range(K):
u_parallel[:,:,:,k] = proj[k].work(u[:,:,:,k]);
return u_parallel;
......
......@@ -154,7 +154,7 @@ class P_rodenburg(ProxOperator):
(fmask[:,:,pos] == 0).astype(fmask.dtype);
phi_prime = scipy.fftpack.ifft2(phi_hat) * fnorm;
for k in xrange(inner_it):
for k in range(inner_it):
this_object_old = this_object.copy();
this_probe_old = this_probe.copy();
cthis_probe_old = numpy.conj(this_probe_old);
......@@ -168,7 +168,7 @@ class P_rodenburg(ProxOperator):
n_object = (cthis_probe_old/i_probe) * d_phi;
this_probe = this_probe_old + n_probe;
for y in xrange(Ny):
for y in range(Ny):
this_object[indy[y],indx] = \
this_object_old[indy[y],indx] + n_object[y,:];
......@@ -222,7 +222,7 @@ class P_rodenburg_probe_fixed(P_rodenburg):
rangeNx = numpy.arange(Nx,dtype=numpy.int);
rangeNy = numpy.arange(Ny,dtype=numpy.int);
for pos in numpy.random.permutation(xrange(self.N_pie)):
for pos in numpy.random.permutation(range(self.N_pie)):
indy = rangeNy + positions[pos,0];
indx = rangeNx + positions[pos,1];
......@@ -241,7 +241,7 @@ class P_rodenburg_probe_fixed(P_rodenburg):
(fmask[:,:,pos] == 0).astype(fmask.dtype);
phi_prime = scipy.fftpack.ifft2(phi_hat) * fnorm;
for k in xrange(inner_it):
for k in range(inner_it):
this_object_old = this_object.copy();
this_probe_old = this_probe.copy();
cthis_probe_old = numpy.conj(this_probe_old);
......@@ -251,7 +251,7 @@ class P_rodenburg_probe_fixed(P_rodenburg):
n_object = (cthis_probe_old/i_probe) * d_phi;
for y in xrange(Ny):
for y in range(Ny):
this_object[indy[y],indx] = \
this_object_old[indy[y],indx] + n_object[y,:];
......@@ -313,12 +313,12 @@ class P_thibault_f(ProxOperator):
if self.ptychography_prox == 'Thibault_AP':
rangeNx = numpy.arange(Nx,dtype=numpy.int);
rangeNy = numpy.arange(Ny,dtype=numpy.int);
for pos in xrange(self.N_pie):
for pos in range(self.N_pie):
indy = rangeNy + positions[pos,0];
indx = rangeNx + positions[pos,1];
phi[:,:,pos] = probe * obj[indy,:][:,indx];
for pos in xrange(self.N_pie):
for pos in range(self.N_pie):
old_phi_hat = scipy.fftpack.fft2(phi[:,:,pos]) / fnorm;
phi_hat = magproj(old_phi_hat,amp_exp_norm[:,:,pos]);
if not fmask is None:
......@@ -378,11 +378,11 @@ class P_thibault_o(ProxOperator):
obj_denom.fill(1e-30);
c_probe = numpy.conj(this_probe)
i_probe = numpy.real(c_probe*this_probe);
for pos in xrange(N_pie):
for pos in range(N_pie):
indy = rangeNy + positions[pos,0];
indx = rangeNx + positions[pos,1];
for y in xrange(Ny):
for y in range(Ny):
obj_enum[indy[y],indx] += c_probe[y,:] * phi[y,:,pos];
obj_denom[indy[y],indx] += i_probe[y,:];
......@@ -404,7 +404,7 @@ class P_thibault_o(ProxOperator):
phi = phi.copy();
if self.ptychography_prox == 'Thibault':
for pos in xrange(N_pie):
for pos in range(N_pie):
indy = rangeNy + positions[pos,0];
indx = rangeNx + positions[pos,1];
phi[:,:,pos] = this_probe * this_object[indy,:][:,indx];
......@@ -464,11 +464,11 @@ class P_thibault_op(ProxOperator):
c_probe = numpy.conj(this_probe);
i_probe = numpy.real(c_probe*this_probe);
for pos in xrange(N_pie):
for pos in range(N_pie):
indy = rangeNy + positions[pos,0];
indx = rangeNx + positions[pos,1];
for y in xrange(Ny):
for y in range(Ny):
obj_enum[indy[y],indx] += c_probe[y,:] * phi[y,:,pos];
obj_denom[indy[y],indx] += i_probe[y,:];
......@@ -488,7 +488,7 @@ class P_thibault_op(ProxOperator):
probe_denom = cfact;
conj_obj = numpy.conj(this_object);
abs_obj = numpy.real(this_object*conj_obj);
for pos in xrange(N_pie):
for pos in range(N_pie):
indy = rangeNy + positions[pos,0];
indx = rangeNx + positions[pos,1];
......@@ -508,7 +508,7 @@ class P_thibault_op(ProxOperator):
phi = phi.copy();
if self.ptychography_prox == 'Thibault':
for pos in xrange(N_pie):
for pos in range(N_pie):
indy = rangeNy + positions[pos,0];
indx = rangeNx + positions[pos,1];
phi[:,:,pos] = this_probe * this_object[indy,:][:,indx];
......@@ -549,7 +549,7 @@ class P_PHeBIE_probe(ProxOperator):
conj_obj = numpy.conj(u.obj);
modsq_obj = numpy.real(u.obj * conj_obj);
for ypos in xrange(self.N_pie):
for ypos in range(self.N_pie):
indy = rangeNy + positions[ypos,0];
indx = rangeNx + positions[ypos,1];
ysum += modsq_obj[indy,:][:,indx];
......@@ -598,7 +598,7 @@ class P_PHeBIE_probe_ptwise(P_PHeBIE_probe):
conj_obj = numpy.conj(u.obj);
modsq_obj = numpy.real(u.obj * conj_obj);
for ypos in xrange(self.N_pie):
for ypos in range(self.N_pie):
indy = rangeNy + positions[ypos,0];
indx = rangeNx + positions[ypos,1];
ysum += modsq_obj[indy,:][:,indx];
......@@ -659,10 +659,10 @@ class P_PHeBIE_object(ProxOperator):
conj_probe = numpy.conj(probe);
modsq_probe = numpy.real(probe * conj_probe);
for xpos in xrange(self.N_pie):
for xpos in range(self.N_pie):
indy = rangeNy + positions[xpos,0];
indx = rangeNx + positions[xpos,1];
for y in xrange(Ny):
for y in range(Ny):
xsum[indy[y],indx] += modsq_probe[y,:];
phisum[indy[y],indx] += conj_probe[y,:] * phi[y,:,xpos];
......@@ -709,10 +709,10 @@ class P_PHeBIE_object_ptwise(P_PHeBIE_object):
conj_probe = numpy.conj(probe);
modsq_probe = numpy.real(probe * conj_probe);
for xpos in xrange(self.N_pie):
for xpos in range(self.N_pie):
indy = rangeNy + positions[xpos,0];
indx = rangeNx + positions[xpos,1];
for y in xrange(Ny):
for y in range(Ny):
xsum[indy[y],indx] += modsq_probe[y,:];
phisum[indy[y],indx] += conj_probe[y,:] * phi[y,:,xpos];
......@@ -769,7 +769,7 @@ class P_PHeBIE_phi(ProxOperator):
obj = u.obj;
probe = u.probe;
for pos in xrange(self.N_pie):
for pos in range(self.N_pie):
indy = rangeNy + positions[pos,0];
indx = rangeNx + positions[pos,1];
new_phi = probe * obj[indy,:][:,indx];
......@@ -823,7 +823,7 @@ class P_PHeBIE_phi_regularized(ProxOperator):
gamma = self.overrelax - 1;
for pos in xrange(self.N_pie):
for pos in range(self.N_pie):
indy = rangeNy + positions[pos,0];
indx = rangeNx + positions[pos,1];
new_phi = (2.0/(2.0+gamma)) * probe * obj[indy,:][:,indx] + \
......@@ -889,7 +889,7 @@ class PtychographyStats():
rangeNy = numpy.arange(self.Ny,dtype=numpy.int);
rangeNx = numpy.arange(self.Nx,dtype=numpy.int);
for pos in xrange(self.N_pie):
for pos in range(self.N_pie):
indy = rangeNy + positions[pos,0];
indx = rangeNx + positions[pos,1];
obj_value += scipy.linalg.norm(probe * obj[indy,:][:,indx] - \
......@@ -920,7 +920,7 @@ class PtychographyStats():
if self.Nx == 1 or self.Ny == 1:
changephi = (scipy.linalg.norm(x1.phi-x2.phi,'fro')/normM)**2;
else:
for j in xrange(self.dim):
for j in range(self.dim):
changephi += (scipy.linalg.norm(x1.phi[:,:,j]-x2.phi[:,:,j], \
'fro')/normM)**2;
changephi += (scipy.linalg.norm(x1.obj-x2.obj,'fro')/normM)**2;
......@@ -972,7 +972,7 @@ class PtychographyStats():
numpy.conj(supported_plane)).real;
r_factor = 0.0;
for pos in xrange(self.N_pie):
for pos in range(self.N_pie):
indy = rangeNy + positions[pos,0];
indx = rangeNx + positions[pos,1];
if fmask is None:
......@@ -989,7 +989,7 @@ class PtychographyStats():
if self.Nx == 1 or self.Ny == 1:
change_phi = (scipy.linalg.norm(x1.phi-x2.phi,'fro')/normM)**2;
else:
for j in xrange(self.dim):
for j in range(self.dim):
change_phi += (scipy.linalg.norm(x1.phi[:,:,j]-x2.phi[:,:,j],'fro')/normM)**2;
if self.ptychography_prox == 'Thibault':
......@@ -1270,7 +1270,7 @@ class Blocking_meta(Algorithm):
sub_phi = numpy.empty((u.phi.shape[0], u.phi.shape[1], \
views_in_block.size),dtype=u.phi.dtype);
for v in xrange(views_in_block.size):
for v in range(views_in_block.size):
view = views_in_block[v];
#self.subsubproblem_config['positions'] = \
# self.positions[[view],:];
......@@ -1292,7 +1292,7 @@ class Blocking_meta(Algorithm):
subsub_u_final.probe.copy());
elif within_blocks_scheme == 'parallel':
views_in_block = numpy.arange(N_pie)[B];
views = xrange(views_in_block.size);
views = range(views_in_block.size);
arg = [(self, u, views_in_block[v], tol) for v in views];
results = self.pool.map(_unwrap_do_view, arg);
......@@ -1334,7 +1334,7 @@ class Blocking_meta(Algorithm):
if between_blocks_scheme == 'sequential':
in_block = self.in_block;
for b in xrange(num_blocks):
for b in range(num_blocks):
B = (in_block == b);
result = self._do_block(tmp_u, b, tol);
tmp_u.phi[:,:,B] = result[0][:,:,B];
......@@ -1342,13 +1342,13 @@ class Blocking_meta(Algorithm):
tmp_u.probe = result[2];
self.block_iters[b] = result[3];
elif between_blocks_scheme == 'parallel':
arg = [(self,tmp_u,b,tol) for b in xrange(num_blocks)];
arg = [(self,tmp_u,b,tol) for b in range(num_blocks)];
results = self.pool.map(_unwrap_do_block, arg);
tmp_u.phi = sum([t[0] for t in results]);
tmp_u.obj = sum([t[1] for t in results]) / num_blocks;
tmp_u.probe = sum([t[2] for t in results]) / num_blocks;
for b in xrange(num_blocks):
for b in range(num_blocks):
self.block_iters[b] = results[b][3];
else:
raise NotImplementedError,'NYI';
......@@ -1740,13 +1740,13 @@ class Ptychography(Problem):
Cx = (Nx_l//2)+1; Cy = (Ny_l//2)+1;
im_l = numpy.zeros(Ny_l,Nx_l);
for i in xrange(Cy-(Ny//2)-1):
for i in range(Cy-(Ny//2)-1):
im_l[i,Cx-(Nx//2)-1:Cx+math.ceil(Nx/2.0)-1] = im[0,:];
for i in xrange(Cy+math.ceil(Ny/2.0)-1,Ny_l):
for i in range(Cy+math.ceil(Ny/2.0)-1,Ny_l):
im_l[i,Cx-(Nx//2)-1:Cx+math.ceil(Nx/2.0)-1] = im[-1,:];
for i in xrange(Cx-(Nx//2)-1):
for i in range(Cx-(Nx//2)-1):
im_l[Cy-(Ny//2)-1:Cy+math.ceil(Ny/2.0)-1,i] = im[:,0];
for i in xrange(Cx+math.ceil(Nx/2.0)-1,Nx_l):
for i in range(Cx+math.ceil(Nx/2.0)-1,Nx_l):
im_l[Cy-(Ny//2)-1:Cy+math.ceil(Ny/2.0)-1,i] = im[:,-1];
im_l[0:Cy-(Ny//2)-1,0:Cx-(Nx//2)-1] = im[0,0];
im_l[0:Cy-(Ny//2)-1,Cx+math.ceil(Nx/2.0)-1:] = im[0,-1];
......@@ -1852,7 +1852,7 @@ class Ptychography(Problem):
positions = numpy.empty((nx*ny,2));
n_fast = numpy.arange(nx);
ind = 0;
for n_slow in xrange(ny):
for n_slow in range(ny):
ind = n_slow*ny;
positions[ind:ind+nx,0] = (pie_step_y/d1y) * n_slow;
positions[ind:ind+nx,1] = (pie_step_x/d1x) * n_fast;
......@@ -1893,8 +1893,8 @@ class Ptychography(Problem):
# Generate the data
ind = 0;
for akk in xrange(ny):
for bkk in xrange(nx):
for akk in range(ny):
for bkk in range(nx):
indy = rangeNy + positions[ind,0];
indx = rangeNx + positions[ind,1];
# Extract roi from sample plane
......@@ -1936,11 +1936,11 @@ class Ptychography(Problem):
probe_support = (numpy.real(numpy.conj(probe) * probe) > 0.01).astype(numpy.float);
shifted_probe_supports = numpy.zeros(sample_plane.shape+tuple([N_pie]));
objectsupport = numpy.zeros_like(sample_plane);
for pos in xrange(N_pie):
for pos in range(N_pie):
indy = rangeNy + positions[pos,0];
indx = rangeNx + positions[pos,1];
for y in xrange(Ny):
for y in range(Ny):
shifted_probe_supports[indy[y],indx,pos] = probe_support[y,:];
objectsupport[indy[y],indx] += probe_support[y,:];
objectsupport = (objectsupport > 0.01).astype(objectsupport.dtype);
......@@ -1960,10 +1960,10 @@ class Ptychography(Problem):
the_max = numpy.amax(positions,axis=0)+1;
row_len = the_max[0] / rows;
col_len = the_max[1] / cols;
for p in xrange(N_pie):
for p in range(N_pie):
top_index = positions[p,:];
for r in xrange(rows):
for c in xrange(cols):
for r in range(rows):
for c in range(cols):
b = c + r*cols;
if placed[p] == False and \
top_index[0] >= round(r*row_len) and \
......@@ -2033,8 +2033,8 @@ class Ptychography(Problem):
fmask = self.config['fmask'];
# Removal of the residual noise in the data is done here
ind = 0;
for n_slow in xrange(ny):
for n_fast in xrange(nx):
for n_slow in range(ny):
for n_fast in range(nx):
# Check if semi-transparent central stop was used. Scale
# intensity accordingly.
if not bs_mask is None:
......@@ -2073,8 +2073,8 @@ class Ptychography(Problem):
radius = 13.0/256.0 * probe.shape[0];
x_c = probe.shape[0]/2;
y_c = probe.shape[1]/2;
for i in xrange(probe.shape[0]):
for j in xrange(probe.shape[1]):
for i in range(probe.shape[0]):
for j in range(probe.shape[1]):
if math.sqrt((i-x_c)**2 + (j-y_c)**2) < radius:
probe_guess[i,j] = guess_value;
elif probe_guess_type == 'robin_initial':
......@@ -2123,10 +2123,10 @@ class Ptychography(Problem):
else:
mask = ((numpy.abs(probe_guess)**2)>low).astype(object_support.dtype);
for pos in xrange(N_pie):
for pos in range(N_pie):
indy = rangeNy + positions[pos,0];
indx = rangeNx + positions[pos,1];
for y in xrange(Ny):
for y in range(Ny):
object_support[indy[y],indx] += mask[y,:];
object_support = (object_support > 0).astype(object_support.dtype);
......@@ -2139,7 +2139,7 @@ class Ptychography(Problem):
# Generate initial guess for exit wave functions
phi = numpy.ones((Nx,Ny,N_pie),dtype=probe_guess.dtype);
for pos in xrange(N_pie):
for pos in range(N_pie):
indy = rangeNy + positions[pos,0];
indx = rangeNx + positions[pos,1];
phi[:,:,pos] = probe_guess * object_guess[indy,:][:,indx];
......@@ -2241,10 +2241,10 @@ class Ptychography(Problem):
pyplot.ylabel('Objective function value');
meas = numpy.zeros(sample_plane.shape);
for pos in xrange(N_pie):
for pos in range(N_pie):
indy = rangeNy + positions[pos,0];
indx = rangeNx + positions[pos,1];
for y in xrange(Ny):
for y in range(Ny):
meas[indy[y],indx] += probe_mask[y,:];
pyplot.figure('Number of measurements, pixelwise');
pyplot.imshow(meas);
......
......@@ -40,8 +40,8 @@ class ProjGiven(ProxOperator):
A = numpy.zeros((9,9,9),dtype=u.dtype);
given = self.given;
for x in xrange(9):
for y in xrange(9):
for x in range(9):
for y in range(9):
z = given[x,y];
if z > 0:
A[x,y,z-1] = 1;
......@@ -70,9 +70,9 @@ class ProjSquare(ProxOperator):
def work(self,u):
Q = numpy.zeros((9,9,9),dtype=u.dtype);
for z in xrange(9):
for x in xrange(0,9,3):
for y in xrange(0,9,3):
for z in range(9):
for x in range(0,9,3):
for y in range(0,9,3):
v = numpy.argmax(u[x:(x+3),y:(y+3),z],axis=0);
w = numpy.argmax(numpy.amax(u[x:(x+3),y:(y+3),z],axis=0));
......@@ -99,8 +99,8 @@ class ProjColumn(ProxOperator):
def work(self,u):
C = numpy.zeros((9,9,9),dtype=u.dtype);
for x in xrange(9):
for z in xrange(9):
for x in range(9):
for z in range(9):
y = numpy.argmax(u[x,:,z]);
C[x,y,z] = 1;
return C;
......@@ -126,8 +126,8 @@ class ProjRow(ProxOperator):
def work(self,u):
R = numpy.zeros((9,9,9),dtype=u.dtype);
for y in xrange(9):
for z in xrange(9):
for y in range(9):
for z in range(9):
x = numpy.argmax(u[:,y,z]);
R[x,y,z] = 1;
return R;
......@@ -189,8 +189,8 @@ class Sudoku(Problem):
u = numpy.zeros((9,9,9,4),dtype=sudoku.dtype);
for x in xrange(9):
for y in xrange(9):
for x in range(9):
for y in range(9):
z = sudoku[x,y]-1;
if z >= 0:
u[x,y,z,:] = 1;
......@@ -207,9 +207,9 @@ class Sudoku(Problem):
solution = numpy.zeros_like(self.sudoku);
A = self.u1[:,:,:,0];
for x in xrange(9):
for y in xrange(9):
for z in xrange(9):
for x in range(9):
for y in range(9):
for z in range(9):
if A[x,y,z] > 0:
solution[x,y] = z+1;
break;
......
......@@ -75,12 +75,12 @@ class AP(Algorithm):
tmp_change = (norm(u-tmp_u,'fro')/normM)**2;
tmp_gap = (norm(tmp1-tmp_u,'fro')/normM)**2;
elif self.Nz == 1:
for j in xrange(self.dim):
for j in range(self.dim):
tmp_change += (norm(u[:,:,j]-tmp_u[:,:,j],'fro')/normM)**2;
tmp_gap += (norm(tmp1[:,:,j]-tmp_u[:,:,j])/normM,'fro')**2;
else:
for j in xrange(self.dim):
for k in xrange(self.Nz):
for j in range(self.dim):
for k in range(self.Nz):
tmp_change += (norm(u[:,:,k,j]-tmp_u[:,:,k,j],'fro')/normM)**2;
tmp_gap += (norm(tmp1[:,:,k,j]-tmp_u[:,:,k,j],'fro')/normM)**2;
change[iters] = sqrt(tmp_change);
......
......@@ -96,12 +96,12 @@ class HPR(Algorithm):
tmp_change = (norm(u-tmp_u,'fro')/normM)**2;
tmp_gap = (norm(tmp3-tmp2,'fro')/normM)**2;
elif self.Nz == 1:
for j in xrange(self.dim):
for j in range(self.dim):
tmp_change += (norm(u[:,:,j]-tmp_u[:,:,j],'fro')/normM)**2;
tmp_gap += (norm(tmp3[:,:,j]-tmp2[:,:,j])/normM,'fro')**2;
else:
for j in xrange(self.dim):
for k in xrange(self.Nz):