sbdi_error_t sbdi_bc_cache_blk_i(uint32_t idx, sbdi_block_t *blk) { blk->idx = idx; sbdi_error_t r = sbdi_bc_cache_blk(cache, blk, SBDI_BC_BT_DATA); if (r != SBDI_SUCCESS) { std::cout << err_to_string(r) << std::endl; } return r; }
void read(unsigned char *buf, size_t len, off_t off) { ssize_t rd = 0; sbdi_error_t r = sbdi_pread(&rd, sbdi, buf, len, off); if (r != SBDI_SUCCESS) { std::cout << "Reading file @ offset " << off << ". Error: " << err_to_string(r) << std::endl; } CPPUNIT_ASSERT(r == SBDI_SUCCESS); }
void write(unsigned char *buf, size_t len, off_t off) { ssize_t wr = 0; sbdi_error_t r = sbdi_pwrite(&wr, sbdi, buf, len, off); if (r != SBDI_SUCCESS) { std::cout << "Writing file @ offset " << off << ". Error: " << err_to_string(r) << std::endl; } CPPUNIT_ASSERT(r == SBDI_SUCCESS); }
/** * Gets a textual error message representing the last error, if there is one. * instance: an instance of Gunderscript. * returns: an error message, or NULL if there are no errors. */ GSAPI const char * gunderscript_err_message(Gunderscript * instance) { assert(instance != NULL); if(gunderscript_get_err(instance) == GUNDERSCRIPTERR_BUILDERR) { assert(instance->compiler != NULL); if(compiler_get_err(instance->compiler) == COMPILERERR_LEXER_ERR) { return lexer_err_to_string(compiler_lex_err(instance->compiler)); } else { return compiler_err_to_string(instance->compiler, compiler_get_err(instance->compiler)); } } else if(gunderscript_get_err(instance) == GUNDERSCRIPTERR_EXECERR) { return vm_err_to_string(vm_get_err(instance->vm)); } else { return err_to_string(gunderscript_get_err(instance)); } }
void dhcpmsg(int errlevel, const char *fmt, ...) { va_list ap; char buf[512]; char *errmsg; if ((errlevel == MSG_DEBUG2 && (debug_level < 2)) || (errlevel == MSG_DEBUG && (debug_level < 1)) || (errlevel == MSG_VERBOSE && !is_verbose)) return; va_start(ap, fmt); /* * either log to stderr, or log to syslog. print out unix * error message if errlevel is MSG_ERR and errno is set */ if (is_daemon) { (void) snprintf(buf, sizeof (buf), (errlevel == MSG_ERR && errno != 0) ? "%s: %%m\n" : "%s\n", gettext(fmt)); (void) vsyslog(err_to_syslog(errlevel), buf, ap); } else { errmsg = strerror(errno); if (errmsg == NULL) errmsg = dgettext(TEXT_DOMAIN, "<unknown error>"); (void) snprintf(buf, sizeof (buf), (errlevel == MSG_ERR && errno != 0) ? "%s: %s: %s: %s\n" : "%s: %s: %s\n", program, dgettext(TEXT_DOMAIN, err_to_string(errlevel)), gettext(fmt), errmsg); (void) vfprintf(stderr, buf, ap); } va_end(ap); }
int main(int argc, char *argv[]) { char *program_name = argv[0]; double l2_sigma_sq = 0.0; int grafting = 0; int grafting_light = 0; lbfgs_parameter_t params; lbfgs_parameter_init(¶ms); params.past = 1; params.delta = 1e-7; int ch; while ((ch = getopt_long(argc, argv, "", longopts, NULL)) != -1) { switch (ch) { case OPTION_FTOL: params.ftol = str_to_double(optarg); break; case OPTION_GTOL: params.gtol = str_to_double(optarg); break; case OPTION_GRAFTING: grafting = str_to_int(optarg); break; case OPTION_GRAFTING_LIGHT: grafting_light = str_to_int(optarg); break; case OPTION_L1: params.orthantwise_c = str_to_double(optarg); break; case OPTION_L2: l2_sigma_sq = str_to_double(optarg); break; case OPTION_LINESEARCH: if (strcmp(optarg, "armijo") == 0) params.linesearch = LBFGS_LINESEARCH_BACKTRACKING_ARMIJO; else if (strcmp(optarg, "backtracking") == 0) params.linesearch = LBFGS_LINESEARCH_BACKTRACKING; else if (strcmp(optarg, "wolfe") == 0) params.linesearch = LBFGS_LINESEARCH_BACKTRACKING_WOLFE; else if (strcmp(optarg, "strong_wolfe") == 0) params.linesearch = LBFGS_LINESEARCH_BACKTRACKING_STRONG_WOLFE; else { usage(program_name); return 1; } break; case OPTION_MINSTEP: fprintf(stderr,"backtracking\n"); params.min_step = str_to_double(optarg); break; case OPTION_MAXSTEP: params.max_step = str_to_double(optarg); break; case '?': default: usage(program_name); return 1; } } argc -= optind; argv += optind; if (argc != 0 && argc != 1) { usage(program_name); return 1; } if (grafting && grafting_light) { fprintf(stderr, "Grafting and grafting-light cannot be used simultaneously..."); return 1; } if ((grafting || grafting_light) && params.orthantwise_c == 0.) { fprintf(stderr, "Grafting requires a l1 norm coefficient..."); return 1; } fprintf(stderr, "l1 norm coefficient: %.4e\n", params.orthantwise_c); fprintf(stderr, "l2 prior sigma^2: %.4e\n\n", l2_sigma_sq); dataset_t ds; int fd = 0; if (argc == 1 && (fd = open(argv[0], O_RDONLY)) == -1) { fprintf(stderr, "Could not open %s\n", argv[0]); return 1; } int r = read_tadm_dataset(fd, &ds); if (r != TADM_OK) { fprintf(stderr, "Error reading data...\n"); return 1; } fprintf(stderr, "Features: %zu\n", ds.n_features); fprintf(stderr, "Contexts: %zu\n\n", ds.n_contexts); if (params.orthantwise_c != 0.0) { params.orthantwise_end = ds.n_features; // l1 prior only works with backtracking linesearch. params.linesearch = LBFGS_LINESEARCH_BACKTRACKING; } model_t model; if (grafting || grafting_light) model_new(&model, ds.n_features, true); else model_new(&model, ds.n_features, false); fprintf(stderr, "Iter\t-LL\t\txnorm\t\tgnorm\n\n"); if (grafting) r = maxent_lbfgs_grafting(&ds, &model, ¶ms, l2_sigma_sq, grafting); else if (grafting_light) r = maxent_lbfgs_grafting_light(&ds, &model, ¶ms, l2_sigma_sq, grafting_light); else r = maxent_lbfgs_optimize(&ds, &model, ¶ms, l2_sigma_sq); dataset_free(&ds); if (r != LBFGS_STOP && r != LBFGS_SUCCESS && r != LBFGS_ALREADY_MINIMIZED) { fprintf(stderr, "%s\n\n", err_to_string(lbfgs_errs, r)); model_free(&model); return 1; } for (int i = 0; i < ds.n_features; ++i) printf("%.8f\n", model.params[i]); model_free(&model); return 0; }