void EigenVectors::InitMatrix(DMatrix &dmat, int size) const { if(!dmat.empty()) { dmat.clear(); } DArray darr(size, 0.); dmat.reserve(size); for(int i = 0; i < size; ++i) { dmat.push_back(darr); } }
model_t load_model(char *modelfile, double Z) { model_t m = _d_calloc(1, sizeof(struct model_s)); char **toks = NULL; // array to tokenize each line size_t len1 = 0; // length of the first line (used as upper bound on number of toks) // msg("Reading %s...", modelfile); forline (line, modelfile) { line[strlen(line)-1] = 0; // chop newline if (len1 == 0) { len1 = strlen(line); toks = _d_calloc(len1, sizeof(char *)); } size_t n = split(line, "\t", toks, len1); if (m->ndim == 0) { m->ndim = n - 2; } assert(n == m->ndim + 2); char *ptr = NULL; long int index = strtol(toks[0], &ptr, 10); assert(ptr > toks[0] && *ptr == ':' && index >= 0); if (index >= m->ntok) { size_t oldn = m->ntok; m->ntok = index + 1; m->v = _d_realloc(m->v, m->ntok * sizeof(darr_t)); m->n = _d_realloc(m->n, m->ntok * sizeof(size_t)); m->z = _d_realloc(m->z, m->ntok * sizeof(double)); for (int i = oldn; i < m->ntok; i++) { m->v[i] = darr(0, svec_t); m->n[i] = 0; m->z[i] = 0; } } char *token = ptr+1; svec_t s = svec(m->v[index], token); assert(!strcmp(s->key, token)); long int count = strtol(toks[1], &ptr, 10); assert(ptr > toks[1] && *ptr == 0 && count > 0); assert(s->cnt == 0); s->cnt = count; m->n[index] += count; assert(s->vec == NULL); s->vec = _d_calloc(m->ndim, sizeof(float)); for (size_t i = 0; i < m->ndim; i++) { s->vec[i] = strtof(toks[i+2], &ptr); assert(ptr > toks[i+2] && *ptr == 0); } }