45 #include <mach/clock.h> 46 #include <mach/mach.h> 54 int N_,
double vtable_,
int ntable_)
55 : alpha(alpha_), v(v_), r(r_), N(N_),
K(K_), vtable(vtable_),
74 double absx = fabs(x);
87 fltb = double(ltab)/(
K/2);
92 for (
int i=0;
i <= ltab;
i++)
94 double s = double(
i)/
fltb/
N;
111 double maxdiff = 0.f;
124 double val0 = sinh(
fac)/
fac;
125 double absx = fabs(x);
138 double facrt =
fac*rt;
139 double res = (sinh(facrt)/facrt)/val0;
145 double facrt =
fac*rt;
146 double res = (sin(facrt)/facrt)/val0;
169 double d = b * b - 4 * a *
c;
174 x1 = (-b +
sqrt(d)) / (2 * a);
175 x2 = (-b -
sqrt(d)) / (2 * a);
184 return 1 /
sqrt(2*
PI*sigma*sigma)*exp(-0.5*((x / sigma)*(x / sigma)));
192 norm /=
sqrt(df*
PI*sigma*sigma);
193 return norm * pow((1 + (x/sigma)*(x/sigma)/df),-((df+1.)/2.));
198 double ang,
double muX,
double muY)
203 double xp = cos(ang) * x + sin(ang) *
y;
204 double yp = -sin(ang) * x + cos(ang) *
y;
207 return 1 /
sqrt(2*
PI*sigmaX*sigmaY)*exp(-0.5*((xp / sigmaX)*(xp / sigmaX) +
208 (yp / sigmaY)*(yp / sigmaY)));
216 2.515517, 0.802853, 0.010328
220 1.432788, 0.189269, 0.001308
226 double z=t - ((c[2]*t + c[1])*t + c[0]) /
227 (((d[2]*t + d[1])*t + d[0])*t + 1.0);
234 double z=t - ((c[2]*t + c[1])*t + c[0]) /
235 (((d[2]*t + d[1])*t + d[0])*t + 1.0);
243 return 0.5 * (1. + erf(x/
sqrt(2.)));
309 result = 0.5*
betai(0.5*rk, 0.5, z);
331 while ( j <= k-2 && tz/f > EPS )
333 tz = tz*((j-1)/(z*j));
346 while ( j<= k-2 && tz/f > EPS)
348 tz = tz*((j-1)/(z*j));
366 return betai(0.5*d1,0.5*d2,(d1*x)/(d1*x+d2));
386 while (fabs(pm-p)/p>0.001);
402 for (
int i = 0;
i < seed;
i++)
409 static unsigned int seed;
411 struct timespec highresTime;
413 #ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time 417 host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
418 clock_get_time(cclock, &mts);
419 mach_port_deallocate(mach_task_self(), cclock);
420 highresTime.tv_sec = mts.tv_sec;
421 highresTime.tv_nsec = mts.tv_nsec;
424 clock_gettime(CLOCK_REALTIME, &highresTime);
427 srand(rand()+clock()+time(NULL)+highresTime.tv_nsec);
428 rand_return = rand();
433 idum = (-(int)(t % 10000)
434 - (int)(rand_return % 10000));
436 seed = (
unsigned int)rand_return;
479 double z0 = (x0 - mean) / stddev;
480 return erf(
ABS(z0) /
sqrt(2.0));
485 double z0 = (x0 - mean) / stddev;
486 return erfc(
ABS(z0) /
sqrt(2.0));
512 double pm, x1, x2, xm;
514 x2 = mean + 5 * stddev;
524 while (
ABS(pm - p) / p > 0.005);
531 return 1 -
betai(degrees_of_freedom / 2, 0.5,
532 degrees_of_freedom / (degrees_of_freedom + t0*t0));
556 double pm, t1, t2, tm;
568 while (fabs(pm - p) / p > 0.005);
574 return gammp(degrees_of_freedom / 2, t0 / 2);
608 #if defined __MINGW32__ || defined __APPLE__ 609 struct tm* localtime_r (
const time_t *clock,
struct tm *result)
611 if (!clock || !result)
613 memcpy(result,localtime(clock),
sizeof(*result));
616 void sin_cos(
double angle,
double * sine,
double * cosine)
619 *cosine = cos(angle);
638 #if !defined _NO_TIME && !defined __MINGW32__ 649 gettimeofday(&tv, NULL);
651 localtime_r(&tv.tv_sec,&tm);
652 *time = tm.tm_hour * 3600 * 1000 + tm.tm_min * 60 * 1000 + tm.tm_sec * 1000 +
656 #if !defined _NO_TIME && !defined __MINGW32__ 662 (*dest).tms_utime += (*dest).tms_utime + (now.tms_utime - (*orig).tms_utime);
663 (*dest).tms_stime += (*dest).tms_stime + (now.tms_utime - (*orig).tms_utime);
667 #if !defined _NO_TIME && !defined __MINGW32__ 673 double userTime = now.tms_utime - time.tms_utime;
674 double sysTime = now.tms_stime - time.tms_stime;
680 std::cout <<
"Elapsed time: User(" << userTime <<
") System(" << sysTime
688 gettimeofday(&tv, NULL);
690 localtime_r(&tv.tv_sec,&tm);
691 TimeStamp now = tm.tm_hour * 3600 * 1000 + tm.tm_min * 60 * 1000 + tm.tm_sec * 1000 +
695 std::cout <<
"Elapsed time: ";
697 std::cout << diff/1000.0 <<
" secs." << std::endl;
699 std::cout << diff <<
" msecs." << std::endl;
704 gettimeofday(&tv, NULL);
705 localtime_r(&tv.tv_sec,&tm);
706 return tm.tm_hour * 3600 * 1000 + tm.tm_min * 60 * 1000 + tm.tm_sec * 1000 +
718 size_t diff = elapsed();
722 std::cout <<
"Elapsed time: ";
725 std::cout << diff/1000.0 <<
" secs." << std::endl;
727 std::cout << diff <<
" msecs." << std::endl;
734 return now() - tic_time;
741 #if !defined _NO_TIME && !defined __MINGW32__ 744 double userTime = now.tms_utime - time.tms_utime;
745 double sysTime = now.tms_stime - time.tms_stime;
751 return userTime + sysTime;
755 #if !defined _NO_TIME && !defined __MINGW32__ 761 double totalTime = (now.tms_utime - time.tms_utime +
763 return totalTime*(1 - fraction_done) / fraction_done;
773 if (time(&seconds) < 0)
775 T = localtime(&seconds);
777 printf(
"%2d:%2d:%2d (day=%2d) =>%s ", T->tm_hour,
778 T->tm_min, T->tm_sec, T->tm_mday, message.c_str());
793 static time_t startt;
798 double h1, h2, m1, m2;
799 bool queue = (getenv(
"XMIPP_IN_QUEUE") != NULL);
809 fprintf(stdout,
"0000/???? sec. ");
811 for (i = 0; i < 10; i++)
818 t2 = (long)(t1 * (
double)totlen / rlen);
824 m1 = (double)t1 / 60.0;
825 m2 = (double)t2 / 60.0;
829 h1 = (double)m1 / 60.0;
830 h2 = (double)m2 / 60.0;
839 fprintf(stdout,
"\r%3.2f/%3.2f %s ", h1, h2,
"hours");
841 fprintf(stdout,
"\r%3.2f/%3.2f %s ", m1, m2,
"min");
843 fprintf(stdout,
"\r%4u/%4u %4s ", (
int)t1, (
int)t2,
"sec.");
847 i = (int)(60 * (1 - (
double)(totlen - rlen) / totlen));
865 char * str = ctime (&rawtime);
866 char * pos = strrchr(str,
'\n');
894 fprintf(stderr,
"%s", _rsOp.c_str());
902 size_t xmippFREAD(
void *dest,
size_t size,
size_t nitems, FILE * &fp,
bool reverse)
906 retval = fread(dest, size, nitems, fp);
909 char *ptr = (
char *)dest;
912 for (
size_t n = 0;
n < nitems;
n++)
914 char * ptrp = ptr + size - 1;
915 for (
size_t i = 0;
i < size; ++
i, --ptrp)
917 if (fread(ptrp, 1, 1, fp) != 1)
930 if (retval != nitems)
937 size_t xmippFWRITE(
const void *src,
size_t size,
size_t nitems, FILE * &fp,
942 retval = fwrite(src, size, nitems, fp);
945 char *ptr = (
char *)src;
948 for (
size_t n = 0;
n < nitems;
n++)
950 char * ptrp = ptr + size - 1;
951 for (
size_t i = 0;
i < size; ++
i, --ptrp)
953 if (fwrite(ptrp, 1, 1, fp) != 1)
970 void mapFile(
const FileName &filename,
char*&map,
size_t &size,
int &fileDescriptor,
bool readOnly)
974 struct stat file_status;
975 if(stat(filename.c_str(), &file_status) != 0)
977 size = file_status.st_size;
980 struct stat file_status;
981 if(stat(filename.c_str(), &file_status) != 0)
983 size = file_status.st_size;
988 fileDescriptor = open(filename.c_str(), O_RDONLY, S_IREAD);
990 fileDescriptor = open(filename.c_str(), O_RDWR, S_IREAD | S_IWRITE);
991 if (fileDescriptor == -1)
995 map = (
char *) mmap(0, size, PROT_READ, MAP_SHARED, fileDescriptor, 0);
997 map = (
char *) mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileDescriptor, 0);
998 if (map == MAP_FAILED)
1002 map =
new char[size];
1003 fileDescriptor = open(filename.data(), O_RDONLY);
1004 if (fileDescriptor == -1)
1006 int ok=
read(fileDescriptor,map,size);
1013 void unmapFile(
char *&map,
size_t &size,
int& fileDescriptor)
1016 if (munmap(map, size) == -1)
1024 close(fileDescriptor);
1034 std::swap(b[i], b[j]);
1042 char t, t0, t1, t2, t3;
1075 for (
size_t i=0;
i<n/2;
i++ )
1087 static const unsigned long ul = 0x00000001;
1088 return ((
int)(*((
unsigned char *) &ul)))!=0;
1094 static const unsigned long ul = 0x01000000;
1095 return ((
int)(*((
unsigned char *) &ul)))!=0;
1107 using std::ios_base;
1108 using std::ifstream;
1120 string pid, comm, state, ppid, pgrp, session, tty_nr;
1121 string tpgid, flags, minflt, cminflt, majflt, cmajflt;
1122 string utime, stime, cutime, cstime, priority, nice;
1123 string O, itrealvalue, starttime;
1127 unsigned long vsize;
1130 stat_stream >> pid >> comm >> state >> ppid >> pgrp >> session >> tty_nr
1131 >> tpgid >> flags >> minflt >> cminflt >> majflt >> cmajflt
1132 >> utime >> stime >> cutime >> cstime >> priority >> nice
1133 >> O >> itrealvalue >> starttime >> vsize >> rss;
1135 stat_stream.close();
1137 long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024;
1138 vm_usage = vsize / 1024.0;
1139 resident_set = rss * page_size_kb;
1144 double virtualMemory, residentMemory;
1146 std::cout <<
"VM: " << virtualMemory <<
"kB ; RSS: " << residentMemory <<
" kB" << std::endl;
1152 size_t jobs_per_worker = N / size;
1153 size_t jobs_resting = N % size;
1155 if (rank < jobs_resting)
1157 first = rank * (jobs_per_worker + 1);
1158 last = first + jobs_per_worker;
1162 first = rank * jobs_per_worker + jobs_resting;
1163 last = first + jobs_per_worker - 1;
1166 return last - first + 1;
1172 for (
size_t rank = 0; rank < size; rank++)
1175 if (myself >= first && myself <= last)
1187 size_t size1=-1, size2=-1;
1188 mapFile(fn1,map1,size1,fd1,
true);
1189 mapFile(fn2,map2,size2,fd2,
true);
1190 int result=memcmp(map1+offset,map2+offset,size1-offset);
double cdf_gauss(double x)
void init_progress_bar(long total)
void TimeMessage(const std::string &message)
void min(Image< double > &op1, const Image< double > &op2)
double student_outside_probb(double p, double degrees_of_freedom)
double betai(double a, double b, double x)
double student_within_t0(double t0, double degrees_of_freedom)
double gaus_up_to_x0(double x0, double mean, double stddev)
double cdf_tstudent(int k, double t)
double rnd_student_t(double nu)
bool IsLittleEndian(void)
#define REPORT_ERROR(nerr, ErrormMsg)
void swapbytes(char *v, unsigned long n)
char * getCurrentTimeString()
int solve_2nd_degree_eq(double a, double b, double c, double &x1, double &x2, double prec)
void sqrt(Image< double > &op)
void annotate_processor_time(ProcessorTimeStamp *time)
double gaus_outside_probb(double p, double mean, double stddev)
size_t divide_equally(size_t N, size_t size, size_t rank, size_t &first, size_t &last)
double sinhwin(double x) const
double icdf_gauss(double p)
void processMemUsage(double &vm_usage, double &resident_set)
double elapsed_time(ProcessorTimeStamp &time, bool _IN_SECS)
double time_to_go(ProcessorTimeStamp &time, double fraction_done)
Memory has not been deallocated.
T norm(const std::vector< T > &v)
double cdf_FSnedecor(int d1, int d2, double x)
double student_up_to_t0(double t0, double degrees_of_freedom)
void ByteSwap(unsigned char *b, int n)
Bad amount of memory requested.
void init_random_generator(int seed)
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
double chi2_from_t0(double t0, double degrees_of_freedom)
size_t divide_equally_group(size_t N, size_t size, size_t myself)
double student_from_t0(double t0, double degrees_of_freedom)
double gaussian2D(double x, double y, double sigmaX, double sigmaY, double ang, double muX, double muY)
__device__ float bessi0(float x)
double rnd_log(double a, double b)
void unmapFile(char *&map, size_t &size, int &fileDescriptor)
void log(Image< double > &op)
virtual void OnProgress(unsigned long _it)
double student_outside_t0(double t0, double degrees_of_freedom)
struct tms ProcessorTimeStamp
void progress_bar(long rlen)
bool compareTwoFiles(const FileName &fn1, const FileName &fn2, size_t offset)
binary comparison of two files skipping first "offset" bytes
double chi2_up_to_t0(double t0, double degrees_of_freedom)
double icdf_FSnedecor(int d1, int d2, double p)
size_t toc(const char *msg=NULL, bool inSecs=true)
double gaus_within_x0(double x0, double mean, double stddev)
void print_elapsed_time(ProcessorTimeStamp &time, bool _IN_SECS)
Couldn't read from file.
double gammp(double a, double x)
double tstudent1D(double x, double df, double sigma, double mu)
size_t xmippFWRITE(const void *src, size_t size, size_t nitems, FILE *&fp, bool reverse)
size_t xmippFREAD(void *dest, size_t size, size_t nitems, FILE *&fp, bool reverse)
virtual void OnInitOperation(unsigned long _est_it)
void mapFile(const FileName &filename, char *&map, size_t &size, int &fileDescriptor, bool readOnly)
double tdev(double nu, int *idum)
constexpr long double EPS
double i0win(double x) const
KaiserBessel(double alpha_, int K, double r_, double v_, int N_, double vtable_=0., int ntable_=5999)
fprintf(glob_prnt.io, "\)
virtual void OnReportOperation(const std::string &_rsOp)
Environment PATH cannot be read.
double I0table_maxerror()
std::vector< double > i0table
void annotate_time(TimeStamp *time)
unsigned int randomize_random_generator()
file read(std::istream &is)
double gaus_outside_x0(double x0, double mean, double stddev)
void acum_time(ProcessorTimeStamp *orig, ProcessorTimeStamp *dest)
double gaus_from_x0(double x0, double mean, double stddev)
double gaussian1D(double x, double sigma, double mu)