static void show_help(bool * keyhelp) { werase(helpwin); if (*keyhelp) { help1(); *keyhelp = FALSE; } else { help2(); *keyhelp = TRUE; } wrefresh(helpwin); }
void tex::help_relation() { help1("I was expecting to see `<', `=', or `>'. Didn't."); }
void tex::help_or() { help1("I'm ignoring this; it doesn't match any \\if."); }
void iterative_matrix_inverse(double *matptr, double *invmatptr, int n, _Bool prev, double epsilon, double *work1, double *work2, int *error, cublasHandle_t cublas_handle, int *nit_out) { INIT_ERROR(error); mat<double> matr(n, matptr, cublas_handle); mat<double> invmat(n, invmatptr, cublas_handle); /* Will allocate and release upon destruction if work1, work2 == NULL */ mat<double> help1(n, work1, cublas_handle); mat<double> help2(n, work2, cublas_handle); /* * - Initialize inverse matrix if previous not used * The starting invmat has to be small enough so that the iteration * won't start running to infinity */ #if 0 mat<double> dummy(n); dummy = matr; printf("dummy.data() = %p\n", dummy.data()); printf("matr.data() = %p\n", matr.data()); printf("dummy.on_host() = %i\n", dummy.on_host(error)); PASS_ERROR(error); printf("matr.on_host() = %i\n", matr.on_host(error)); PASS_ERROR(error); printf("sum = %f %f\n", dummy.sum(), matr.sum()); printf("max = %f %f\n", dummy.max(), matr.max()); printf("min = %f %f\n", dummy.min(), matr.min()); printf("amax = %f %f\n", dummy.amax(), matr.amax()); printf("amin = %f %f\n", dummy.amin(), matr.amin()); #endif if (!prev) { double smin, smax; ev_bounds(n, matptr, &smin, &smax, error); PASS_ERROR(error); mat_mul_sca(1.0/(n*MAX(fabs(smin), fabs(smax))), matr, invmat, error); PASS_ERROR(error); } /* * Find inverse via S^-1 = 2 S^1 - S^-1 S S^-1 */ double sigma = epsilon + 1.0; int i = 0; while (sigma > epsilon) { /* * help1 = matr.invmat */ gemm(OP_N, OP_N, 1.0, matr, invmat, 0.0, help1, error); PASS_ERROR(error); help2 = invmat; /* * invmat = -help2.help1 + 2*invmat */ gemm(OP_N, OP_N, -1.0, help2, help1, 2.0, invmat, error); PASS_ERROR(error); mat_mul_sca(1.0, help2, -1.0, invmat, help1, error); PASS_ERROR(error); sigma = help1.amax(error); PASS_ERROR(error); i = i+1; if (i % 100 == 0) { prscrlog("iterative_matrix_inverse: No convergence after %i iterations.", i); } } if (nit_out) { *nit_out = i; } }
void scope5() { help1(); help3(); }
void scope4() { help1(); help2(); }
void tex::help_double_sup() { help1("I treat `x^1^2' essentially like `x^1{}^2'."); }
void tex::help_double_sub() { help1("I treat `x_1_2' essentially like `x_1{}_2'."); }
void tex::help_xtra_right() { help1("I'm ignoring a \\right that had no matching \\left."); }
void tex::help_limits() { help1("I'm ignoring this misplaced \\limits or \\nolimits command."); }
static void play(void) /* play the game */ { bool keyhelp; /* TRUE if keystroke help is up */ int i, j, count; int lastcol = 0; /* last location visited */ int lastrow = 0; int ny = 0, nx = 0; int review = 0; /* review history */ int rw = 0, col = 0; /* current row and column */ do { /* clear screen and draw board */ werase(boardwin); werase(helpwin); werase(msgwin); dosquares(); help1(); wnoutrefresh(stdscr); wnoutrefresh(helpwin); wnoutrefresh(msgwin); wnoutrefresh(boardwin); doupdate(); movecount = 0; for (i = 0; i < BDEPTH; i++) { for (j = 0; j < BWIDTH; j++) { board[i][j] = FALSE; unmarkcell(i, j); } } memset(history, 0, sizeof(history)); history[0].y = history[0].x = -1; history[1].y = history[1].x = -1; lastrow = lastcol = -2; movecount = 1; trialcount = 1; keyhelp = FALSE; show_help(&keyhelp); for (;;) { if (rw != lastrow || col != lastcol) { if (lastrow >= 0 && lastcol >= 0) { cellmove(lastrow, lastcol); if (board[lastrow][lastcol]) waddch(boardwin, trail); else waddch(boardwin, oldch); } cellmove(rw, col); oldch = winch(boardwin); lastrow = rw; lastcol = col; } cellmove(rw, col); waddch(boardwin, plus); cellmove(rw, col); wrefresh(msgwin); switch (wgetch(boardwin)) { case 'k': case '8': case KEY_UP: ny = rw + BDEPTH - 1; nx = col; break; case 'j': case '2': case KEY_DOWN: ny = rw + 1; nx = col; break; case 'h': case '4': case KEY_LEFT: ny = rw; nx = col + BWIDTH - 1; break; case 'l': case '6': case KEY_RIGHT: ny = rw; nx = col + 1; break; case 'y': case '7': case KEY_A1: ny = rw + BDEPTH - 1; nx = col + BWIDTH - 1; break; case 'b': case '1': case KEY_C1: ny = rw + 1; nx = col + BWIDTH - 1; break; case 'u': case '9': case KEY_A3: ny = rw + BDEPTH - 1; nx = col + 1; break; case 'n': case '3': case KEY_C3: ny = rw + 1; nx = col + 1; break; #ifdef NCURSES_MOUSE_VERSION case KEY_MOUSE: { MEVENT myevent; getmouse(&myevent); if (myevent.y >= CY(0) && myevent.y <= CY(BDEPTH) && myevent.x >= CX(0) && myevent.x <= CX(BWIDTH)) { nx = CXINV(myevent.x); ny = CYINV(myevent.y); ungetch('\n'); break; } else { beep(); continue; } } #endif /* NCURSES_MOUSE_VERSION */ case KEY_B2: case '\n': case ' ': review = 0; if (evalmove(rw, col)) { drawmove(trail, history[movecount - 1].y, history[movecount - 1].x, rw, col); history[movecount].y = (short) rw; history[movecount].x = (short) col; movecount++; trialcount++; if (!chkmoves(rw, col)) { if (completed() < 0) { waddstr(msgwin, "\nYou won."); } else { waddstr(msgwin, "\nNo further moves are possible."); } } } else { beep(); } break; case KEY_UNDO: case KEY_BACKSPACE: case '\b': review = 0; if (movecount <= 0) { no_previous_move(); } else if (movecount <= 1) { ny = history[movecount].y; nx = history[movecount].x; if (nx < 0 || ny < 0) { ny = lastrow; nx = lastcol; } movecount = 0; board[ny][nx] = FALSE; oldch = minus; drawmove(' ', ny, nx, -1, -1); movecount = 1; trialcount = 1; no_previous_move(); } else { int oldy = history[movecount - 1].y; int oldx = history[movecount - 1].x; if (!board[rw][col]) { cellmove(rw, col); waddch(boardwin, ' '); } board[oldy][oldx] = FALSE; --movecount; ny = history[movecount - 1].y; nx = history[movecount - 1].x; if (nx < 0 || ny < 0) { ny = oldy; nx = oldx; } drawmove(' ', oldy, oldx, ny, nx); /* avoid problems if we just changed the current cell */ cellmove(lastrow, lastcol); oldch = winch(boardwin); } break; case 'a': nx = col; ny = rw; find_next_move(&ny, &nx); break; case 'F': if (review > 0) { review--; ny = history[movecount - review - 1].y; nx = history[movecount - review - 1].x; } else { beep(); } break; case 'B': if (review < movecount - 2) { review++; ny = history[movecount - review - 1].y; nx = history[movecount - review - 1].x; } else { beep(); } break; case KEY_REDO: case '\f': case 'r': clearok(curscr, TRUE); wnoutrefresh(stdscr); wnoutrefresh(boardwin); wnoutrefresh(msgwin); wnoutrefresh(helpwin); doupdate(); break; case 'q': case 'x': goto dropout; case '?': show_help(&keyhelp); break; default: beep(); break; } col = nx % BWIDTH; rw = ny % BDEPTH; } dropout: if ((count = completed()) < 0) wprintw(msgwin, "\nYou won. Care to try again? "); else wprintw(msgwin, "\n%d squares filled. Try again? ", count); wclrtoeol(msgwin); } while (tolower(wgetch(msgwin)) == 'y'); }
int main(int argc, char** args) { help1(); return 0; }