コード例 #1
0
ファイル: flag_x.c プロジェクト: FredericCosnefroy/ft_printf
int					flag_x(t_format f, va_list *ap)
{
	unsigned long long int		nb;
	char						c;
	int							left;
	int							len;

	left = (ft_strchr(f.flags, '-') ? 0 : 1);
	nb = get_unsigned_arg(f.modifier, ap);
	get_out(&f, nb, &c);
	len = 0;
	if ((left ? c : ' ') != '0')
		f.out = add_prefix(&f, nb);
	else
	{
		if (ft_strchr(f.flags, '#') && nb != 0)
			len -= 2;
	}
	len += f.length - ft_strlen(f.out);
	f.out = add_string(&f, len, (left ? c : ' '), left);
	if ((left ? c : ' ') == '0')
		f.out = add_prefix(&f, nb);
	ft_putstr(f.out);
	len = ft_strlen(f.out);
	free(f.out);
	return (len);
}
コード例 #2
0
ファイル: pattern.c プロジェクト: Mougatine/ocr
void train_nn(struct net nwk, struct training t)
{
    unsigned epoch = 0;
    unsigned freq = 500;
    unsigned limit = 5000;

    do {
        unsigned error = 0;

        for (size_t i = 0; i < t.n_set; ++i) {
            net_compute(nwk, get_in(&t, i));
            net_error(nwk, get_out(&t, i));

            if (epoch % freq == 0) {
                char c = convert_output(get_out(&t, i), 52);
                char rst = convert_output(net_output(nwk), 52);
                if (c != rst) {
                    printf("In: %c\t", c);
                    printf("Out: %c\n", rst);
                    ++error;
                }
            }
        }

        if (epoch % freq == 0) {
            printf("[%d] ERROR: %d\n", epoch, error);
            printf("******************\n");
        }

        ++epoch;

        if (epoch == limit) {
            printf("Continue? ");
            int b = 0;
            scanf("%d", &b);
            if (b)
                epoch = 0;
        }

    } while(epoch < limit);
}
コード例 #3
0
ファイル: api_io.cpp プロジェクト: antkar/syncpp
void rt::TextOutputValue::api_print(const gc::Local<ExecContext>& context, const gc::Local<Value>& value) {
	std::ostream& out = get_out();
	rt::OperandType type = value->get_operand_type();
	if (rt::OperandType::INTEGER == type) {
		out << value->get_integer();
	} else if (rt::OperandType::STRING == type) {
		out << value->get_string();
	} else if (rt::OperandType::FLOAT == type) {
		out << value->get_float();
	} else if (rt::OperandType::BOOLEAN == type) {
		out << (value->get_boolean() ? "true" : "false");
	} else {
		out << value->to_string(context);
	}
	if (out.fail()) throw RuntimeError("Write error");
}
コード例 #4
0
ファイル: update_ncurses.c プロジェクト: gperroch/Corewar-C
void			update_ncurses(t_core *c)
{
	unsigned int		ch;

	if ((c->ncycles % c->ncurse_refresh) == 0 || c->debug_mode == 1)
		update_screen(c, 1);
	if (c->debug_mode)
	{
		pause_menu(c);
		return ;
	}
	ch = getch();
	if (ch == 'q')
		get_out();
	else if (ch == KEY_UP && (c->ncurse_refresh < 500))
		c->ncurse_refresh++;
	else if (ch == KEY_DOWN && (c->ncurse_refresh > 1))
		c->ncurse_refresh--;
	else if (ch == ' ')
		pause_menu(c);
}
コード例 #5
0
ファイル: pattern.c プロジェクト: Mougatine/ocr
struct training load_pattern(char *dir)
{
    char path[2048];
    char filename[2048];
    t_img_desc *img;

    strcpy(path, dir);
    for (dir = path; *dir; ++dir);
    if (*(--dir) != '/')
        strcat(path, "/");

    const size_t n_font = 7;
    const size_t n_letter = 52;
    const size_t n_set = n_letter * n_font;
    const size_t size_in = 400;
    const size_t size_out = 52;

    struct training t = { NULL, NULL, n_set, size_in, size_out };
    t.in = malloc(sizeof(double) * t.n_in * t.n_set);
    assert(t.in);
    t.out = malloc(sizeof(double) * t.n_out * t.n_set);
    assert(t.out);

    for (size_t f = 0; f < n_font; ++f) {
        /* Lower */
        for (size_t l = 0; l < n_letter / 2; ++l) {
            sprintf(filename, "%s%s/%c/%lu.png", path, "lower",
                    (char)l+'A', f);

            img = load_image(filename, 1);
            printf("[INFO] Load %s (%ix%i -- %i)\n", filename,
                    img->x, img->y, img->comp);

            process_pattern(img, 1);

            size_t line = l + f * n_letter;
            gen_input(img, get_in(&t, line));
            gen_output(get_out(&t, line), size_out, (char)l+'a');

            free_image(img);
        }

        /* Upper */
        for (size_t l = 0; l < n_letter / 2; ++l) {
            sprintf(filename, "%s%s/%c/%lu.png", path, "upper",
                    (char)l+'A', f);

            img = load_image(filename, 1);
            printf("[INFO] Load %s (%ix%i -- %i)\n", filename,
                    img->x, img->y, img->comp);

            process_pattern(img, 1);

            size_t line = (l + 26) + f * n_letter;
            gen_input(img, get_in(&t, line));
            gen_output(get_out(&t, line), size_out, (char)l+'A');

            free_image(img);
        }
    }

    return t;
}
コード例 #6
0
ファイル: api_io.cpp プロジェクト: antkar/syncpp
void rt::TextOutputValue::api_println_0(const gc::Local<ExecContext>& context) {
	std::ostream& out = get_out();
	out << std::endl;
	if (out.fail()) throw RuntimeError("Write error");
}