size_t DataSet::readDataFile (size_t len, size_t in, size_t out, FILE *f)
{
    REAL *r_in, *r_out;

    assert(f != NULL);
    assert(x != NULL && y != NULL);

    r_in  = rv_alloc(in);
    r_out = rv_alloc(out);

    size_t i, j;
    for (i = 0; i < len; i++) {
        for (j = 0; j < in; j++) {
            int c = fscanf(f, "%lf", &r_in[j]);
            if (c < 1) {
                /*fprintf(stderr, "rv_read: line too short (%d)\n", i);*/
                goto exit_readfile;
            }
        }

        for (j = 0; j < out; j++) {
            int c = fscanf(f, "%lf", &r_out[j]);
            if (c < 1) goto exit_readfile;
        }

        if (!x->appendData(1, in, &r_in) || !y->appendData(1, out, &r_out))
            break;
    }

exit_readfile:
    rv_free(r_in);
    rv_free(r_out);
    return i;
}
void NNLayer::free_space () {
    rm_free(weight, n_neuron);
    rm_free(wbackup, n_neuron);
    rm_free(wdelta, n_neuron);
    rm_free(wdel_old, n_neuron);
    rm_free(wdir, n_neuron);
    rv_free(sig_der);
    n_input = n_neuron = 0;
}
Exemplo n.º 3
0
int rv_map_delete(rv_map *map, rv_map_item *item) {
    RV_CHECK(map);
    if (!item)
        return ERR;
    if (!item->prev) {
        // first item in slot, must resolve slot index for deletion
        rv_map_slot *slot = map->root + get_slot_index(map, item->key);
        slot->first = item->next;
        slot->first->prev = NULL;
    }
    else {
        item->prev->next = item->next;
        if (!item->next)
            item->next->prev = item->prev;
    }
    rv_free(item->key);
    rv_free(item);
    map->count--;
    return 0;
}
Exemplo n.º 4
0
int rv_map_clear(rv_map *map, bool init) {
    RV_CHECK(map);
    if (map->count) {
        rv_map_item *cur;
        rv_map_item *tmp;
        for (uint i = 0; i < map->slots; i++) {
            cur = map->root[i].first;
            while (cur) {
                tmp = cur->next;
                rv_free(cur->key);
                rv_free(cur);
                cur = tmp;
            }
        }
        map->count = 0;
        if (init)
            memset(map->root, 0, sizeof(rv_map_slot) * map->slots);
    }
    return 0;
}
Exemplo n.º 5
0
void rv_map_destroy(rv_map *map) {
    rv_map_clear(map, false);
    rv_free(map->root);
}