int main(int argc, char** argv) {

    pthread_t threads[NUM_THRD];
    int thread_args[NUM_THRD];
    int rc, i;

    //Init Matrix
	initMatrix();

    while(errorCount()) {
        for (int x = 0; x < SIZE; x++) 
            x1[x] = x2[x];
        
        //Count N * x + b
        for (i = 0; i < NUM_THRD; i++) {
            thread_args[i] = i;
            rc = pthread_create(&threads[i], NULL, count, (void *) &thread_args[i]);
            assert(0 == rc);
        }

        for (i = 0; i < NUM_THRD; i++) {
            rc = pthread_join(threads[i], NULL);
            assert(0 == rc);
        }
    } 

    printX2();

    return 0;
}
Example #2
0
// units of k0, kp, only matter relative to d (only m*d products ever used)
SMatrix::SMatrix(const cdouble *eps, const double *d, int NIn, double k0In, double kpIn)
	: kz(new cdouble[N+1]), k(new cdouble[N+1]), kp(kpIn), k0(k0In), N(NIn),
	sTE(new cdouble[4*(2*N+1)]), sTM(new cdouble[4*(2*N+1)]) // member init. list
{
	mlgeo g = mlgeo(eps, d, N);
	initMatrix(g);
}
Example #3
0
int main(int argc, char* argv[]){
    int i;

    char c;
    int selectedFunc=-1;
    while( (c=getopt(argc,argv,"M:N:F:")) != -1){
        switch(c){
        case 'M':
            M = atoi(optarg);
            break;
        case 'N':
            N = atoi(optarg);
            break;
        case 'F':
            selectedFunc = atoi(optarg);
            break;
        case '?':
        default:
            printf("./tracegen failed to parse its options.\n");
            exit(1);
        }
    }
  

    /*  Register transpose functions */
    registerFunctions();

    /* Fill A with data */
    initMatrix(M,N, A, B); 

    /* Record marker addresses */
    FILE* marker_fp = fopen(".marker","w");
    assert(marker_fp);
    //fprintf(marker_fp, "%llx %llx", 
    fprintf(marker_fp, "%lx %lx", 
            //(unsigned long long int) &MARKER_START,
            //(unsigned long long int) &MARKER_END );
            (unsigned long int) &MARKER_START,
            (unsigned long int) &MARKER_END );
    fclose(marker_fp);

    if (-1==selectedFunc) {
        /* Invoke registered transpose functions */
        for (i=0; i < func_counter; i++) {
            MARKER_START = 33;
            (*func_list[i].func_ptr)(M, N, A, B);
            MARKER_END = 34;
            if (!validate(i,M,N,A,B))
                return i+1;
        }
    } else {
        MARKER_START = 33;
        (*func_list[selectedFunc].func_ptr)(M, N, A, B);
        MARKER_END = 34;
        if (!validate(selectedFunc,M,N,A,B))
            return selectedFunc+1;

    }
    return 0;
}
Example #4
0
Matrix *copyMatrixConfig(Matrix *from) {
    Matrix *to = initMatrix();
    to->pages = from->pages;
    allocMatrixByConfig(to);

    return to;
}
Example #5
0
int main(int argc, char *argv[]) {
	
	if(argc != 5) {
		printf("Usage:\n<program_name> <rows> <columns> <aug_rows> <aug_columns>\n");
		return -1;
	}

	
	int r1=atoi(argv[1]);
	int c1=atoi(argv[2]);

	
	int r2=atoi(argv[3]);
	int c2=atoi(argv[4]);


	if(r1 != r2) {
		printf("\n Number of rows of both matrix should be same %d != %d", r1, r2);
		return -2;
	}


	int **matrix1 = createMatrix(r1,c1);
	int **matrix2 = createMatrix(r2,c2);
	printf("Matrix 1 :\n");

	initMatrix(matrix1, r1,c1);
	displayMatrix(matrix1, r1,c1);

	printf("Matrix 2 :\n");
	initMatrix(matrix2, r2,c2);
	displayMatrix(matrix2, r2,c2);


	int **aug_matrix3 = augMatrix(matrix1, r1, c1, matrix2, r2, c2);
	deleteMatrix(matrix1,r1,c1);
	deleteMatrix(matrix2,r2,c2);

	int r3 = r1;
	int c3 = c1 + c2;
	printf("\nSum Matrix 3 :\n");
	displayMatrix(aug_matrix3, r3, c3);
	deleteMatrix(aug_matrix3,r3,c3);

	return 0;
}
Example #6
0
void AliasingManager::computeClosure() {
	// Initialization of matrices
	initMatrix(MK_SymetricalMatrix);
	initMatrix(MK_ClosedMatrix);

	// Efficient closure algorithm
	// http://www.enseignement.polytechnique.fr/informatique/profs/
	//                                  Jean-Jacques.Levy/poly/main5/node5.html
	for (int x = 0, n = m_dimension; x < n; x++)
		for (int u = 0; u < n; u++)
			if (m_matricesMap[MK_ClosedMatrix][u][x])
				for (int v = 0; v < n; v++)
					if (m_matricesMap[MK_ClosedMatrix][x][v])
						m_matricesMap[MK_ClosedMatrix][u][v] = true;

	m_matrixChanged = false;
}
Example #7
0
void VisualMatrix::init()
{
	initSprite();
	initEffect();
	initMatrix();
	initStats();
	initState();
}
Example #8
0
void CMap::increaseMap()
{
	width++;
	height++;
	
	center();
	initMatrix();
}
mesh_core::PlaneProjection::PlaneProjection(
      const Eigen::Vector3d& normal,
      const Eigen::Vector3d& origin,
      const Eigen::Vector3d& x_axis)
  : Plane(normal, origin)
  , origin_(origin)
{
  initMatrix(x_axis);
}
Example #10
0
int main(){
   int **M;
   int i=0;
   initMatrix(M);
   setDataToMatrix(M);
   printMatrix(M);
   findMaAn(M);
   return 1;
}
Example #11
0
int main (int argc, char *argv[])
{
    int c, i, j;
    int begin, end;
    int iTotalSize;
    pthread_attr_t attr;
    pthread_t *tid;
    int *id;
    double error;
    if (argc == 1)
    {
	printf("This program should take at least one parameter for input matrix\n");
	return 0;
    }
    if (argc == 3)
	task_num = atoi(argv[2]);
    if (argc > 3)
    {
	printf("This program should not take more than 2 parameters \n");
	return 0;
    }
    nsize = initMatrix(argv[1]);
    id = (int *) malloc (sizeof (int) * task_num);
    tid = (pthread_t *) malloc (sizeof (pthread_t) * task_num);
    if (!id || !tid)
    {
	fprintf(stderr, "The matrix file open error\n");
        exit(-1);
    }
    pthread_attr_init (&attr);
    pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
    for (i = 1; i < task_num; i++) {
        id[i] = i;
        pthread_create (&tid[i], &attr, work_thread, &id[i]);
    }
    id[0]=0;
    work_thread(&id[0]);
    // wait for all threads to finish
    for (i = 1; i < task_num; i++)
        pthread_join (tid[i], NULL);

    FILE *result;
    result = fopen ("result.txt", "w");
    for (i=0; i<nsize; i++){
        fprintf (result, "X[%d] = %f \n", i, X[i]);
    }
    error = 0.0;

    for (i = 0; i < nsize; i++) {
        double error__ = (X__[i]==0.0) ? 1.0 : fabs((X[i]-X__[i])/X__[i]);
        if (error < error__) {
            error = error__;
        }
    }
    fprintf(stdout, "Error: %6.3f\n", error);
    return 0;
}
Example #12
0
// Position and Rotation
const LLMatrix4&  	LLMatrix4::initRotTrans(const F32 angle, const F32 rx, const F32 ry, const F32 rz,
											const F32 tx, const F32 ty, const F32 tz)
{
	LLMatrix3	mat(angle, rx, ry, rz);
	LLVector3	translation(tx, ty, tz);
	initMatrix(mat);
	setTranslation(translation);
	return (*this);
}
Example #13
0
mesh_core::PlaneProjection::PlaneProjection(
      const Plane& plane,
      const Eigen::Vector3d& point_near_origin,
      const Eigen::Vector3d& x_axis)
  : Plane(plane)
{
  double dist = point_near_origin.dot(normal_) + d_;
  origin_ = point_near_origin - dist * normal_;
  initMatrix(x_axis);
}
Example #14
0
Matrix4 orthoM(float left, float right, float bottom, float top, float near, float far) {
	float tx = -(right+left)/(right-left);
	float ty = -(top+bottom)/(top-bottom);
	float tz = -(far+near)/(far-near);
	return initMatrix(
		2/(right-left), 0, 0, 0,
		0, 2/(top-bottom), 0, 0,
		0, 0, -2/(far-near), 0,
		tx, ty, tz, 1);
}
Example #15
0
/* returns an nxn identity matrix */
Matrix idMat(int n)
{
	Matrix mat = initMatrix(n);
	int i;
	for(i = 0; i < n; i++)
	{
		mat->m[i][i] = 1;
	}
	return mat;
}
Example #16
0
int MatchingApplication::match() {
    try{
        addOptions();
        processArguments();
        initConfiguration();

        // Cleaning
        if(w_)
            delete w_;
        if(g1_)
            delete g1_;
        if(g2_)
            delete g2_;
        if(gl1_)
            delete gl1_;
        if(gl2_)
            delete gl2_;
        w_ = 0;
        g1_ = g2_ = 0;
        gl1_ = gl2_ = 0;

        // Check number of arguments
        QStringList args = positionalArguments();
        if(args.size() != 2)
            Exception(QString("You must provide exactly two %1 (%2 given)").arg(isMultiMatching_?"directories":"graphs").arg(args.size()));

        // Loading weights and graphs
        w_ = new Weights(cfg_->substitution, cfg_->creation);
        if(isMultiMatching_) {
            gl1_ = new GraphList(QDir(args.at(0)), cfg_->ext);
            gl2_ = (args.at(0).compare(args.at(1)) == 0)? gl1_ : new GraphList(QDir(args.at(1)), cfg_->ext);
        } else {
            g1_ = new Graph(args.at(0));
            g2_ = new Graph(args.at(1));
        }
        initMatrix();
        QThreadPool::globalInstance()->setMaxThreadCount(cfg_->parallelInstances);

        // Running the matching(s)
        if(isMultiMatching_) {
            for(auto i : *gl1_)
                for(auto j : *gl2_)
                    if((gl1_ != gl2_) || (j->getIndex() > i->getIndex()))
                        queue_.enqueue(qMakePair(i,j));
        } else {
            queue_.enqueue(qMakePair(g1_, g2_));
        }
        populate();

        return exec();
    } catch(std::exception &e) {
        error(e);
    }
    return EXIT_FAILURE;
}
Example #17
0
int main(int argc, char* argv[])
{
	//loadCalculatedValues();
	parseFile("input.txt");
	initMatrix();
	calculateCurrentMoves();
	runTestMoves();
	outputFile("output.txt");
	//std::cout << "p1 score is " << player1Score << " p2 score is " << player2Score << std::endl;
	return 0;
}
Example #18
0
/* create a 2D matrix from a 1D array */
Matrix createMatrix(double *mtx, int n)
{
	Matrix mat = initMatrix(n);
	int i,j;
	for(i = 0; i < n; i++)
	{
		for(j = 0; j < n; j++, mtx++)
			mat->m[i][j] = *mtx;
	}
	return mat;
}
Example #19
0
void NewLDAModel(LDAMODEL** m)
{
  (*m) = xmalloc(sizeof(LDAMODEL));
  initUIVector(&((*m)->classid));
  initMatrix(&((*m)->evect));
  initArray(&((*m)->mnpdf));
  initArray(&((*m)->features));
  initMatrix(&((*m)->inv_cov));
  initMatrix(&((*m)->mu));
  initMatrix(&((*m)->fsdev));
  initMatrix(&((*m)->fmean));
  initDVector(&((*m)->eval));
  initDVector(&((*m)->pprob));
  initDVector(&((*m)->sens));
  initDVector(&((*m)->spec));
  initDVector(&((*m)->ppv)); /* o precision */
  initDVector(&((*m)->npv));
  initDVector(&((*m)->acc));
  (*m)->nclass = (*m)->class_start = 0;
}
Example #20
0
void onDraw()
{
  /*setViewer O(1)*/
  setMatrixMode(PROJECTION);
  initMatrix();
  setViewer(vertex(eyex, eyey, eyez), vertex(lookx, looky, lookz), vertex(upx, upy, upz));
  setFrustum(10, 10*MAX_H/MAX_W, 4, 25);

  /*createPolygons O(1)*/
  initScene();
  setMatrixMode(MODELVIEW); 
  initMatrix();
  if(!Aisclippingwindow)
	drawA(Ax, Ay, Az);
  drawB(Bx, By, Bz);

  /*drawPixels*/
  renderScene();
  glDrawPixels(MAX_W, MAX_H, GL_RGBA, GL_BYTE, data);
  glFlush();
}
int main(int argc, char *argv[])
{
    int i;
    struct timeval start, finish;
    double error;
    
    pthread_attr_t attr;
    pthread_t *tid;
    int *id;
    
    if (argc < 2) {
	fprintf(stderr, "usage: %s <matrixfile>\n", argv[0]);
	exit(-1);
    }
    
    // for getting the threads
    if(argc == 3) {
        task_num = strtol(argv[2], NULL, 10);
    }

    nsize = initMatrix(argv[1]);
    initRHS(nsize);
    initResult(nsize);
   
    // create threads
    id = (int *) malloc (sizeof (int) * task_num);
    tid = (pthread_t *) malloc (sizeof (pthread_t) * task_num);
    if (!id || !tid)
        errexit ("out of shared memory");
    pthread_attr_init (&attr);
    pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
    for (i = 1; i < task_num; i++) {
        id[i] = i;
        pthread_create (&tid[i], &attr, work_thread, &id[i]);
    }

    id[0]=0;
    work_thread(&id[0]);
    // wait for all threads to finish
    for (i = 1; i < task_num; i++)
        pthread_join (tid[i], NULL);
	    
    solveGauss(nsize);
    
    error = 0.0;
    for (i = 0; i < nsize; i++) {
	double error__ = (X__[i]==0.0) ? 1.0 : fabs((X[i]-X__[i])/X__[i]);
	if (error < error__) {
		error = error__;
	}
    }
    fprintf(stdout, "Error: %e\n", error);
}
Example #22
0
static int readFile(FILE *file, pmatrix_t *matrix, index_t rows, index_t columns) {
	index_t x, y;
	initMatrix(matrix, rows, columns);
	if (matrix == NULL)
		return ERRORCODE_CANT_MALLOC;
	for(y = 0; y < rows; y++) {
		for(x = 0; x < columns; x++)
			if (fscanf(file, UNIT_SPECIFIER, getMatrixElement(*matrix, y, x)) != 1)
				return ERRORCODE_PARSER_ERROR; 
	}
	return ERRORCODE_NOERRORS;
}
Example #23
0
int main(){
  std::vector<std::vector<int>> matrix;
  
  initMatrix(matrix);

  int toy = matrix[6][8] * matrix[7][9] * matrix[8][10] * matrix[9][11];
  std::cout << " toy example: " << toy << std::endl;

  std::cout << " the greatest product of 4 is " << products(matrix) << std::endl;

  return 0;
}
float TExamplesDistance_DTW::operator ()(const TExample &e1, const TExample &e2) const
{ 
  vector<float> seq1, seq2, der1, der2;
  getNormalized(e1, seq1);
  getNormalized(e2, seq2);
  TdtwMatrix mtrx;
  switch (dtwDistance) {
	case DTW_EUCLIDEAN: {
	  initMatrix(seq1, seq2, mtrx);
	  break;
						}
	case DTW_DERIVATIVE: {
		getDerivatives(seq1, der1);
		getDerivatives(seq2, der2);
		initMatrix(der1, der2, mtrx);
		break;
						 }
  }
  float dist = calcDistance(mtrx);
  return dist;
}
Example #25
0
int GzPushMatrix(GzRender *render, GzMatrix	matrix)
{
/*
- push a matrix onto the Ximage stack
- check for stack overflow
*/
	//init if render->matlevel = -1
	if(render->matlevel == -1){
		initMatrix(&(render->Ximage[0]),4);
		(render->Ximage[0])[0][0] = 1;
		(render->Ximage[0])[1][1] = 1;
		(render->Ximage[0])[2][2] = 1;
		(render->Ximage[0])[3][3] = 1;
		render->matlevel += 1;
	}
	
	if(render->matlevel > -1)
	{
		if (render->matlevel < MATLEVELS - 1)
		{
			//GzMatrix tempMatrix;
			//matrixCopy(matrix, &tempMatrix,4,4);
			render->matlevel += 1;
			initMatrix(&(render->Ximage[render->matlevel]),4);
			matrixMul(render->Ximage[render->matlevel-1], matrix, &(render->Ximage[render->matlevel]),4,4,4);
		}else
		{
			errorCall("GzPushMatrix","matlevel >= MATLEVELS");
			AfxMessageBox( "Matrix has full\n" );
			return GZ_FAILURE;
		}
	}else
	{
		errorCall("GzPushMatrix", "render->matlevel < -1");
		//return GZ_FAILURE;
	}

	return GZ_SUCCESS;
}
ForwardBackward::ForwardBackward(const HiddenMarkovModel &hmm, const std::vector<int> &outputSequence)
    : hmm(hmm), outputSequence(outputSequence)
{
    assert(outputSequence.size() > 0);

    int timeEnd = outputSequence.size()-1;

    lnForward = initMatrix(timeEnd + 1, hmm.getAmountHiddenStates(), 1.0);

    int start = 0;
    int outputIndex = outputSequence.at(start);
    for (size_t i = 0; i < hmm.getAmountHiddenStates(); i++) {
        lnForward.at(start).at(i) = hmm.lnInitial.at(i)
                + hmm.lnEmission.at(i).at(outputIndex);
    }

    lnBackward = initMatrix(timeEnd + 1, hmm.getAmountHiddenStates(), 1.0);

    for (size_t i = 0; i < hmm.getAmountHiddenStates(); i++) {
        lnBackward.at(timeEnd).at(i) = 0;
    }
}
short newCorner( short alpha, short beta, short gamma, 
                 short c1, short c2, short c3)
{ // generates a cube corner (3 x face) 
  // alpha beta gamma indicate the rotation
  // c1, c2, c3 are the colors for the three faces in order
  // return index to face table  (containing 3 new faces)
  
  short fo, po;
  short x, y, z;
  short a, b ,c, d, e, f, g;
  
  // determin vertex coordinates  
  x = (U + U/2 +3);
  y = (U + U/2 +3);
  z = (U + U/2 +3);
  
  // rotation
  initMatrix( mo, alpha, beta, gamma, 0, 0, 0);

  // verify there is room in the tables
    if ((facec>=3) && (pyc>=3) && (pc>=7))
    {
      // generate all points necessary for the cube corner
      // in base position
        a = newPoint( x,   y,   z);        // A        
        b = newPoint( x,   y-U, z);        // B
        c = newPoint( x-U, y-U, z);        // C
        d = newPoint( x-U, y,   z);        // D
        e = newPoint( x,   y-U, z-U);      // E
        f = newPoint( x,   y,   z-U);      // F
        g = newPoint( x-U, y,   z-U);      // G
        
      // generate all the polygons and faces 
      // with proper orientation (normal outbound)
        newFace ( newPoly( a, b, c, d), c1);
        newFace ( newPoly( d, g, f, a), c2);
        fo = newFace( newPoly( a, f, e, b), c3); 
        
      // add an object with 3 faces
        po = newObj( fo, 3);
        
      // rotate as required
        rotateObject( mo, po);

      // returns the object index
        return po;
    } // if 
    else 
        while( 1);
} // new cube corner
Example #28
0
void Skok(fxpnt_matrix_t **Y, fxpnt_matrix_t **U, int N, int d, int delay){
  int i,j;
  m_free(Y);
  m_free(U);
  *U = initMatrix(N, 1);
  *Y = initMatrix(N, 1);
  for(i = 0; i < delay; i++)
    (*U)->matrix[i][0] = 0;
  for(i = delay; i < N; i++)
    (*U)->matrix[i][0] = 1;
  for(i = 0; i < N-d; i++){
    for(j = 0; j < St; j++){
      if(i > j){
        (*Y)->matrix[i+d][0] = (*Y)->matrix[i+d][0] - teta->matrix[j][0]*(*Y)->matrix[i-j+d-1][0];
        }
    }
    for(j = 0; j <= teta->rows - St; j++){
      if(i > j){
        (*Y)->matrix[i+d][0] = (*Y)->matrix[i+d][0] + teta->matrix[j+St][0]*(*U)->matrix[i-j][0];
        }
    }
  }
}
Example #29
0
/* create a clone of matrix provided */
Matrix copyMatrix(Matrix mat)
{
	Matrix copy = initMatrix(mat->dim);
	copy->dim = mat->dim;
	int i, j;
	for(i = 0; i < mat->dim; i++)
	{
		for(j = 0; j < mat->dim; j++)
		{
			copy->m[i][j] = mat->m[i][j];
		}
	}
	return copy;
}
Example #30
0
void init_output_dist(const Eigen::MatrixBase<Derived> &outputDist_const,const Eigen::MatrixBase<Derived2> &normalization_const) {
	UNCONST(Derived,outputDist_const,outputDist);
	UNCONST(Derived2,normalization_const,normalization);
	initMatrix(outputDist);
	//std::cout << outputDist << "\n\n";
	normalization.setZero();
	for(int i=0; i<outputDist.rows(); i++) {
		normalization += outputDist.row(i);
	}

	for(int i=0; i<outputDist.rows(); i++) {
		outputDist.row(i) = (outputDist.row(i).array()/normalization.array()).matrix();
	}
}