double __hypot (double x, double y) { double z = __ieee754_hypot(x,y); if(__builtin_expect(!__finite(z), 0) && __finite(x) && __finite(y) && _LIB_VERSION != _IEEE_) return __kernel_standard(x, y, 4); /* hypot overflow */ return z; }
double __exp2 (double x) { double z = __ieee754_exp2 (x); if (__builtin_expect (!__finite (z), 0) && __finite (x) && _LIB_VERSION != _IEEE_) /* exp2 overflow: 44, exp2 underflow: 45 */ return __kernel_standard (x, x, 44 + !!__signbit (x)); return z; }
double __exp10 (double x) { double z = __ieee754_exp10 (x); if (__builtin_expect (!__finite (z), 0) && __finite (x) && _LIB_VERSION != _IEEE_) /* exp10 overflow (46) if x > 0, underflow (47) if x < 0. */ return __kernel_standard (x, x, 46 + !!__signbit (x)); return z; }
double __lgamma_r(double x, int *signgamp) { double y = __ieee754_lgamma_r(x,signgamp); if(__builtin_expect(!__finite(y), 0) && __finite(x) && _LIB_VERSION != _IEEE_) return __kernel_standard(x, x, __floor(x)==x&&x<=0.0 ? 15 /* lgamma pole */ : 14); /* lgamma overflow */ return y; }
/* wrapper pow */ double __pow (double x, double y) { double z = __ieee754_pow (x, y); if (__builtin_expect (!__finite (z), 0)) { if (_LIB_VERSION != _IEEE_) { if (__isnan (x)) { if (y == 0.0) /* pow(NaN,0.0) */ return __kernel_standard (x, y, 42); } else if (__finite (x) && __finite (y)) { if (__isnan (z)) /* pow neg**non-int */ return __kernel_standard (x, y, 24); else if (x == 0.0 && y < 0.0) { if (signbit (x) && signbit (z)) /* pow(-0.0,negative) */ return __kernel_standard (x, y, 23); else /* pow(+0.0,negative) */ return __kernel_standard (x, y, 43); } else /* pow overflow */ return __kernel_standard (x, y, 21); } } } else if (__builtin_expect (z == 0.0, 0) && __finite (x) && __finite (y) && _LIB_VERSION != _IEEE_) { if (x == 0.0) { if (y == 0.0) /* pow(0.0,0.0) */ return __kernel_standard (x, y, 20); } else /* pow underflow */ return __kernel_standard (x, y, 22); } return z; }
double __lgamma(double x) { int local_signgam = 0; double y = __ieee754_lgamma_r(x, _LIB_VERSION != _ISOC_ /* ISO C99 does not define the global variable. */ ? &signgam : &local_signgam); if(__builtin_expect(!__finite(y), 0) && __finite(x) && _LIB_VERSION != _IEEE_) return __kernel_standard(x, x, __floor(x)==x&&x<=0.0 ? 15 /* lgamma pole */ : 14); /* lgamma overflow */ return y; }
double __ieee754_exp10 (double arg) { if (__finite (arg) && arg < DBL_MIN_10_EXP - DBL_DIG - 10) return DBL_MIN * DBL_MIN; else /* This is a very stupid and inprecise implementation. It'll get replaced sometime (soon?). */ return __ieee754_exp (M_LN10 * arg); }
double __ieee754_exp10 (double arg) { int32_t lx; double arg_high, arg_low; double exp_high, exp_low; if (!__finite (arg)) return __ieee754_exp (arg); if (arg < DBL_MIN_10_EXP - DBL_DIG - 10) return DBL_MIN * DBL_MIN; else if (arg > DBL_MAX_10_EXP + 1) return DBL_MAX * DBL_MAX; GET_LOW_WORD (lx, arg); lx &= 0xf8000000; arg_high = arg; SET_LOW_WORD (arg_high, lx); arg_low = arg - arg_high; exp_high = arg_high * log10_high; exp_low = arg_high * log10_low + arg_low * M_LN10; return __ieee754_exp (exp_high) * __ieee754_exp (exp_low); }
/** Qnormalisation Method: function that implements the ben Bolstad Method quantile Normalization of High density Oliglonucleotide Array Data @input : data matrix (each column is an experiment, each row a gene or data) @output: data matrix with the results @nrows: number of genes or rows in the matrix @ncolumns: number of experiments in the matrix @returns >0 if everything was fine <0 if there was an error **/ int Qnormalization(double **input, double **output, int nrows, int ncolumns) { int i,j,k,n; double average; double** ordered; int** indexes; //initialize auxiliar array to not modify the input array ordered=(double **)malloc(nrows*sizeof(double*)); for (i=0; i<nrows;i++){ ordered[i]=(double *)malloc(ncolumns*(sizeof(double))); } //auxiliar array to store the indexes indexes=(int **)malloc(nrows*sizeof(int*)); for (i=0; i<nrows;i++){ indexes[i]=(int *)malloc(ncolumns*(sizeof(int))); } //copy the values for (i=0; i<nrows;i++){ for (j=0; j<ncolumns;j++){ ordered[i][j]=input[i][j]; //UNIFY NAN CONSTANT if ((!__finite(input[i][j]))||(__isnan(input[i][j]))) ordered[i][j]=HUGE_VAL; } } //initialize the indexes array for (i=0; i<nrows;i++){ for (j=0; j<ncolumns;j++){ indexes[i][j]=j; } } //order each data column for (i=0; i<nrows; i++){ //Quicksort QsortC(ordered[i],0,ncolumns-1,indexes[i]); // bubbleSort(ordered[i], ncolumns, indexes[i]); } //APPLY QNORMALISATION //Take the means across rows of Xsort and assign this mean to each element in the row to get X0sort //. Get Xnormalized by rearranging each column of X0 sort to have the same ordering as original X //calculate the average of each j elem for (j=0; j<ncolumns; j++){ average=HUGE_VAL; n=0; for (i=0; i<nrows;i++){ if ((__finite(ordered[i][j]))&&(!__isnan(ordered[i][j]))){ if ((!__finite(average))||(__isnan(average))){ average=0; } average+=ordered[i][j]; n++; } } if ((__finite(average))&&(!__isnan(average))){ average/=n; } for (i=0; i<nrows;i++){ if ((__finite(ordered[i][j]))&&(!__isnan(ordered[i][j]))) ordered[i][j]=average; } } //reorder each data column for (i=0; i<nrows;i++){ for (j=0; j<ncolumns;j++){ k=indexes[i][j]; output[i][k]=ordered[i][j]; } } return 1; }
Err mathlib_finite(UInt16 refnum, double x, Int16 *result) { #pragma unused(refnum) *result = __finite(x); return mlErrNone; }
int parse_args(int argc, char **argv, simengine_opts *opts){ int arg; int option_index = 0; memset(opts, 0, sizeof(simengine_opts)); while(1){ arg = getopt_long(argc, argv, "", long_options, &option_index); if(-1 == arg) break; switch(arg){ case HELP: print_usage(); return 1; break; case START: if(opts->start_time){ printf("ERROR: start time was already set.\n"); return 1; } opts->start_time = atof(optarg); if(!__finite(opts->start_time)){ printf("Error: start time is invalid %f.\n", opts->start_time); return 1; } //printf("Start %s -> %f\n", optarg, opts->start_time); break; case STOP: if(opts->stop_time){ printf("ERROR: stop time was already set.\n"); return 1; } opts->stop_time = atof(optarg); if(!__finite(opts->stop_time)){ printf("Error: start time is invalid %f.\n", opts->stop_time); return 1; } //printf("Stop %s -> %f\n", optarg, opts->stop_time); break; case MODELS: if(opts->num_models){ printf("ERROR: number of models was already set.\n"); return 1; } opts->num_models = atoi(optarg); if(opts->num_models < 1){ printf("ERROR: invalud number of models %d\n", opts->num_models); return 1; } //printf("Number of models %d\n", opts->num_models); break; case INPUT_FILE: opts->inputs_filename = optarg; opts->inputs = fopen(opts->inputs_filename, "r"); if(!opts->inputs){ printf("ERROR: Could not open input file '%s'.\n", opts->inputs_filename); return 1; } break; case STATE_INIT_FILE: opts->states_filename = optarg; opts->states = fopen(opts->states_filename, "r"); if(!opts->states){ printf("ERROR: Could not open state initial value file '%s'.\n", opts->states_filename); return 1; } break; case OUTPUT_FILE: opts->outputs_filename = optarg; opts->outputs = fopen(opts->outputs_filename, "w"); if(!opts->outputs){ printf("ERROR: Could not open output file '%s'.\n", opts->outputs_filename); return 1; } break; case CPU: if(opts->target){ printf("ERROR: target already set\n"); return 1; } opts->target = "CPU"; //printf("Target CPU\n"); break; case OPENMP: if(opts->target){ printf("ERROR: target already set\n"); return 1; } opts->target = "OPENMP"; //printf("Target Parallel CPU\n"); break; case GPU: if(opts->target){ printf("ERROR: target already set\n"); return 1; } opts->target = "GPU"; //printf("Target GPU\n"); break; case FLOAT: if(opts->precision){ printf("ERROR: precision already set\n"); return 1; } opts->precision = "float"; //printf("Single precision\n"); break; case DOUBLE: if(opts->precision){ printf("ERROR: precision already set\n"); return 1; } opts->precision = "double"; //printf("Double precision\n"); break; case DEBUG: opts->debug = 1; printf("Debugging enabled\n"); break; case EMULATE: opts->emulate = 1; printf("Emulation enabled\n"); break; case PROFILE: opts->profile = 1; printf("Profiling enabled\n"); break; case REMAKE: opts->remake = 1; printf("Skipping simEngine compilation and only recompiling C code.\n"); break; case NOCOMPILE: opts->nocompile = 1; printf("Skipping all compilation and executing simulation.\n"); break; default: printf("ERROR: invalid argument %s\n", argv[optind]); return 1; } } if(optind+1 < argc){ printf("Error: too many models passed to simex\n"); while(optind < argc) printf("\t%s\n", argv[optind++]); return 1; } if(optind == argc){ printf("Error: no model passed to simex\n"); return 1; } opts->model_file = argv[optind]; opts->model_name = get_model_name(opts->model_file); //printf("DSL model file '%s'.\n", opts->model_file); if(opts->stop_time < opts->start_time){ printf("ERROR: stop time (%f) must be greater than start time (%f)\n", opts->stop_time, opts->start_time); return 1; } // Set defaults for any unset options if(!opts->target){ opts->target = "CPU"; } if(!opts->num_models){ opts->num_models = 1; } if(!opts->precision){ opts->precision = "double"; } if(!opts->outputs){ opts->outputs = stdout; } return 0; }
__MATH_FUNCTIONS_DBL_PTX3_DECL__ int __finitel(/* we do not support long double yet, hence double */double a) { return __finite((double)a); }