void input_errors(int nptrs, char **ptrs) { int i; for (i = 0; i < nptrs - 1; i++) { save_text(ptrs[i]); save_text(","); } save_text(ptrs[i]); save_text("\n"); }
static gboolean delete_event ( GtkWidget *widget, GdkEvent *event, gpointer data ) { save_text(); return FALSE; }
static inline void save_char(int c) { static char text[2]; if (c == 0) c = 0200; text[0] = c; save_text(text); }
static gboolean focus_out_event( GtkWidget *widget, GdkEventButton *event, GtkWidget *window ) { save_text(); gtk_widget_destroy(window); return FALSE; }
ProfileDataInfoDialog::ProfileDataInfoDialog(const QStringList& text, const QString& pattern, const QString& suffix, QWidget *parent) : QDialog(parent) { Q_UNUSED(parent); this->text = text; this->pattern = pattern; this->suffix = suffix; setWindowTitle(i18n("Info Settings")); QVBoxLayout *mainLayout = new QVBoxLayout; setLayout(mainLayout); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::Apply); QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); applyButton = buttonBox->button(QDialogButtonBox::Apply); connect(buttonBox, &QDialogButtonBox::accepted, this, &ProfileDataInfoDialog::slotAccepted); connect(buttonBox, &QDialogButtonBox::rejected, this, &ProfileDataInfoDialog::reject); connect(applyButton, &QPushButton::clicked, this, &ProfileDataInfoDialog::slotApplied); QWidget *widget = new QWidget(this); mainLayout->addWidget(widget); mainLayout->addWidget(buttonBox); ui.setupUi(widget); connect(ui.kpushbutton_pattern, SIGNAL(clicked()), this, SLOT(pattern_wizard())); ui.kpushbutton_pattern->setIcon(QIcon::fromTheme("tools-wizard")); ui.ktextedit_text->setPlainText(text.join("\n")); connect(ui.ktextedit_text, SIGNAL(textChanged()), this, SLOT(trigger_changed())); ui.qlineedit_pattern->setText(pattern); connect(ui.qlineedit_pattern, SIGNAL(textEdited(const QString&)), this, SLOT(trigger_changed())); ui.qlineedit_suffix->setText(suffix); connect(ui.qlineedit_suffix, SIGNAL(textEdited(const QString&)), this, SLOT(trigger_changed())); ui.kpushbutton_load->setIcon(QIcon::fromTheme("document-open")); ui.kpushbutton_save->setIcon(QIcon::fromTheme("document-save")); connect(ui.kurllabel_aboutvariables, SIGNAL(leftClickedUrl()), this, SLOT(about_variables())); connect(ui.kpushbutton_load, SIGNAL(clicked()), this, SLOT(load_text())); connect(ui.kpushbutton_save, SIGNAL(clicked()), this, SLOT(save_text())); applyButton->setEnabled(false); }
bool mail_body::save_to(string& out) const { switch (mime_stype_) { case MIME_STYPE_HTML: return save_html(html_, hlen_, out); case MIME_STYPE_PLAIN: return save_text(text_, tlen_, out); case MIME_STYPE_ALTERNATIVE: return save_alternative(html_, hlen_, text_, tlen_, out); case MIME_STYPE_RELATED: acl_assert(attachments_); return save_relative(html_, hlen_, text_, tlen_, *attachments_, out); default: logger_error("unknown mime_stype: %d", mime_stype_); return false; } }
int main( int argc, char *argv[] ) { config conf; setup_config(&conf, argc, argv); init_progress(conf.progress_width, conf.nsteps, conf.progress_disabled); TYPE dx = 20.f; TYPE dt = 0.002f; // compute the pitch for perfect coalescing size_t dimx = conf.nx + 2*conf.radius; size_t dimy = conf.ny + 2*conf.radius; size_t nbytes = dimx * dimy * sizeof(TYPE); if (conf.verbose) { printf("x = %zu, y = %zu\n", dimx, dimy); printf("nsteps = %d\n", conf.nsteps); printf("radius = %d\n", conf.radius); } TYPE c_coeff[NUM_COEFF]; TYPE *curr = (TYPE *)malloc(nbytes); TYPE *next = (TYPE *)malloc(nbytes); TYPE *vsq = (TYPE *)malloc(nbytes); if (curr == NULL || next == NULL || vsq == NULL) { fprintf(stderr, "Allocations failed\n"); return 1; } config_sources(&conf.srcs, &conf.nsrcs, conf.nx, conf.ny, conf.nsteps); TYPE **srcs = sample_sources(conf.srcs, conf.nsrcs, conf.nsteps, dt); init_data(curr, next, vsq, c_coeff, dimx, dimy, dx, dt); double start = seconds(); for (int step = 0; step < conf.nsteps; step++) { for (int src = 0; src < conf.nsrcs; src++) { if (conf.srcs[src].t > step) continue; int src_offset = POINT_OFFSET(conf.srcs[src].x, conf.srcs[src].y, dimx, conf.radius); curr[src_offset] = srcs[src][step]; } fwd(next, curr, vsq, c_coeff, conf.nx, conf.ny, dimx, dimy, conf.radius); TYPE *tmp = next; next = curr; curr = tmp; update_progress(step + 1); } double elapsed_s = seconds() - start; finish_progress(); float point_rate = (float)conf.nx * conf.ny / (elapsed_s / conf.nsteps); fprintf(stderr, "iso_r4_2x: %8.10f s total, %8.10f s/step, %8.2f Mcells/s/step\n", elapsed_s, elapsed_s / conf.nsteps, point_rate / 1000000.f); if (conf.save_text) { save_text(curr, dimx, dimy, conf.ny, conf.nx, "snap.text", conf.radius); } free(curr); free(next); free(vsq); for (int i = 0; i < conf.nsrcs; i++) { free(srcs[i]); } free(srcs); return 0; }
void RandomPCA::pca(MatrixXd &X, int method, bool transpose, unsigned int ndim, unsigned int nextra, unsigned int maxiter, double tol, long seed, int kernel, double sigma, bool rbf_center, unsigned int rbf_sample, bool save_kernel, bool do_orth, bool do_loadings) { unsigned int N; if(kernel != KERNEL_LINEAR) { transpose = false; verbose && std::cout << timestamp() << " Kernel not linear, can't transpose" << std::endl; } verbose && std::cout << timestamp() << " Transpose: " << (transpose ? "yes" : "no") << std::endl; if(transpose) { if(stand_method != STANDARDIZE_NONE) X_meansd = standardize_transpose(X, stand_method, verbose); N = X.cols(); } else { if(stand_method != STANDARDIZE_NONE) X_meansd = standardize(X, stand_method, verbose); N = X.rows(); } unsigned int total_dim = ndim + nextra; MatrixXd R = make_gaussian(X.cols(), total_dim, seed); MatrixXd Y = X * R; verbose && std::cout << timestamp() << " dim(Y): " << dim(Y) << std::endl; normalize(Y); MatrixXd Yn; verbose && std::cout << timestamp() << " dim(X): " << dim(X) << std::endl; MatrixXd K; if(kernel == KERNEL_RBF) { if(sigma == 0) { unsigned int med_samples = fminl(rbf_sample, N); double med = median_dist(X, med_samples, seed, verbose); sigma = sqrt(med); } verbose && std::cout << timestamp() << " Using RBF kernel with sigma=" << sigma << std::endl; K.noalias() = rbf_kernel(X, sigma, rbf_center, verbose); } else { verbose && std::cout << timestamp() << " Using linear kernel" << std::endl; K.noalias() = X * X.transpose() / (N - 1); } //trace = K.diagonal().array().sum() / (N - 1); trace = K.diagonal().array().sum(); verbose && std::cout << timestamp() << " Trace(K): " << trace << " (N: " << N << ")" << std::endl; verbose && std::cout << timestamp() << " dim(K): " << dim(K) << std::endl; if(save_kernel) { verbose && std::cout << timestamp() << " saving K" << std::endl; save_text("kernel.txt", K); } for(unsigned int iter = 0 ; iter < maxiter ; iter++) { verbose && std::cout << timestamp() << " iter " << iter; Yn.noalias() = K * Y; if(do_orth) { verbose && std::cout << " (orthogonalising)"; ColPivHouseholderQR<MatrixXd> qr(Yn); MatrixXd I = MatrixXd::Identity(Yn.rows(), Yn.cols()); Yn = qr.householderQ() * I; Yn.conservativeResize(NoChange, Yn.cols()); } else normalize(Yn); double diff = (Y - Yn).array().square().sum() / Y.size(); verbose && std::cout << " " << diff << std::endl; Y.noalias() = Yn; if(diff < tol) break; } verbose && std::cout << timestamp() << " QR begin" << std::endl; ColPivHouseholderQR<MatrixXd> qr(Y); MatrixXd Q = MatrixXd::Identity(Y.rows(), Y.cols()); Q = qr.householderQ() * Q; Q.conservativeResize(NoChange, Y.cols()); verbose && std::cout << timestamp() << " dim(Q): " << dim(Q) << std::endl; verbose && std::cout << timestamp() << " QR done" << std::endl; MatrixXd B = Q.transpose() * X; verbose && std::cout << timestamp() << " dim(B): " << dim(B) << std::endl; MatrixXd Et; pca_small(B, method, Et, d, verbose); verbose && std::cout << timestamp() << " dim(Et): " << dim(Et) << std::endl; d = d.array() / (N - 1); if(transpose) { V.noalias() = Q * Et; // We divide P by sqrt(N - 1) since X has not been divided // by it (but B has) P.noalias() = X.transpose() * V; VectorXd s = 1 / (d.array().sqrt() * sqrt(N - 1)); MatrixXd Dinv = s.asDiagonal(); U = P * Dinv; } else { // P = U D = X V U.noalias() = Q * Et; P.noalias() = U * d.asDiagonal(); if(do_loadings) { VectorXd s = 1 / (d.array().sqrt() * sqrt(N - 1)); MatrixXd Dinv = s.asDiagonal(); V = X.transpose() * U * Dinv; } } P.conservativeResize(NoChange, ndim); U.conservativeResize(NoChange, ndim); V.conservativeResize(NoChange, ndim); d.conservativeResize(ndim); pve = d.array() / trace; }
static inline char *tparam_internal(const char *string, va_list ap) { #define NUM_VARS 26 int param[9]; int popcount; int variable[NUM_VARS]; static int sVariable[NUM_VARS]; char len; int number; int level; int x, y; int i; int varused = -1; register const char *cp; out_used = 0; if (string == NULL) return NULL; /* * Find the highest parameter-number referred to in the format string. * Use this value to limit the number of arguments copied from the * variable-length argument list. */ for (cp = string, popcount = number = 0; *cp != '\0'; cp++) { if (cp[0] == '%' && cp[1] != '\0') { switch (cp[1]) { case '%': cp++; break; case 'i': if (popcount < 2) popcount = 2; break; case 'p': cp++; if (cp[1] >= '1' && cp[1] <= '9') { int c = cp[1] - '0'; if (c > popcount) popcount = c; } break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'd': case 'c': case 's': ++number; break; } } } if (number > 9) number = 9; for (i = 0; i < max(popcount, number); i++) { /* * FIXME: potential loss here if sizeof(int) != sizeof(char *). * A few caps (such as plab_norm) have string-valued parms. */ param[i] = va_arg(ap, int); } /* * This is a termcap compatibility hack. If there are no explicit pop * operations in the string, load the stack in such a way that * successive pops will grab successive parameters. That will make * the expansion of (for example) \E[%d;%dH work correctly in termcap * style, which means tparam() will expand termcap strings OK. */ stack_ptr = 0; if (popcount == 0) { popcount = number; for (i = number - 1; i >= 0; i--) npush(param[i]); } #ifdef TRACE if (_nc_tracing & TRACE_CALLS) { for (i = 0; i < popcount; i++) save_number(", %d", param[i]); _tracef(T_CALLED("%s(%s%s)"), tname, _nc_visbuf(string), out_buff); out_used = 0; } #endif /* TRACE */ while (*string) { if (*string != '%') save_char(*string); else { string++; switch (*string) { default: break; case '%': save_char('%'); break; case 'd': save_number("%d", npop()); break; case 'x': save_number("%x", npop()); break; case '0': string++; len = *string; if (len == '2' || len == '3') { ++string; if (*string == 'd') { if (len == '2') save_number("%02d", npop()); else save_number("%03d", npop()); } else if (*string == 'x') { if (len == '2') save_number("%02x", npop()); else save_number("%03x", npop()); } } break; case '2': string++; if (*string == 'd') { save_number("%2d", npop()); } else if (*string == 'x') { save_number("%2x", npop()); } break; case '3': string++; if (*string == 'd') { save_number("%3d", npop()); } else if (*string == 'x') { save_number("%3x", npop()); } break; case 'c': save_char(npop()); break; case 's': save_text(spop()); break; case 'p': string++; if (*string >= '1' && *string <= '9') npush(param[*string - '1']); break; case 'P': string++; if (islower(*string)) { i = (*string - 'a'); if (i >= 0 && i < NUM_VARS) { while (varused < i) variable[++varused] = 0; variable[i] = npop(); } } else { i = (*string - 'A'); if (i >= 0 && i < NUM_VARS) sVariable[i] = npop(); } break; case 'g': string++; if (islower(*string)) { i = (*string - 'a'); if (i >= 0 && i < NUM_VARS) { while (varused < i) variable[++varused] = 0; npush(variable[i]); } } else { i = (*string - 'A'); if (i >= 0 && i < NUM_VARS) npush(sVariable[i]); } break; case '\'': string++; npush(*string); string++; break; case L_BRACE: number = 0; string++; while (*string >= '0' && *string <= '9') { number = number * 10 + *string - '0'; string++; } npush(number); break; case '+': npush(npop() + npop()); break; case '-': y = npop(); x = npop(); npush(x - y); break; case '*': npush(npop() * npop()); break; case '/': y = npop(); x = npop(); npush(x / y); break; case 'm': y = npop(); x = npop(); npush(x % y); break; case 'A': npush(npop() && npop()); break; case 'O': npush(npop() || npop()); break; case '&': npush(npop() & npop()); break; case '|': npush(npop() | npop()); break; case '^': npush(npop() ^ npop()); break; case '=': y = npop(); x = npop(); npush(x == y); break; case '<': y = npop(); x = npop(); npush(x < y); break; case '>': y = npop(); x = npop(); npush(x > y); break; case '!': npush(! npop()); break; case '~': npush(~ npop()); break; case 'i': param[0]++; param[1]++; break; case '?': break; case 't': x = npop(); if (!x) { /* scan forward for %e or %; at level zero */ string++; level = 0; while (*string) { if (*string == '%') { string++; if (*string == '?') level++; else if (*string == ';') { if (level > 0) level--; else break; } else if (*string == 'e' && level == 0) break; } if (*string) string++; } } break; case 'e': /* scan forward for a %; at level zero */ string++; level = 0; while (*string) { if (*string == '%') { string++; if (*string == '?') level++; else if (*string == ';') { if (level > 0) level--; else break; } } if (*string) string++; } break; case ';': break; } /* endswitch (*string) */ } /* endelse (*string == '%') */ if (*string == '\0') break; string++; } /* endwhile (*string) */ if (out_buff == 0) out_buff = calloc(1,1); if (out_used == 0) *out_buff = '\0'; T((T_RETURN("%s"), _nc_visbuf(out_buff))); return(out_buff); }
static void save_number(const char *fmt, int number) { char temp[80]; (void)sprintf(temp, fmt, number); save_text(temp); }
static inline char * tparam_internal(const char *string, int *dataptr) { #define NUM_VARS 26 char *p_is_s[9]; int param[9]; int lastpop; int popcount; int number; int len; int level; int x, y; int i; int len2; register const char *cp; static int len_fmt = MAX_FORMAT_LEN; static char dummy[] = ""; static char format[MAX_FORMAT_LEN]; static int dynamic_var[NUM_VARS]; static int static_vars[NUM_VARS]; out_used = 0; if (string == NULL) return NULL; if ((len2 = grub_strlen(string)) > len_fmt) { return NULL; } /* * Find the highest parameter-number referred to in the format string. * Use this value to limit the number of arguments copied from the * variable-length argument list. */ number = 0; lastpop = -1; popcount = 0; grub_memset(p_is_s, 0, sizeof(p_is_s)); /* * Analyze the string to see how many parameters we need from the varargs * list, and what their types are. We will only accept string parameters * if they appear as a %l or %s format following an explicit parameter * reference (e.g., %p2%s). All other parameters are numbers. * * 'number' counts coarsely the number of pop's we see in the string, and * 'popcount' shows the highest parameter number in the string. We would * like to simply use the latter count, but if we are reading termcap * strings, there may be cases that we cannot see the explicit parameter * numbers. */ for (cp = string; (cp - string) < (int) len2;) { if (*cp == '%') { cp++; cp = parse_format(cp, format, &len); switch (*cp) { default: break; case 'd': /* FALLTHRU */ case 'o': /* FALLTHRU */ case 'x': /* FALLTHRU */ case 'X': /* FALLTHRU */ case 'c': /* FALLTHRU */ number++; lastpop = -1; break; case 'l': case 's': if (lastpop > 0) p_is_s[lastpop - 1] = dummy; ++number; break; case 'p': cp++; i = (*cp - '0'); if (i >= 0 && i <= 9) { lastpop = i; if (lastpop > popcount) popcount = lastpop; } break; case 'P': case 'g': cp++; break; case '\'': cp += 2; lastpop = -1; break; case '{': cp++; while (*cp >= '0' && *cp <= '9') { cp++; } break; case '+': case '-': case '*': case '/': case 'm': case 'A': case 'O': case '&': case '|': case '^': case '=': case '<': case '>': case '!': case '~': lastpop = -1; number += 2; break; case 'i': lastpop = -1; if (popcount < 2) popcount = 2; break; } } if (*cp != '\0') cp++; } if (number > 9) number = 9; for (i = 0; i < max(popcount, number); i++) { /* * A few caps (such as plab_norm) have string-valued parms. * We'll have to assume that the caller knows the difference, since * a char* and an int may not be the same size on the stack. */ if (p_is_s[i] != 0) { p_is_s[i] = (char *)(*(dataptr++)); } else { param[i] = (int)(*(dataptr++)); } } /* * This is a termcap compatibility hack. If there are no explicit pop * operations in the string, load the stack in such a way that * successive pops will grab successive parameters. That will make * the expansion of (for example) \E[%d;%dH work correctly in termcap * style, which means tparam() will expand termcap strings OK. */ stack_ptr = 0; if (popcount == 0) { popcount = number; for (i = number - 1; i >= 0; i--) npush(param[i]); } while (*string) { /* skip delay timings */ if (*string == '$' && *(string + 1) == '<') { while( *string && *string != '>') string++; if ( *string == '>' ) string++; } else if ( *string == '%') { string++; string = parse_format(string, format, &len); switch (*string) { default: break; case '%': save_char('%'); break; case 'd': /* FALLTHRU */ case 'o': /* FALLTHRU */ case 'x': /* FALLTHRU */ case 'X': /* FALLTHRU */ case 'c': /* FALLTHRU */ save_number(format, npop(), len); break; case 'l': save_number("%d", strlen(spop()), 0); break; case 's': save_text(format, spop(), len); break; case 'p': string++; i = (*string - '1'); if (i >= 0 && i < 9) { if (p_is_s[i]) spush(p_is_s[i]); else npush(param[i]); } break; case 'P': string++; if (isUPPER(*string)) { i = (*string - 'A'); static_vars[i] = npop(); } else if (isLOWER(*string)) { i = (*string - 'a'); dynamic_var[i] = npop(); } break; case 'g': string++; if (isUPPER(*string)) { i = (*string - 'A'); npush(static_vars[i]); } else if (isLOWER(*string)) { i = (*string - 'a'); npush(dynamic_var[i]); } break; case '\'': string++; npush(*string); string++; break; case '{': number = 0; string++; while (*string >= '0' && *string <= '9') { number = number * 10 + *string - '0'; string++; } npush(number); break; case '+': npush(npop() + npop()); break; case '-': y = npop(); x = npop(); npush(x - y); break; case '*': npush(npop() * npop()); break; case '/': y = npop(); x = npop(); npush(y ? (x / y) : 0); break; case 'm': y = npop(); x = npop(); npush(y ? (x % y) : 0); break; case 'A': npush(npop() && npop()); break; case 'O': npush(npop() || npop()); break; case '&': npush(npop() & npop()); break; case '|': npush(npop() | npop()); break; case '^': npush(npop() ^ npop()); break; case '=': y = npop(); x = npop(); npush(x == y); break; case '<': y = npop(); x = npop(); npush(x < y); break; case '>': y = npop(); x = npop(); npush(x > y); break; case '!': npush(!npop()); break; case '~': npush(~npop()); break; case 'i': if (p_is_s[0] == 0) param[0]++; if (p_is_s[1] == 0) param[1]++; break; case '?': break; case 't': x = npop(); if (!x) { /* scan forward for %e or %; at level zero */ string++; level = 0; while (*string) { if (*string == '%') { string++; if (*string == '?') level++; else if (*string == ';') { if (level > 0) level--; else break; } else if (*string == 'e' && level == 0) break; } if (*string) string++; } } break; case 'e': /* scan forward for a %; at level zero */ string++; level = 0; while (*string) { if (*string == '%') { string++; if (*string == '?') level++; else if (*string == ';') { if (level > 0) level--; else break; } } if (*string) string++; } break; case ';': break; } /* endswitch (*string) */ } else { /* endelse (*string == '%') */ save_char(*string); } if (*string == '\0') break; string++; } /* endwhile (*string) */ get_space(1); out_buff[out_used] = '\0'; return (out_buff); }
int main(int argc, char * argv[]) { po::options_description desc("Options"); desc.add_options() ("help", "produce help message") ("bfile", po::value<std::string>(), "PLINK root name") ("w", po::value<std::string>(), "SNP weights filename") ("stand", po::value<std::string>(), "standardization method [none | binom | sd | center]") ("out", po::value<std::string>(), "output filename") ("numthreads", po::value<int>(), "set number of OpenMP threads") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); if(vm.count("help")) { std::cerr << desc << std::endl; return EXIT_FAILURE; } int num_threads = 1; if(vm.count("numthreads")) num_threads = vm["numthreads"].as<int>(); int stand_method = STANDARDIZE_BINOM; if(vm.count("stand")) { std::string m = vm["stand"].as<std::string>(); if(m == "binom") stand_method = STANDARDIZE_BINOM; else if(m == "sd") stand_method = STANDARDIZE_SD; else if(m == "center") stand_method = STANDARDIZE_CENTER; else if(m == "none") stand_method = STANDARDIZE_NONE; else { std::cerr << "Error: unknown standardization method (--stand): " << m << std::endl; return EXIT_FAILURE; } } std::string geno_file, fam_file; if(vm.count("bfile")) { geno_file = vm["bfile"].as<std::string>() + std::string(".bed"); fam_file = vm["bfile"].as<std::string>() + std::string(".fam"); std::cout << ">>> genotype file: " << geno_file << std::endl; } else { std::cerr << "Error: bfile not specified" << std::endl; return EXIT_FAILURE; } std::string w_file; if(vm.count("w")) { w_file = vm["w"].as<std::string>(); } std::string out_file = "PredX.txt"; if(vm.count("out")) { out_file = vm["out"].as<std::string>(); } #ifdef _OPENMP #ifdef EIGEN_HAS_OPENMP omp_set_num_threads(num_threads); std::cout << timestamp() << " Using " << num_threads << " OpenMP threads" << std::endl; #endif #endif Data data(1); data.verbose = true; data.read_pheno(fam_file.c_str(), 6); data.geno_filename = geno_file.c_str(); data.get_size(); data.read_bed(false); standardize(data.X, stand_method, false); MatrixXd W = data.read_plink_pheno(w_file.c_str(), 1); MatrixXd P = data.X * W; save_text(P, out_file.c_str()); return EXIT_SUCCESS; }
static void enter_callback( GtkWidget *widget, GtkWidget *window ) { save_text(); gtk_widget_destroy(window); }