/* try to get the module's context, returns a PAM status code */ static int ctx_get(pam_handle_t *pamh,const char *username,struct pld_ctx **pctx) { struct pld_ctx *ctx=NULL; int rc; /* try to get the context from PAM */ rc=pam_get_data(pamh,PLD_CTX,(const void **)&ctx); if ((rc==PAM_SUCCESS)&&(ctx!=NULL)) { /* if the user is different clear the context */ if ((ctx->user!=NULL)&&(strcmp(ctx->user,username)!=0)) ctx_clear(ctx); } else { /* allocate a new context */ ctx=calloc(1,sizeof(struct pld_ctx)); if (ctx==NULL) { pam_syslog(pamh,LOG_CRIT,"calloc(): failed to allocate memory: %s",strerror(errno)); return PAM_BUF_ERR; } ctx_clear(ctx); /* store the new context with the handler to free it */ rc=pam_set_data(pamh,PLD_CTX,ctx,ctx_free); if (rc!=PAM_SUCCESS) { ctx_free(pamh,ctx,0); pam_syslog(pamh,LOG_ERR,"failed to store context: %s",pam_strerror(pamh,rc)); return rc; } } /* return the context */ *pctx=ctx; return PAM_SUCCESS; }
int main(void) { int i; flint_rand_t state; printf("init/ clear... "); fflush(stdout); _randinit(state); /* Unmanaged element type (long) */ for (i = 0; i < 100; i++) { long m, n; double d; ctx_t ctx; mat_coo_t A; m = n_randint(state, 100) + 1; n = n_randint(state, 100) + 1; d = (double) n_randint(state, 101) / (double) 100; ctx_init_long(ctx); mat_coo_init(A, m, n, ctx); mat_coo_randtest(A, state, d, ctx); mat_coo_clear(A, 1, ctx); ctx_clear(ctx); } /* Managed element type (mpq_t) */ for (i = 0; i < 100; i++) { long m, n; double d; ctx_t ctx; mat_coo_t A; m = n_randint(state, 100) + 1; n = n_randint(state, 100) + 1; d = (double) n_randint(state, 101) / (double) 100; ctx_init_mpq(ctx); mat_coo_init(A, m, n, ctx); mat_coo_randtest(A, state, d, ctx); mat_coo_clear(A, 1, ctx); ctx_clear(ctx); } _randclear(state); _fmpz_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }
int main(void) { int i, result; flint_rand_t state; _randinit(state); { const char *str = "3 [5 0 0] [0 5 0] [0 0 5] (2 0 1)[1 1 3]"; const long n = atoi(str) - 1; mpoly_t P; ctx_t ctxFracQt; qadic_ctx_t Qq; fmpz_t p = {3L}; long d = 40; qadic_t t1; prec_t prec, prec_in; /* prec_in.N0 = 9; prec_in.N1 = 9; prec_in.N2 = 9; prec_in.N3 = 13; prec_in.N3i = 14; prec_in.N3w = 23; prec_in.N3iw = 22; prec_in.N4 = 18; prec_in.m = 29; prec_in.K = 178; prec_in.r = 0; prec_in.s = 0; */ ctx_init_fmpz_poly_q(ctxFracQt); qadic_ctx_init_conway(Qq, p, d, 1, 1, "X", PADIC_SERIES); qadic_init2(t1, 1); qadic_gen(t1, Qq); mpoly_init(P, n + 1, ctxFracQt); mpoly_set_str(P, str, ctxFracQt); frob(P, ctxFracQt, t1, Qq, &prec, NULL, 1); qadic_clear(t1); mpoly_clear(P, ctxFracQt); ctx_clear(ctxFracQt); qadic_ctx_clear(Qq); } _randclear(state); _fmpz_cleanup(); return EXIT_SUCCESS; }
static void ctx_fini(krb5_db2_context *dbc) { if (dbc->db_lf_file != -1) (void) close(dbc->db_lf_file); if (dbc->policy_db) (void) osa_adb_fini_db(dbc->policy_db, OSA_ADB_POLICY_DB_MAGIC); ctx_clear(dbc); free(dbc); }
int main(void) { int i, result; flint_rand_t state; _randinit(state); /* A generic sextic curve. */ { const char *str = "3 [6 0 0] [0 6 0] [0 0 6] " "(2 0 -1)[5 1 0] (2 0 7)[5 0 1] (2 0 2)[1 5 0] (2 0 1)[0 5 1] (2 0 2)[1 0 5] (2 0 1)[0 1 5] " "(2 0 2)[4 2 0] (2 0 2)[4 0 2] (2 0 3)[2 4 0] (2 0 1)[0 4 2] (2 0 3)[2 0 4] (2 0 1)[0 2 4] " "(2 0 3)[4 1 1] (2 0 3)[1 4 1] (2 0 1)[1 1 4] " "(2 0 -1)[3 3 0] (2 0 -2)[3 0 3] (2 0 4)[0 3 3] " "(2 0 2)[3 2 1] (2 0 1)[3 1 2] (2 0 -1)[2 3 1] (2 0 1)[1 3 2] (2 0 2)[2 1 3] (2 0 1)[1 2 3] " "(2 0 1)[2 2 2]"; const long n = atoi(str) - 1; mpoly_t P; ctx_t ctxFracQt; qadic_ctx_t Qq; fmpz_t p = {5L}; long d = 1; qadic_t t1; prec_t prec, prec_in; ctx_init_fmpz_poly_q(ctxFracQt); qadic_ctx_init_conway(Qq, p, d, 1, 1, "X", PADIC_SERIES); qadic_init2(t1, 1); qadic_set_ui(t1, 2, Qq); mpoly_init(P, n + 1, ctxFracQt); mpoly_set_str(P, str, ctxFracQt); frob(P, ctxFracQt, t1, Qq, &prec, NULL, 1); qadic_clear(t1); mpoly_clear(P, ctxFracQt); ctx_clear(ctxFracQt); qadic_ctx_clear(Qq); } _randclear(state); _fmpz_cleanup(); return EXIT_SUCCESS; }
int main(void) { int i, result; flint_rand_t state; _randinit(state); /* A quartic surface from Example 4.2.1 in [AKR]. TODO: This currently still fails! */ { const char *str = "4 (2 2 -1)[4 0 0 0] [0 4 0 0] [0 0 4 0] [0 0 0 4] " "(2 0 -1)[0 1 3 0] (2 0 1)[1 1 2 0] (2 0 1)[1 1 1 1] " "(2 0 1)[2 1 1 0] (2 0 -1)[2 1 0 1] (2 0 1)[1 0 3 0] (2 0 -1)[1 0 2 1]"; const long n = atoi(str) - 1; mpoly_t P; ctx_t ctxFracQt; qadic_ctx_t Qq; fmpz_t p = {3L}; long d = 2; qadic_t t1; prec_t prec, prec_in; ctx_init_fmpz_poly_q(ctxFracQt); qadic_ctx_init_conway(Qq, p, d, 1, 1, "X", PADIC_SERIES); qadic_init2(t1, 1); qadic_gen(t1, Qq); mpoly_init(P, n + 1, ctxFracQt); mpoly_set_str(P, str, ctxFracQt); frob(P, ctxFracQt, t1, Qq, &prec, NULL, 1); qadic_clear(t1); mpoly_clear(P, ctxFracQt); ctx_clear(ctxFracQt); qadic_ctx_clear(Qq); } _randclear(state); _fmpz_cleanup(); return EXIT_SUCCESS; }
int main(void) { int i, result; flint_rand_t state; _randinit(state); { const char *str = "4 [5 0 0 0] [0 5 0 0] [0 0 5 0] [0 0 0 5] (2 0 1)[2 1 1 1]"; const long n = atoi(str) - 1; mpoly_t P; ctx_t ctxFracQt; qadic_ctx_t Qq; fmpz_t p = {2L}; long d = 10; qadic_t t1; prec_t prec, prec_in; ctx_init_fmpz_poly_q(ctxFracQt); qadic_ctx_init_conway(Qq, p, d, 1, 1, "X", PADIC_SERIES); qadic_init2(t1, 1); qadic_gen(t1, Qq); mpoly_init(P, n + 1, ctxFracQt); mpoly_set_str(P, str, ctxFracQt); frob(P, ctxFracQt, t1, Qq, &prec, NULL, 1); qadic_clear(t1); mpoly_clear(P, ctxFracQt); ctx_clear(ctxFracQt); qadic_ctx_clear(Qq); } _randclear(state); _fmpz_cleanup(); return EXIT_SUCCESS; }
/* Set *dbc_out to the db2 database context for context. If one does not * exist, create one in the uninitialized state. */ static krb5_error_code ctx_get(krb5_context context, krb5_db2_context **dbc_out) { krb5_db2_context *dbc; kdb5_dal_handle *dal_handle; dal_handle = context->dal_handle; if (dal_handle->db_context == NULL) { dbc = (krb5_db2_context *) malloc(sizeof(krb5_db2_context)); if (dbc == NULL) return ENOMEM; else { memset(dbc, 0, sizeof(krb5_db2_context)); ctx_clear(dbc); dal_handle->db_context = dbc; } } *dbc_out = dal_handle->db_context; return 0; }
/* Initialize the lock file and policy database fields of dbc. The db_name and * tempdb fields must already be set. */ static krb5_error_code ctx_init(krb5_db2_context *dbc) { krb5_error_code retval; char *polname = NULL, *plockname = NULL; retval = ctx_dbsuffix(dbc, SUFFIX_LOCK, &dbc->db_lf_name); if (retval) return retval; /* * should be opened read/write so that write locking can work with * POSIX systems */ if ((dbc->db_lf_file = open(dbc->db_lf_name, O_RDWR, 0666)) < 0) { if ((dbc->db_lf_file = open(dbc->db_lf_name, O_RDONLY, 0666)) < 0) { retval = errno; goto cleanup; } } set_cloexec_fd(dbc->db_lf_file); dbc->db_inited++; retval = ctx_dbsuffix(dbc, SUFFIX_POLICY, &polname); if (retval) goto cleanup; retval = ctx_dbsuffix(dbc, SUFFIX_POLICY_LOCK, &plockname); if (retval) goto cleanup; retval = osa_adb_init_db(&dbc->policy_db, polname, plockname, OSA_ADB_POLICY_DB_MAGIC); cleanup: free(polname); free(plockname); if (retval) ctx_clear(dbc); return retval; }
int main(void) { int i, j, result; flint_rand_t state; ctx_t ctx; printf("decompose_poly... "); fflush(stdout); _randinit(state); ctx_init_mpq(ctx); { mpoly_t P; mon_t *B; long *iB, lenB, l, u, k; long n, d; printf("\n"); fflush(stdout); mpoly_init(P, 3, ctx); mpoly_set_str(P, "3 [3 0 0] [0 3 0] [0 0 3] (2)[1 1 1]", ctx); n = P->n - 1; d = mpoly_degree(P, -1, ctx); gmc_basis_sets(&B, &iB, &lenB, &l, &u, n, d); printf("P = "), mpoly_print(P, ctx), printf("\n"); printf("n = %ld\n", n); printf("d = %ld\n", d); printf("l u = %ld %ld\n", l, u); printf("B = "), gmc_basis_print(B, iB, lenB, n, d), printf("\n"); for (k = l + 1; k <= u + 1; k++) { mat_csr_t mat; mat_csr_solve_t s; mon_t *rows, *cols; long *p; mpoly_t *A, *D; p = malloc((n + 2) * sizeof(long)); gmc_init_auxmatrix(mat, &rows, &cols, p, P, k, ctx); mat_csr_solve_init(s, mat, ctx); A = malloc((n + 1) * sizeof(mpoly_t)); for (j = 0; j <= n; j++) mpoly_init(A[j], n + 1, ctx); D = malloc((n + 1) * sizeof(mpoly_t)); for (j = 0; j <= n; j++) mpoly_init(D[j], n + 1, ctx); gmc_derivatives(D, P, ctx); printf("k = %ld\n", k); printf("["); for (i = 0; i < RUNS; i++) { mpoly_t poly1, poly2, poly3; char *zero; mpoly_init(poly1, n + 1, ctx); mpoly_init(poly2, n + 1, ctx); mpoly_init(poly3, n + 1, ctx); zero = malloc(ctx->size); ctx->init(ctx, zero); ctx->zero(ctx, zero); mpoly_randtest_hom(poly1, state, k * d - (n + 1), 20, ctx); for (j = iB[k]; j < iB[k + 1]; j++) mpoly_set_coeff(poly1, B[j], zero, ctx); gmc_decompose_poly(A, poly1, s, rows, cols, p, ctx); for (j = 0; j <= n; j++) mpoly_addmul(poly2, A[j], D[j], ctx); for (j = iB[k]; j < iB[k + 1]; j++) mpoly_set_coeff(poly2, B[j], zero, ctx); if (!mpoly_is_zero(poly1, ctx)) printf("."), fflush(stdout); result = (mpoly_equal(poly1, poly2, ctx)); if (!result) { printf("FAIL:\n\n"); printf("poly1 = "), mpoly_print(poly1, ctx), printf("\n"); printf("poly2 = "), mpoly_print(poly2, ctx), printf("\n"); for (j = 0; j <= n; j++) printf("D[%d] = ", j), mpoly_print(D[j], ctx), printf("\n"); for (j = 0; j <= n; j++) printf("A[%d] = ", j), mpoly_print(A[j], ctx), printf("\n"); abort(); } mpoly_clear(poly1, ctx); mpoly_clear(poly2, ctx); mpoly_clear(poly3, ctx); ctx->clear(ctx, zero); free(zero); } printf("]\n"); mat_csr_clear(mat, ctx); mat_csr_solve_clear(s, ctx); free(rows); free(cols); free(p); for (j = 0; j <= n; j++) mpoly_clear(A[j], ctx); free(A); for (j = 0; j <= n; j++) mpoly_clear(D[j], ctx); free(D); } mpoly_clear(P, ctx); free(B); free(iB); } ctx_clear(ctx); _randclear(state); _fmpz_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }
int main(void) { int i, result; flint_rand_t state; printf("inv... "); fflush(stdout); _randinit(state); /* Check aliasing */ /* Managed element type (mpq_t) */ for (i = 0; i < 50; i++) { long n; ctx_t ctx; mat_t A, B, C; long ansB, ansC; n = n_randint(state, 20) + 1; ctx_init_mpq(ctx); mat_init(A, n, n, ctx); mat_init(B, n, n, ctx); mat_init(C, n, n, ctx); mat_randtest(A, state, ctx); mat_set(B, A, ctx); ansC = mat_inv(C, B, ctx); ansB = mat_inv(B, B, ctx); result = ((ansB == ansC) && (!ansB || mat_equal(B, C, ctx))); if (!result) { printf("FAIL:\n\n"); printf("A: \n"), mat_print(A, ctx), printf("\n"); printf("B: \n"), mat_print(B, ctx), printf("\n"); printf("C: \n"), mat_print(C, ctx), printf("\n"); printf("ansB = %ld\n", ansB); printf("ansC = %ld\n", ansC); } mat_clear(A, ctx); mat_clear(B, ctx); mat_clear(C, ctx); ctx_clear(ctx); } /* Check A * A^{-1} == A^{-1} * A == Id */ /* Managed element type (mpq_t) */ for (i = 0; i < 50; i++) { long n; ctx_t ctx; mat_t A, B, C, D, I; long ansB; n = n_randint(state, 20) + 1; ctx_init_mpq(ctx); mat_init(A, n, n, ctx); mat_init(B, n, n, ctx); mat_init(C, n, n, ctx); mat_init(D, n, n, ctx); mat_init(I, n, n, ctx); mat_randtest(A, state, ctx); ansB = mat_inv(B, A, ctx); if (!ansB) { mat_mul(C, A, B, ctx); mat_mul(D, B, A, ctx); } result = (ansB || (mat_equal(C, D, ctx) && mat_is_one(C, ctx))); if (!result) { printf("FAIL:\n\n"); printf("A: \n"), mat_print(A, ctx), printf("\n"); printf("B: \n"), mat_print(B, ctx), printf("\n"); printf("C: \n"), mat_print(C, ctx), printf("\n"); printf("D: \n"), mat_print(D, ctx), printf("\n"); printf("ansB = %ld\n", ansB); } mat_clear(A, ctx); mat_clear(B, ctx); mat_clear(C, ctx); mat_clear(D, ctx); ctx_clear(ctx); } _randclear(state); _fmpz_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }
int main(void) { int i, result; flint_rand_t state; printf("add... "); fflush(stdout); _randinit(state); /* Check that addition is abelian */ /* Unmanaged element type (long) */ for (i = 0; i < 100; i++) { long m, n; ctx_t ctx; mat_t A, B, C, D; m = n_randint(state, 50) + 1; n = n_randint(state, 50) + 1; ctx_init_long(ctx); mat_init(A, m, n, ctx); mat_init(B, m, n, ctx); mat_init(C, m, n, ctx); mat_init(D, m, n, ctx); mat_randtest(A, state, ctx); mat_randtest(B, state, ctx); mat_add(C, A, B, ctx); mat_add(D, B, A, ctx); result = mat_equal(C, D, ctx); if (!result) { printf("FAIL:\n\n"); printf("Matrix A\n"); mat_print(A, ctx); printf("\n"); printf("Matrix A\n"); mat_print(B, ctx); printf("\n"); } mat_clear(A, ctx); mat_clear(B, ctx); mat_clear(C, ctx); mat_clear(D, ctx); ctx_clear(ctx); } /* Managed element type (mpq_t) */ for (i = 0; i < 100; i++) { long m, n; ctx_t ctx; mat_t A, B, C, D; m = n_randint(state, 50) + 1; n = n_randint(state, 50) + 1; ctx_init_mpq(ctx); mat_init(A, m, n, ctx); mat_init(B, m, n, ctx); mat_init(C, m, n, ctx); mat_init(D, m, n, ctx); mat_randtest(A, state, ctx); mat_randtest(B, state, ctx); mat_add(C, A, B, ctx); mat_add(D, B, A, ctx); result = mat_equal(C, D, ctx); if (!result) { printf("FAIL:\n\n"); printf("Matrix A\n"); mat_print(A, ctx); printf("\n"); printf("Matrix A\n"); mat_print(B, ctx); printf("\n"); } mat_clear(A, ctx); mat_clear(B, ctx); mat_clear(C, ctx); mat_clear(D, ctx); ctx_clear(ctx); } /* Check that the zero matrix does what it's supposed to do */ /* Unmanaged element type (long) */ for (i = 0; i < 100; i++) { long m, n; ctx_t ctx; mat_t A, B, C, D; m = n_randint(state, 50) + 1; n = n_randint(state, 50) + 1; ctx_init_long(ctx); mat_init(A, m, n, ctx); mat_init(B, m, n, ctx); mat_init(C, m, n, ctx); mat_init(D, m, n, ctx); mat_randtest(A, state, ctx); mat_zero(B, ctx); mat_add(C, A, B, ctx); mat_add(D, B, A, ctx); result = mat_equal(A, C, ctx) && mat_equal(C, D, ctx); if (!result) { printf("FAIL:\n\n"); printf("Matrix A\n"); mat_print(A, ctx); printf("\n"); printf("Matrix A\n"); mat_print(B, ctx); printf("\n"); } mat_clear(A, ctx); mat_clear(B, ctx); mat_clear(C, ctx); mat_clear(D, ctx); ctx_clear(ctx); } /* Managed element type (mpq_t) */ for (i = 0; i < 100; i++) { long m, n; ctx_t ctx; mat_t A, B, C, D; m = n_randint(state, 50) + 1; n = n_randint(state, 50) + 1; ctx_init_mpq(ctx); mat_init(A, m, n, ctx); mat_init(B, m, n, ctx); mat_init(C, m, n, ctx); mat_init(D, m, n, ctx); mat_randtest(A, state, ctx); mat_zero(B, ctx); mat_add(C, A, B, ctx); mat_add(D, B, A, ctx); result = mat_equal(A, C, ctx) && mat_equal(C, D, ctx); if (!result) { printf("FAIL:\n\n"); printf("Matrix A\n"); mat_print(A, ctx); printf("\n"); printf("Matrix A\n"); mat_print(B, ctx); printf("\n"); } mat_clear(A, ctx); mat_clear(B, ctx); mat_clear(C, ctx); mat_clear(D, ctx); ctx_clear(ctx); } _randclear(state); _fmpz_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }
int main(void) { char *str; /* String for the input polynomial P */ mpoly_t P; /* Input polynomial P */ long n; /* Number of variables minus one */ long K; /* Required t-adic precision */ long N, Nw; long i, b; mat_t M; ctx_t ctxM; mon_t *rows, *cols; padic_mat_struct *C; fmpz_t p; printf("valuations... \n"); fflush(stdout); /* Example 3-1-1 */ /* str = "3 [3 0 0] [0 3 0] [0 0 3] (2 0 1)[1 1 1]"; */ /* Example 4-4-2 */ /* str = "4 [4 0 0 0] [0 4 0 0] [0 0 4 0] [0 0 0 4] (2 0 1)[3 1 0 0] (2 0 1)[1 0 1 2] (2 0 1)[0 1 0 3]"; */ /* Example 3-3-6 */ /* str = "3 [3 0 0] [0 3 0] [0 0 3] (2 0 314)[2 1 0] (2 0 42)[0 2 1] (2 0 271)[1 0 2] (2 0 -23)[1 1 1]"; */ /* Example 3-3-2 */ /* str = "3 [3 0 0] [0 3 0] [0 0 3] (2 0 1)[2 1 0] (2 0 1)[0 2 1] (2 0 1)[1 0 2]"; */ /* Example ... */ /* str = "4 [4 0 0 0] [0 4 0 0] [0 0 4 0] [0 0 0 4] (2 0 1)[1 1 1 1]"; */ /* Cubic surface from AKR */ str = "4 (1 3)[0 3 0 0] (2 0 3)[0 1 2 0] " "(2 0 -1)[1 1 1 0] (2 0 3)[1 1 0 1] " "(2 0 -1)[2 1 0 0] [0 0 3 0] (2 0 -1)[1 0 2 0] " "(1 2)[0 0 0 3] [3 0 0 0]"; n = atoi(str) - 1; N = 10; Nw = 22; K = 616; ctx_init_fmpz_poly_q(ctxM); mpoly_init(P, n + 1, ctxM); mpoly_set_str(P, str, ctxM); printf("P = "), mpoly_print(P, ctxM), printf("\n"); b = gmc_basis_size(n, mpoly_degree(P, -1, ctxM)); mat_init(M, b, b, ctxM); gmc_compute(M, &rows, &cols, P, ctxM); mat_print(M, ctxM); printf("\n"); fmpz_init(p); fmpz_set_ui(p, 5); gmde_solve(&C, K, p, N, Nw, M, ctxM); printf("Valuations\n"); for (i = 0; i < K; i++) { long v = padic_mat_val(C + i); if (v < LONG_MAX) printf(" i = %ld val = %ld val/log(i) = %f\n", i, v, (i > 1) ? (double) v / log(i) : 0); else printf(" i = %ld val = +infty\n", i); } fmpz_clear(p); mpoly_clear(P, ctxM); mat_clear(M, ctxM); for (i = 0; i < K; i++) padic_mat_clear(C + i); free(C); ctx_clear(ctxM); return EXIT_SUCCESS; }
int main(void) { char *str; /* String for the input polynomial P */ mpoly_t P; /* Input polynomial P */ int n; /* Number of variables minus one */ long K; /* Required t-adic precision */ long N, Nw; long b; /* Matrix dimensions */ long i, j, k; mat_t M; ctx_t ctxM; mon_t *rows, *cols; padic_mat_struct *C; fmpz_t p; fmpz_poly_mat_t B; long vB; printf("solve... \n"); fflush(stdout); /* Example 3-1-1 */ /* str = "3 [3 0 0] [0 3 0] [0 0 3] (2 0 1)[1 1 1]"; */ /* Example 3-3-2 */ /* str = "3 [3 0 0] [0 3 0] [0 0 3] (2 0 1)[2 1 0] (2 0 1)[0 2 1] (2 0 1)[1 0 2]"; */ /* Example 4-4-2 */ /* str = "4 [4 0 0 0] [0 4 0 0] [0 0 4 0] [0 0 0 4] (2 0 1)[3 1 0 0] (2 0 1)[1 0 1 2] (2 0 1)[0 1 0 3]"; */ /* Example ... */ /* str = "4 [4 0 0 0] [0 4 0 0] [0 0 4 0] [0 0 0 4] (2 0 1)[1 1 1 1]"; */ /* Example from AKR */ str = "4 (1 3)[0 3 0 0] (2 0 3)[0 1 2 0] " "(2 0 -1)[1 1 1 0] (2 0 3)[1 1 0 1] " "(2 0 -1)[2 1 0 0] [0 0 3 0] (2 0 -1)[1 0 2 0] " "(1 2)[0 0 0 3] [3 0 0 0]"; n = atoi(str) - 1; K = 616; N = 10; Nw = 22; fmpz_init(p); fmpz_set_ui(p, 5); ctx_init_fmpz_poly_q(ctxM); ctxM->print = &__fmpz_poly_q_print_pretty; mpoly_init(P, n + 1, ctxM); mpoly_set_str(P, str, ctxM); printf("P = "), mpoly_print(P, ctxM), printf("\n"); b = gmc_basis_size(n, mpoly_degree(P, -1, ctxM)); mat_init(M, b, b, ctxM); fmpz_poly_mat_init(B, b, b); vB = 0; gmc_compute(M, &rows, &cols, P, ctxM); mat_print(M, ctxM); printf("\n"); gmde_solve(&C, K, p, N, Nw, M, ctxM); gmde_convert_soln(B, &vB, C, K, p); printf("Solution to (d/dt + M) C = 0:\n"); fmpz_poly_mat_print(B, "t"); printf("vB = %ld\n", vB); gmde_check_soln(B, vB, p, N, K, M, ctxM); mpoly_clear(P, ctxM); mat_clear(M, ctxM); free(rows); free(cols); fmpz_poly_mat_clear(B); ctx_clear(ctxM); fmpz_clear(p); for (i = 0; i < K; i++) padic_mat_clear(C + i); free(C); _fmpz_cleanup(); return EXIT_SUCCESS; }
int main(void) { int i, result; flint_rand_t state; int c; __ctx_struct *ctx; ctx_t *CTX; printf("mul_vec... "); fflush(stdout); _randinit(state); CTX = malloc(2 * sizeof(ctx_t)); ctx_init_long(CTX[0]); ctx_init_mpq(CTX[1]); for (c = 0; c < 2; c++) { ctx = CTX[c]; /* A (x1 + x2) == A x1 + A x2 */ for (i = 0; i < 100; i++) { mat_csr_t A; long m, n; char *x1, *x2, *y, *z; m = n_randint(state, 100) + 1; n = n_randint(state, 100) + 1; mat_csr_init(A, m, n, ctx); x1 = _vec_init(n, ctx); x2 = _vec_init(n, ctx); y = _vec_init(m, ctx); z = _vec_init(m, ctx); mat_csr_randtest(A, state, 0.3, ctx); mat_csr_mul_vec(y, A, x1, ctx); mat_csr_mul_vec(z, A, x2, ctx); _vec_add(z, y, z, m, ctx); _vec_add(x1, x1, x2, n, ctx); mat_csr_mul_vec(y, A, x1, ctx); result = _vec_equal(y, z, m, ctx); if (!result) { printf("FAIL:\n\n"); abort(); } mat_csr_clear(A, ctx); _vec_clear(x1, n, ctx); _vec_clear(x2, n, ctx); _vec_clear(y, m, ctx); _vec_clear(z, m, ctx); } } ctx_clear(CTX[0]); ctx_clear(CTX[1]); free(CTX); _randclear(state); _fmpz_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }
int main(void) { int i; flint_rand_t state; printf("set_entry\n"); printf("---------\n"); fflush(stdout); _randinit(state); /* Run a single example */ { ctx_t ctx; mat_coo_t A; long x; ctx_init_long(ctx); /* [ 0 -4 1 ] [ 0 0 1 0 ] [ 2 0 0 -3 ] [ 0 1 0 0 ] */ mat_coo_init(A, 4, 4, ctx); x = -4; mat_coo_set_entry(A, 0, 1, &x, ctx); x = 1; mat_coo_set_entry(A, 0, 3, &x, ctx); x = 1; mat_coo_set_entry(A, 1, 2, &x, ctx); x = 2; mat_coo_set_entry(A, 2, 0, &x, ctx); x = -3; mat_coo_set_entry(A, 2, 3, &x, ctx); x = 1; mat_coo_set_entry(A, 3, 1, &x, ctx); printf("Matrix A (debug):\n"); mat_coo_debug(A, ctx); printf("\n"); printf("Matrix A (dense):\n"); mat_coo_print_dense(A, ctx); printf("\n"); mat_coo_clear(A, 1, ctx); ctx_clear(ctx); } printf("... "); /* Unmanaged type (long) */ for (i = 0; i < 1000; i++) { long m, n, z; double d; ctx_t ctx; mat_coo_t A; m = n_randint(state, 100) + 1; n = n_randint(state, 100) + 1; d = (double) n_randint(state, 101) / (double) 100; ctx_init_long(ctx); mat_coo_init(A, m, n, ctx); mat_coo_randtest(A, state, d, ctx); for (z = 0; z < 10; z++) { long row, col; long x; row = n_randint(state, m); col = n_randint(state, n); x = z_randtest_not_zero(state); mat_coo_set_entry(A, row, col, &x, ctx); } mat_coo_clear(A, 1, ctx); ctx_clear(ctx); } /* Managed type (mpq_t) */ for (i = 0; i < 1000; i++) { long m, n, z; double d; ctx_t ctx; mat_coo_t A; m = n_randint(state, 100) + 1; n = n_randint(state, 100) + 1; d = (double) n_randint(state, 101) / (double) 100; ctx_init_mpq(ctx); mat_coo_init(A, m, n, ctx); mat_coo_randtest(A, state, d, ctx); for (z = 0; z < 10; z++) { long row, col; mpq_t x; row = n_randint(state, m); col = n_randint(state, n); mpq_init(x); ctx->randtest_not_zero(ctx, x, state); mat_coo_set_entry(A, row, col, &x, ctx); mpq_clear(x); } mat_coo_clear(A, 1, ctx); ctx_clear(ctx); } _randclear(state); _fmpz_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }
int main(void) { int i, result; flint_rand_t state; printf("block_triangularise\n"); printf("-------------------\n"); fflush(stdout); _randinit(state); /* Run a single example, with output(?) */ { long m, n; mat_csr_t A; ctx_t ctx; long *P, *Q, *B, nz, b; ctx_init_long(ctx); m = n = 10; P = malloc(n * sizeof(long)); Q = malloc(n * sizeof(long)); B = malloc(n * sizeof(long)); mat_csr_init(A, m, n, ctx); mat_csr_randtest(A, state, 0.3, ctx); printf("Matrix A:\n"); mat_csr_print_dense(A, ctx); printf("\n"); nz = mat_csr_zfdiagonal(P, A); printf("Matrix A:\n"); mat_csr_permute_rows(A, P, ctx); mat_csr_print_dense(A, ctx); printf("\n"); b = mat_csr_block_triangularise(Q, B, A, ctx); printf("Matrix A:\n"); mat_csr_permute_rows(A, Q, ctx); mat_csr_permute_cols(A, Q, ctx); mat_csr_print_dense(A, ctx); printf("\n"); printf("Blocks B:"); _long_vec_print(B, b); printf("\n"); free(P); free(Q); free(B); mat_csr_clear(A, ctx); ctx_clear(ctx); } printf("... "); for (i = 0; i < 1000; i++) { long m, n; mat_csr_t A; ctx_t ctx; long *P, *Q, *B, nz, b; ctx_init_long(ctx); m = n = 100; P = malloc(n * sizeof(long)); Q = malloc(n * sizeof(long)); B = malloc(n * sizeof(long)); mat_csr_init(A, m, n, ctx); mat_csr_randtest(A, state, 0.03, ctx); nz = mat_csr_zfdiagonal(P, A); mat_csr_permute_rows(A, P, ctx); b = mat_csr_block_triangularise(Q, B, A, ctx); mat_csr_permute_rows(A, Q, ctx); mat_csr_permute_cols(A, Q, ctx); result = _is_block_triangular(A, B, b); if (!result) { printf("FAIL:\n\n"); abort(); } free(P); free(Q); free(B); mat_csr_clear(A, ctx); ctx_clear(ctx); } _randclear(state); _fmpz_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }
krb5_error_code krb5_db2_promote_db(krb5_context context, char *conf_section, char **db_args) { krb5_error_code retval; krb5_boolean merge_nra = FALSE, real_locked = FALSE; krb5_db2_context *dbc_temp, *dbc_real = NULL; char **db_argp; /* context must be initialized with an exclusively locked temp DB. */ if (!inited(context)) return KRB5_KDB_DBNOTINITED; dbc_temp = context->dal_handle->db_context; if (dbc_temp->db_lock_mode != KRB5_LOCKMODE_EXCLUSIVE) return KRB5_KDB_NOTLOCKED; if (!dbc_temp->tempdb) return EINVAL; /* Check db_args for whether we should merge non-replicated attributes. */ for (db_argp = db_args; *db_argp; db_argp++) { if (!strcmp(*db_argp, "merge_nra")) { merge_nra = TRUE; break; } } /* Make a db2 context for the real DB. */ dbc_real = k5alloc(sizeof(*dbc_real), &retval); if (dbc_real == NULL) return retval; ctx_clear(dbc_real); /* Try creating the real DB. */ dbc_real->db_name = strdup(dbc_temp->db_name); if (dbc_real->db_name == NULL) goto cleanup; dbc_real->tempdb = FALSE; retval = ctx_create_db(context, dbc_real); if (retval == EEXIST) { /* The real database already exists, so open and lock it. */ dbc_real->db_name = strdup(dbc_temp->db_name); if (dbc_real->db_name == NULL) goto cleanup; dbc_real->tempdb = FALSE; retval = ctx_init(dbc_real); if (retval) goto cleanup; retval = ctx_lock(context, dbc_real, KRB5_DB_LOCKMODE_EXCLUSIVE); if (retval) goto cleanup; } else if (retval) goto cleanup; real_locked = TRUE; if (merge_nra) { retval = ctx_merge_nra(context, dbc_temp, dbc_real); if (retval) goto cleanup; } /* Perform filesystem manipulations for the promotion. */ retval = ctx_promote(context, dbc_temp, dbc_real); if (retval) goto cleanup; /* Unlock and finalize context since the temp DB is gone. */ (void) krb5_db2_unlock(context); krb5_db2_fini(context); cleanup: if (real_locked) (void) ctx_unlock(context, dbc_real); if (dbc_real) ctx_fini(dbc_real); return retval; }
/* free the context (this is installed as handler into PAM) */ static void ctx_free(pam_handle_t UNUSED(*pamh),void *data,int UNUSED(err)) { struct pld_ctx *ctx=data; ctx_clear(ctx); free(ctx); }
/* Initialize dbc by locking and creating the DB. If the DB already exists, * clear it out if dbc->tempdb is set; otherwise return EEXIST. */ static krb5_error_code ctx_create_db(krb5_context context, krb5_db2_context *dbc) { krb5_error_code retval = 0; char *dbname = NULL, *polname = NULL, *plockname = NULL; retval = ctx_allfiles(dbc, &dbname, &dbc->db_lf_name, &polname, &plockname); if (retval) return retval; dbc->db_lf_file = open(dbc->db_lf_name, O_CREAT | O_RDWR | O_TRUNC, 0600); if (dbc->db_lf_file < 0) { retval = errno; goto cleanup; } retval = krb5_lock_file(context, dbc->db_lf_file, KRB5_LOCKMODE_EXCLUSIVE | KRB5_LOCKMODE_DONTBLOCK); if (retval != 0) goto cleanup; set_cloexec_fd(dbc->db_lf_file); dbc->db_lock_mode = KRB5_LOCKMODE_EXCLUSIVE; dbc->db_locks_held = 1; if (dbc->tempdb) { /* Temporary DBs are locked for their whole lifetime. Since we have * the lock, any remnant files can be safely destroyed. */ (void) destroy_file(dbname); (void) unlink(polname); (void) unlink(plockname); } dbc->db = open_db(dbc, O_RDWR | O_CREAT | O_EXCL, 0600); if (dbc->db == NULL) { retval = errno; goto cleanup; } /* Create the policy database, initialize a handle to it, and lock it. */ retval = osa_adb_create_db(polname, plockname, OSA_ADB_POLICY_DB_MAGIC); if (retval) goto cleanup; retval = osa_adb_init_db(&dbc->policy_db, polname, plockname, OSA_ADB_POLICY_DB_MAGIC); if (retval) goto cleanup; retval = osa_adb_get_lock(dbc->policy_db, KRB5_DB_LOCKMODE_EXCLUSIVE); if (retval) goto cleanup; dbc->db_inited = 1; cleanup: if (retval) { if (dbc->db != NULL) dbc->db->close(dbc->db); if (dbc->db_locks_held > 0) { (void) krb5_lock_file(context, dbc->db_lf_file, KRB5_LOCKMODE_UNLOCK); } if (dbc->db_lf_file >= 0) close(dbc->db_lf_file); ctx_clear(dbc); } free(dbname); free(polname); free(plockname); return retval; }
int main(void) { int i, result; flint_rand_t state; printf("zero... "); fflush(stdout); _randinit(state); /* Unmanaged element type (long) */ for (i = 0; i < 100; i++) { long m, n; ctx_t ctx; mat_t A; m = n_randint(state, 100) + 1; n = n_randint(state, 100) + 1; ctx_init_long(ctx); mat_init(A, m, n, ctx); mat_randtest(A, state, ctx); mat_zero(A, ctx); result = mat_is_zero(A, ctx); if (!result) { printf("FAIL:\n\n"); printf("Matrix A\n"); mat_print(A, ctx); printf("\n"); abort(); } mat_clear(A, ctx); ctx_clear(ctx); } /* Managed element type (mpq_t) */ for (i = 0; i < 100; i++) { long m, n; ctx_t ctx; mat_t A; m = n_randint(state, 100) + 1; n = n_randint(state, 100) + 1; ctx_init_mpq(ctx); mat_init(A, m, n, ctx); mat_randtest(A, state, ctx); mat_zero(A, ctx); result = mat_is_zero(A, ctx); if (!result) { printf("FAIL:\n\n"); printf("Matrix A\n"); mat_print(A, ctx); printf("\n"); abort(); } mat_clear(A, ctx); ctx_clear(ctx); } _randclear(state); _fmpz_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }
int main(void) { int i, result; flint_rand_t state; printf("transpose... "); fflush(stdout); _randinit(state); /* Check aliasing */ /* Unmanaged element type (long) */ for (i = 0; i < 100; i++) { long m, n; ctx_t ctx; mat_t A, B, C; m = n_randint(state, 50) + 1; n = m; ctx_init_long(ctx); mat_init(A, m, n, ctx); mat_init(B, m, n, ctx); mat_init(C, m, n, ctx); mat_randtest(A, state, ctx); mat_set(B, A, ctx); mat_transpose(C, B, ctx); mat_transpose(B, B, ctx); result = mat_equal(B, C, ctx); if (!result) { printf("FAIL:\n\n"); printf("Matrix A\n"); mat_print(A, ctx); printf("\n"); printf("Matrix B\n"); mat_print(B, ctx); printf("\n"); printf("Matrix C\n"); mat_print(C, ctx); printf("\n"); } mat_clear(A, ctx); mat_clear(B, ctx); mat_clear(C, ctx); ctx_clear(ctx); } /* Check that (A^t)^t == A */ /* Unmanaged element type (long) */ for (i = 0; i < 100; i++) { long m, n; ctx_t ctx; mat_t A, B, C; m = n_randint(state, 50) + 1; n = n_randint(state, 50) + 1; ctx_init_long(ctx); mat_init(A, m, n, ctx); mat_init(B, n, m, ctx); mat_init(C, m, n, ctx); mat_randtest(A, state, ctx); mat_transpose(B, A, ctx); mat_transpose(C, B, ctx); result = mat_equal(A, C, ctx); if (!result) { printf("FAIL:\n\n"); printf("Matrix A\n"); mat_print(A, ctx); printf("\n"); printf("Matrix B\n"); mat_print(B, ctx); printf("\n"); printf("Matrix C\n"); mat_print(C, ctx); printf("\n"); } mat_clear(A, ctx); mat_clear(B, ctx); mat_clear(C, ctx); ctx_clear(ctx); } _randclear(state); _fmpz_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }