/* $Id: shoot_optim3d.c 4875 2012-08-30 20:04:30Z john $ */ /* (c) John Ashburner (2011) */ #include #include extern double log(double x); #include "shoot_optim3d.h" #include "shoot_multiscale.h" #include "shoot_regularisers.h" static double dotprod(mwSize m, float a[], float b[]) { mwSize i; double dp = 0.0; for(i=0; i tol*norm(b), p = r + beta*p; Ap = A*p; alpha = rtr/(p'*Ap); x = x + alpha*p; r = r - alpha*Ap; rtrold = rtr; rtr = r'*r; beta = rtr/rtrold; it = it+1; if it>nit, break; end; end; */ void cgs3(mwSize dm[], float A[], float b[], double param[], double tol, int nit, float x[], float r[], float p[], float Ap[]) { mwSize i, m = dm[0]*dm[1]*dm[2]*3, it; double rtr, nb, rtrold, alpha, beta; /* printf("\n **** %dx%d ****\n",dm[0],dm[1]); */ nb = tol*norm(m,b); # ifdef NEVER /* Assuming starting estimates of zeros */ /* x = zeros(size(b)); */ for(i=0; i=0; j--) { mwSignedIndex jc; prolong(n[j+1],u[j+1],n[j],u[j],rbuf); if(j>0) copy(3*m[j],bo[j],b[j]); for(jc=0; jc=j; jj--) /* From lowest res to high res */ { prolong(n[jj+1],u[jj+1],n[jj],res,rbuf); addto(3*m[jj], u[jj], res); relax(n[jj], a[jj], b[jj], param[jj], nit, u[jj]); } } } } else /* Use starting estimate and just run some V-cycles */ { mwSignedIndex jc; /* for(j=1; j=0; jj--) /* From lowest res to highest res */ { prolong(n[jj+1],u[jj+1],n[jj],res,rbuf); addto(3*m[jj], u[jj], res); relax(n[jj], a[jj], b[jj], param[jj], nit, u[jj]); } } } }