void init(int argc, char** argv){ if (argc != 2 || atoi(argv[1]) <= 0) exit(1); numUnixProcess = atoi(argv[1]); //Read Files readMatrix("ini1.txt", &mAlines, &mAcolumns, &matrixA); readMatrix("ini2.txt", &mBlines, &mBcolumns, &matrixB); //check if (mAcolumns != mBlines){ printf("Can't multiply.\n\n"); exit(1); } mResultlines = mAlines; mResultcolumns = mBcolumns; matrixResult = (int*) mmap(0, mResultlines * mResultcolumns * sizeof(int), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANON,-1,0); if (numUnixProcess > mResultlines){ numUnixProcess = mResultlines; } }
void ManipTool::load_parameters(std::string fn_nv, std::string fn_rorate,std::string fn_trans,std::string fixed_rel){ if((is_file_exist(fn_nv.c_str()) == true)&&(is_file_exist(fn_rorate.c_str()) == true)&&\ (is_file_exist(fn_trans.c_str()) == true)&&(is_file_exist(fixed_rel.c_str()) == true)){ f_nv.open(fn_nv.c_str()); ts.rel_o = readMatrix(f_nv); f_nv.close(); f_fixed_rel_o.open(fixed_rel.c_str()); ts.m_fixed_rel_o= readMatrix(f_fixed_rel_o); f_fixed_rel_o.close(); f_rotate.open(fn_rorate.c_str()); ts.rotate_s2sdot = readMatrix(f_rotate); f_rotate.close(); f_trans.open(fn_trans.c_str()); est_trans = readMatrix(f_trans); std::cout<<"init position "<<est_trans<<std::endl; std::cout<<"rel_o "<<ts.rel_o<<std::endl; std::cout<<"rotation are "<<ts.rotate_s2sdot<<std::endl; f_trans.close(); // est_trans(0) += 0.5*(double) rand() / (RAND_MAX); // est_trans(1) += 0.5*(double) rand() / (RAND_MAX); // est_trans(2) += 0.5*(double) rand() / (RAND_MAX); } else{ std::cout<<"tool parameters files are not exist"<<std::endl; exit(0); } }
void main() { int A[MAXROWS][MAXCOLS], B[MAXROWS][MAXCOLS], C[MAXROWS][MAXCOLS]; int M, N; /*Function declarations*/ void readMatrix(int arr[][MAXCOLS], int M, int N); void printMatrix(int arr[][MAXCOLS], int M, int N); void productMatrix(int A[][MAXCOLS], int B[][MAXCOLS], int C[][MAXCOLS], int M, int N); // clrscr(); printf("Enter the value of M and N\n"); scanf("%d %d",&M, &N); printf ("Enter matrix A\n"); readMatrix(A,M,N); printf("Matrix A\n"); printMatrix(A,M,N); printf ("Enter matrix B\n"); readMatrix(B,M,N); printf("Matrix B\n"); printMatrix(B,M,N); productMatrix(A,B,C, M,N); printf ("The product matrix is\n"); printMatrix(C,M,N); }
int main(int argc, char *argv[]) { if(argc < 2) { printf("Usage: matrix-thread nThreads\n"); return -1; } numThreads = atoi(argv[1]); A = readMatrix(IN_1); B = readMatrix(IN_2); if(A->numCols != B->numRows) { fprintf(stderr, "Wrong matrix dimensions\n"); return -1; } C = makeMatrix(A->numRows, B->numCols); dispatchThreads(); writeMatrix(OUTPUT_FILE, C); freeMatrix(A); freeMatrix(B); freeMatrix(C); return 0; }
void p3b(void) { int ** matrix1=readMatrix("matrix1.txt"); int ** matrix2=readMatrix("matrix2.txt"); int ** subMatrix = sub(matrix1, matrix2, 1, 1, 0, 1, 3); printMatrix(MATSIZE,matrix1); printMatrix(MATSIZE,matrix2); printMatrix(3,subMatrix); }
void p2(void) { int matrix1[MATSIZE][MATSIZE]; int matrix2[MATSIZE][MATSIZE]; int sumMatrix[MATSIZE][MATSIZE]; readMatrix("matrix1.txt", (int *)matrix1); readMatrix("matrix2.txt", (int *)matrix2); sum((int *)matrix1, (int *)matrix2,(int *)sumMatrix,MATSIZE); printMatrix(MATSIZE,(int *)matrix1); printMatrix(MATSIZE,(int *)matrix2); printMatrix(MATSIZE,(int *)sumMatrix); }
/* Public initialisations functions */ st_parts_at * initPrior(char* dir) { dir = addInputPath(dir); st_parts_at *prior_parts; char *residual_file= createPath(dir, "residuals.csv"); char *species_prior_file= createPath(dir, "species_prior.csv"); prior_parts = (st_parts_at *) malloc(sizeof(st_part_at)); prior_parts->sps = readMatrix(species_prior_file); prior_parts->res = readMatrix(residual_file); return(prior_parts); }
int main(int argc, char const *argv[]) { Matrix *m1 = readMatrix(getFileMatrixName(argc, argv, 1)); Matrix *m2 = readMatrix(getFileMatrixName(argc, argv, 2)); int process = getNumberOfProcessOrThreadNumber(argc, argv); Matrix result = multipleMatrixUsingProcess(*m1,*m2, process); writeMatrix("out.txt", result); return 0; }
void LDAModel::readFromFile(string filename) { ifstream input(filename.c_str()); if (!input) { throw BALL::Exception::FileNotFound(__FILE__, __LINE__, filename); } String line0; getline(input, line0); // skip comment line getline(input, line0); // read read line containing model specification if (line0.getField(0, "\t") != type_) { String e = "Wrong input data! Use training data file generated by a "; e = e + type_ + " model !"; throw Exception::WrongDataType(__FILE__, __LINE__, e.c_str()); } int no_descriptors = line0.getField(2, "\t").toInt(); int no_y = line0.getField(3, "\t").toInt(); bool centered_data = line0.getField(4, "\t").toInt(); int no_classes = line0.getField(5, "\t").toInt(); bool trained = line0.getField(6, "\t").toBool(); substance_names_.clear(); getline(input, line0); // skip empty line readModelParametersFromFile(input); Model::readDescriptorInformationFromFile(input, no_descriptors, centered_data); if (!trained) { sigma_.resize(0, 0); return; } readClassInformationFromFile(input, no_classes); readMatrix(sigma_, input, no_descriptors, no_descriptors); getline(input, line0); // skip empty line mean_vectors_.resize(no_y); for (int c = 0; c < no_y; c++) // read all mean-vector matrices { readMatrix(mean_vectors_[c], input, no_classes, no_descriptors); } input.close(); }
double* readMatrixCart(char *nomFichier, int matrix_size, int nbCols, int nbLines, int coords[]) { char *line = malloc(256); size_t len; ssize_t end; char *endNb; FILE *file; int i = 0; int j; char *ptr; double *matrice = readMatrix(nomFichier, matrix_size, matrix_size); double *bloc = (double*)malloc(nbLines*nbCols*sizeof(double)); //On prend la partie qu'on a besoin for(i = 0; i < nbLines; i++) { for(j = 0; j < nbCols; j++) { int pos = (coords[0]*nbLines+i)*matrix_size+(coords[1]*nbCols) + j; bloc[i*nbCols + j] = matrice[pos]; } } free(matrice); return bloc; }
void SphereGenerator::genObj() { isCircle = 0; QFileInfo fileInfo(fileName); if(!fileInfo.exists()) { std::cout << "error: file does not exist" << std::endl; return; } QDir baseDir(fileInfo.absoluteDir()); QSettings settings(fileInfo.absoluteFilePath(),QSettings::IniFormat); // read in width sX = settings.value("sample/numX").toInt(); sZ = settings.value("sample/numZ").toInt(); sMatrixFile = QDir::cleanPath(QDir(baseDir).filePath(settings.value("sample/matrixfile").toString())); sTexture = QDir::cleanPath(QDir(baseDir).filePath(settings.value("sample/texture").toString())); sObj = QDir::cleanPath(QDir(baseDir).filePath(settings.value("sample/outputobj").toString())); isCircle = settings.value("circle/circle").toInt(); // initialize projList.clear(); mvList.clear(); centerList.clear(); readMatrix(sMatrixFile); deComposeMV(); output(); }
void p4(void) { int matrix1[MATSIZE][MATSIZE]; readMatrix("matrix1.txt", (int *)matrix1); printMatrix(MATSIZE,(int *)matrix1); printf("The determinant of the matrix is %d\n",determinant(MATSIZE,(int *)matrix1)); }
/* MCMC Var-Cov tuning matrix */ st_mcmc_update *initMCMCUpdate(char *dir) { st_mcmc_update *mcmc_update; dir = addInputPath(dir); char *tuning_file = createPath(dir, "tuning.csv"); gsl_matrix *tuning = readMatrix(tuning_file); char *fixed_file = createPath(dir, "fixed.csv"); gsl_vector *fixed = readVector(fixed_file); if(tuning->size1 != tuning->size2 || tuning->size1 != fixed->size) { printf("Error in initMCMCUpdate\n"); exit(GSL_FAILURE); } gsl_vector *z = gsl_vector_alloc(fixed->size); mcmc_update = (st_mcmc_update *) malloc(sizeof(st_mcmc_update)); mcmc_update->tuning = tuning; mcmc_update->fixed=fixed; mcmc_update->z = z; mcmc_update->always_accept = 1; int i; for(i=0; i<fixed->size; i++) mcmc_update->always_accept *= (int) VGET(mcmc_update->fixed, i); return(mcmc_update); }
void MatrixMarket2Bin::convert(const char *filename) { char bin_file[512]; sprintf(bin_file, "%s.bin", filename); readMatrix(filename); writeMatrix(bin_file); }
MatrixArchive::BlockType MatrixArchive::readBlock(std::istream & fin, std::string & name, Eigen::MatrixXd & matrix, std::string & stringValue) const { char start, end; // start character fin.read(&start,1); BlockType blockType; if(start == s_magicCharStartAStringBlock){ blockType = STRING; } else{ SM_ASSERT_EQ(MatrixArchiveException, start, s_magicCharStartAMatrixBlock, "The block didn't start with the expected character"); blockType = MATRIX; } // 64 character name char nameBuffer[s_fixedNameSize + 1]; nameBuffer[s_fixedNameSize] = '\0'; fin.read(nameBuffer,(std::streamsize)s_fixedNameSize); name = nameBuffer; boost::trim(name); switch(blockType){ case MATRIX: readMatrix(fin, matrix); break; case STRING: readString(fin, stringValue); break; } // end character fin.read(&end,1); SM_ASSERT_EQ(MatrixArchiveException, end, s_magicCharEnd, "The matrix block didn't end with the expected character"); return blockType; }
Eigen::MatrixXd readMatrixFromFile(const std::string &filename, int_t rows, int_t cols) { Eigen::MatrixXd M = readMatrix(filename); REQUIRE(M.rows() == rows); REQUIRE(M.cols() == cols); return M; }
Class_Substitution_Matrix::Class_Substitution_Matrix(string * filename){ aminoacid_alphabetSize=20; // 0-19 gapChar = aminoacid_alphabetSize; aminoacid_ascii2num = new int [256]; aminoacid_num2ascii = new char[aminoacid_alphabetSize+1]; for (int i=0; i<= aminoacid_alphabetSize; i++) {aminoacid_num2ascii[i] = '-';} // all upper case // hmm: ACDEFGHIKLMNPQRSTVWY for (int i=0; i< 256; i++) {aminoacid_ascii2num[i] = gapChar;} // initialize with invalid/gap character // no amino acids: O,U,B,J,X,Z - treat as gap... int j=0; for (int i='A'; i<= 'Z'; i++) { if (i=='B' || i=='J' || i=='O' || i=='U' || i=='X' || i=='Z') { aminoacid_ascii2num[i] = gapChar; } else { aminoacid_ascii2num[i] = j; aminoacid_num2ascii[j] = i; j++; } } this->matrix = readMatrix(filename); }
double* readMatrixCyclic(char *nomFichier, int matrix_size, int nbLines, int rank, int nodes) { char *line = malloc(256); size_t len; ssize_t end; char *endNb; FILE *file; int i = 0; int j; char *ptr; double *matrice = readMatrix(nomFichier, matrix_size, matrix_size); double *bloc = (double*)malloc(nbLines*matrix_size*sizeof(double)); //On prend la partie qu'on a besoin for(i = 0; i < nbLines; i++) { for(j = 0; j < matrix_size; j++) { bloc[i*matrix_size + j] = matrice[(i*nodes+rank)*matrix_size + j]; } } if(matrice) free(matrice); return bloc; }
int checkDeadlock(int n) { struct sembuf sb; sb.sem_flg = SEM_UNDO; sb.sem_num = MATRIX; sb.sem_op = -1; if(semop(sid, &sb, 1) == -1) { perror("semop"); exit(1); } readMatrix(n); sb.sem_op = 1; if(semop(sid, &sb, 1) == -1) { perror("semop"); exit(1); } int i, j, f[4]; for(i=0;i<4;i++) f[i] = 0; for(i=0;i<n;i++) { for(j=0;j<4;j++) { if(A[i][j]==2 && A[i][(j+1)%4]==1) f[j] = 1; } } if(f[0]==1 && f[1]==1 && f[2]==1 && f[3]==1) return 1; else return 0; }
int main() { Matrix *mat = readMatrix("input.txt"); if(gaussJordan(mat) == 1) printf("error\n");; //printMat(mat,mat -> size); writeMatrix(mat); destroyMat(mat); return 0; }
void p5(void) { char dataFileMat1[]="matrix.txt"; double ** matrix=readMatrix(dataFileMat1); double ** L=choleskyDecomp(matrix, MATSIZE,0); printf("The cholesky decomposition of the matrix is: \n"); printMatrix(L,MATSIZE); freeMatrix(L,MATSIZE); }
void p3(void) { printf("read"); double ** matrix=readMatrix("matrix.txt"); printf("read"); double ** multMatrix = mult(matrix, matrix, MATSIZE); printMatrix(multMatrix,MATSIZE); freeMatrix(multMatrix,MATSIZE); }
int main(int argc, char **argv) { int n; double **pFile, **e, **s; if (argc == 1) { printf("Please enter the file name which contain Matrix data!\n\nUsage: %s <filename>\n", argv[0]); exit(EXIT_FAILURE); } pFile = readMatrix(argv[1], &n, 1); #ifdef DEBUG output_A(pFile, n, n); #endif e = eliminate((const double **)pFile, n, n+1); if (!e) exit(EXIT_FAILURE); printf("RESULT...\n"); output_A(e, n, n+1); s = solve(e, n); printf("方程的解为:\n"); output_A(s, 1, n); // 求逆阵 double **T = readMatrix("gauss_inverse", &n, 0); double **M_I = matrix_I(n); output_A(T, n, n); #ifdef DEBUG_INVERSE printf("输出单位矩阵:\n"); output_A(M_I, n, n); #endif double **II = invers(T, M_I, n); revers(II, n, n); printf("输出逆阵:\n"); output_A(II, n, n); printf("测试:\n"); output_A(multi(T, II, n), n, n); return 0; }
int main() { while(~scanf("%d", &n)) { readMatrix(a); readMatrix(b); readMatrix(c); for(int i=0;i<n;++i) x[i] = i; mutiply(x, a, d); mutiply(d, b, e); mutiply(x, c, f); if(equal(e, f)) printf("YES\n"); else printf("NO\n"); } return 0; }
void ecology_initialization(ode_set *des,FILE *in){ float tmp; time_t t; char buff[CHAR_BUFF_SIZE]; while( fscanf(in, " %s ", buff) != EOF){ if (!strcmp(buff, "CARRYING_CAPACITY")){ //reading carrying capacity fscanf(in,"%f ",&tmp); carrying_capacity = tmp; } else if (!strcmp(buff, "INTERACTION_MATRIX")){ //identifying the type of the interaction matrix fscanf(in, "%s ", buff); if (!strcmp(buff,"custom")){ im = safeMatrixAlloc(dim,dim); readMatrix(in, im, dim,dim); time(&t); printf("#Init random with clock seed: %d\n", (int) t); srand(t); } else if (!strcmp(buff,"uniform_random")){ int seed; fscanf(in, "%d", &seed); srand(seed); im = uniformRandomAlloc(dim,.7); } } else if (!strcmp(buff, "DUMP")){ //identifying the dumping method fscanf(in, "%s ", buff); if (!strcmp(buff,"state")){ des->data_dump = &ecology_dump; } else if (!strcmp(buff,"full")){ des->data_dump = &ecology_full_dump; } } } time(&t); printf("#Init random with clock seed: %d\n", (int) t); srand(t); generalized_simplex(dim,carrying_capacity*0.4,des->state); //displaying the matrix printMatrix(stdout, im, dim, dim); fclose(in); fflush(stdout); }
void readFillStyle(FILE *f, struct FillStyle *s, Blocktype shapeType, int isMorph) { int type; type = readUInt8(f); s->type = type; if(type==0) /* solid fill */ { if(shapeType==DEFINESHAPE3) readRGBA(f, &(s->fill.color)); else readRGB(f, &(s->fill.color)); if(isMorph) readRGBA(f, &(s->fill2.color)); } else if(type==0x10 || type==0x12) { /* linear (0x10) or radial (0x10) gradient */ readMatrix(f, &(s->matrix)); if(isMorph) readMatrix(f, &(s->matrix2)); readGradient(f, &(s->fill.gradient), shapeType); } else if(type==0x40 || type==0x41) { /* tiled bitmap (0x40) or clipped bitmap (0x41) fill */ s->fill.bitmap = readUInt16(f); readMatrix(f, &(s->matrix)); if(isMorph) readMatrix(f, &(s->matrix2)); } else error("Unknown fill type: %i\n", type); }
static gfxmatrix_t read_matrix(reader_t*r, state_t*state, U8 id, U8 flags) { assert(id>=0 && id<16); if(flags&FLAG_SAME_AS_LAST) { gfxmatrix_t m = state->last_matrix[id]; readXY(r, state, &m); return m; } gfxmatrix_t m = readMatrix(r, state); state->last_matrix[id] = m; return m; }
void ProjectorCalibration :: loadFromFile(const char* filename) { QFileInfo f (filename); ntk_throw_exception_if(!f.exists(), "Could not find calibration file."); cv::FileStorage calibration_file (filename, CV_STORAGE_READ); readMatrix(calibration_file, "proj_intrinsics", intrinsics); readMatrix(calibration_file, "proj_distortion", distortion); readMatrix(calibration_file, "R", R); readMatrix(calibration_file, "T", T); cv::Mat1i size_mat; readMatrix(calibration_file, "proj_size", size_mat); proj_size = cv::Size(size_mat(0,0), size_mat(0,1)); calibration_file.release(); pose = new Pose3D(); pose->toRightCamera(intrinsics, R, T); initUndistortRectifyMap(intrinsics, distortion, Mat(), intrinsics, proj_size, CV_16SC2, undistort_map1, undistort_map2); }
bool SOGP::readFrom(FILE *fp,bool ascii){ if(!fp){ printf("SOGP::load error\n"); return false; } int ver; fscanf(fp,"SOGP version %d\n",&ver); if(ver!=VER){ printf("SOGP is version %d, file is %d\n",VER,ver); return false; } fscanf(fp,"current_size: %d\n",¤t_size); m_params.readFrom(fp,ascii); readMatrix(alpha,fp,"alpha",ascii); readMatrix(C,fp,"C",ascii); readMatrix(Q,fp,"Q",ascii); readMatrix(BV,fp,"BV",ascii); return true; }
void ALLModel::readFromFile(string filename) { std::ifstream input(filename.c_str()); if (!input) { throw BALL::Exception::FileNotFound(__FILE__, __LINE__, filename); } String line0; getline(input, line0); // skip comment line getline(input, line0); // read read line containing model specification if (line0.getField(0, "\t") != type_) { String e = "Wrong input data! Use training data file generated by a "; e = e + type_ + " model !"; throw Exception::WrongDataType(__FILE__, __LINE__, e.c_str()); } int no_descriptors = line0.getField(2, "\t").toInt(); int no_y = line0.getField(3, "\t").toInt(); bool centered_data = line0.getField(4, "\t").toInt(); bool centered_y = line0.getField(5, "\t").toInt(); int no_substances = line0.getField(6, "\t").toInt(); substance_names_.clear(); getline(input, line0); // skip empty line readModelParametersFromFile(input); if (centered_y) { readResponseTransformationFromFile(input, no_y); } Model::readDescriptorInformationFromFile(input, no_descriptors, centered_data); readMatrix(descriptor_matrix_, input, no_substances, no_descriptors); getline(input, line0); // skip empty line readMatrix(Y_, input, no_substances, no_y); }