Problem read_data(std::string const &dense_path, std::string const &sparse_path) { Problem prob(get_nr_line(dense_path), get_nr_field(dense_path)); read_dense(prob, dense_path); read_sparse(prob, sparse_path); return prob; }
/*========================================== * main *========================================== */ int main(int argc, char* argv[]) { int i, t, d, **dt, dtot; //double alpha; char **doc; FILE *fp; int *prob_t_given_d, *indx; int T; // number of topics int D; // number of docs if (argc != 1) { fprintf(stderr, "usage: %s\n", argv[0]); exit(-1); } dt = read_sparse("Ndt.txt",&D,&T); assert(D>0); assert(T>0); fp = fopen("docs.txt","r"); assert(fp); doc = (char**)malloc(D*sizeof(char*)); assert(doc); for (d = 0; d < D; d++) { doc[d] = (char*)malloc(100*sizeof(char)); fscanf(fp,"%s",doc[d]); } fclose(fp); prob_t_given_d = ivec(T); indx = ivec(T); for (d = 0; d < D; d++) { printf("<%s> ", doc[d]); dtot = 0; for (t = 0; t < T; t++) { prob_t_given_d[t] = dt[d][t]; dtot += dt[d][t]; } isort(T, prob_t_given_d, -1, indx); for (i = 0; i < 4; i++) { if ((1.0*dt[d][indx[i]])/dtot > 0.1) printf("t%d ", indx[i]+1); } printf("\n"); } return 0; }
static bool read_data(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo) { bool bRet = false; _pInfo->iType = getScilabTypeFromDataSet(_iDatasetId); switch (_pInfo->iType) { case sci_matrix: { bRet = read_double(_iDatasetId, _iItemPos, _piAddress, _pInfo); break; } case sci_strings: { bRet = read_string(_iDatasetId, _iItemPos, _piAddress, _pInfo); break; } case sci_list: case sci_tlist: case sci_mlist: { bRet = read_list(_iDatasetId, _pInfo->iType, _iItemPos, _piAddress, _pInfo); break; } case sci_boolean: { bRet = read_boolean(_iDatasetId, _iItemPos, _piAddress, _pInfo); break; } case sci_poly: { bRet = read_poly(_iDatasetId, _iItemPos, _piAddress, _pInfo); break; } case sci_ints: { bRet = read_integer(_iDatasetId, _iItemPos, _piAddress, _pInfo); break; } case sci_sparse: { bRet = read_sparse(_iDatasetId, _iItemPos, _piAddress, _pInfo); break; } case sci_boolean_sparse: { bRet = read_boolean_sparse(_iDatasetId, _iItemPos, _piAddress, _pInfo); break; } case sci_void: //void item only on list variable { bRet = read_void(_iDatasetId, _iItemPos, _piAddress, _pInfo); break; } case sci_undefined: //undefined item only on list variable { bRet = read_undefined(_iDatasetId, _iItemPos, _piAddress, _pInfo); break; } default: { Scierror(999, _("%s: Invalid HDF5 Scilab format.\n"), "listvar_in_hdf5"); break; } } return bRet; }
int main(int argc, char **argv) { char *filename = "dio_sparse"; int pid[NUM_CHILDREN]; int num_children = 1; int i; long alignment = 512; int writesize = 65536; int filesize = 100 * 1024 * 1024; int offset = 0; int c; int children_errors = 0; int ret; while ((c = getopt(argc, argv, "dw:n:a:s:o:")) != -1) { char *endp; switch (c) { case 'd': debug++; break; case 'a': alignment = strtol(optarg, &endp, 0); alignment = scale_by_kmg(alignment, *endp); break; case 'w': writesize = strtol(optarg, &endp, 0); writesize = scale_by_kmg(writesize, *endp); break; case 's': filesize = strtol(optarg, &endp, 0); filesize = scale_by_kmg(filesize, *endp); break; case 'o': offset = strtol(optarg, &endp, 0); offset = scale_by_kmg(offset, *endp); break; case 'n': num_children = atoi(optarg); if (num_children > NUM_CHILDREN) { fprintf(stderr, "number of children limited to %d\n", NUM_CHILDREN); num_children = NUM_CHILDREN; } break; case '?': usage(); break; } } setup(); tst_resm(TINFO, "Dirtying free blocks"); dirty_freeblocks(filesize); fd = SAFE_OPEN(cleanup, filename, O_DIRECT | O_WRONLY | O_CREAT | O_EXCL, 0600); SAFE_FTRUNCATE(cleanup, fd, filesize); tst_resm(TINFO, "Starting I/O tests"); signal(SIGTERM, SIG_DFL); for (i = 0; i < num_children; i++) { switch (pid[i] = fork()) { case 0: SAFE_CLOSE(NULL, fd); read_sparse(filename, filesize); break; case -1: while (i-- > 0) kill(pid[i], SIGTERM); tst_brkm(TBROK | TERRNO, cleanup, "fork()"); default: continue; } } tst_sig(FORK, DEF_HANDLER, cleanup); ret = dio_sparse(fd, alignment, writesize, filesize, offset); tst_resm(TINFO, "Killing childrens(s)"); for (i = 0; i < num_children; i++) kill(pid[i], SIGTERM); for (i = 0; i < num_children; i++) { int status; pid_t p; p = waitpid(pid[i], &status, 0); if (p < 0) { tst_resm(TBROK | TERRNO, "waitpid()"); } else { if (WIFEXITED(status) && WEXITSTATUS(status) == 10) children_errors++; } } if (children_errors) tst_resm(TFAIL, "%i children(s) exited abnormally", children_errors); if (!children_errors && !ret) tst_resm(TPASS, "Test passed"); cleanup(); tst_exit(); }
static bool read_data(int dataset, VarInfo6& info) { bool bRet = false; char* ctype = getScilabTypeFromDataSet6(dataset); std::string type(ctype); FREE(ctype); info.ctype = type; if (type == g_SCILAB_CLASS_DOUBLE) { info.type = sci_matrix; return read_double(dataset, info); } if (type == g_SCILAB_CLASS_STRING) { info.type = sci_strings; return read_string(dataset, info); } if (type == g_SCILAB_CLASS_LIST) { info.type = sci_list; return read_list(dataset, info, "list"); } if (type == g_SCILAB_CLASS_TLIST) { info.type = sci_tlist; return read_list(dataset, info, "tlist"); } if (type == g_SCILAB_CLASS_MLIST) { info.type = sci_mlist; return read_list(dataset, info, "mlist"); } if (type == g_SCILAB_CLASS_BOOLEAN) { info.type = sci_boolean; return read_boolean(dataset, info); } if (type == g_SCILAB_CLASS_POLY) { info.type = sci_poly; return read_poly(dataset, info); } if (type == g_SCILAB_CLASS_INT) { info.type = sci_ints; return read_integer(dataset, info); } if (type == g_SCILAB_CLASS_SPARSE) { info.type = sci_sparse; return read_sparse(dataset, info); } if (type == g_SCILAB_CLASS_BSPARSE) { info.type = sci_boolean_sparse; return read_boolean_sparse(dataset, info); } if (type == g_SCILAB_CLASS_VOID) { info.type = sci_void; return read_void(dataset, info); } if (type == g_SCILAB_CLASS_UNDEFINED) { info.type = sci_undefined; return read_undefined(dataset, info); } if (type == g_SCILAB_CLASS_STRUCT) { info.type = sci_mlist; return read_struct(dataset, info); } if (type == g_SCILAB_CLASS_CELL) { info.type = sci_mlist; return read_cell(dataset, info); } if (type == g_SCILAB_CLASS_HANDLE) { info.type = sci_handles; return read_handles(dataset, info); } if (type == g_SCILAB_CLASS_MACRO) { info.type = sci_c_function; return read_macro(dataset, info); } Scierror(999, _("%s: Invalid HDF5 Scilab format.\n"), "listvar_in_hdf5"); return false; }