예제 #1
0
//function for creating matrix from user input
void createMatrix(int row,int col,FILE *fp)
{
	int i,j;
	char after;
	matrix input;
	
	input.row=row;		//set row and column in struct
	input.col=col;
	
	printf("Creating [%dx%d] matrix:\n",row,col);
	for(i=0;i<row;i++)			//for each row...
	{
		for(j=0;j<col;j++)		//for each column...
		{
			printf("Enter data for position [%d,%d] > ",i+1,j+1);
			while(scanf("%lf%c",&input.data[i][j],&after)!=2||after!='\n')		//scan the input from keyboard to array data[][] + error checking
			{
				rewind(stdin);	//rewind in case of invalid input			
				printf("Error: invalid input, try again> ");
			}
		}
	}
	
	writeMatrix(input,fp);		//call writeMatrix() to save the struct to file
}
예제 #2
0
void MatrixMarket2Bin::convert(const char *filename) {
  char bin_file[512];
  sprintf(bin_file, "%s.bin", filename);

  readMatrix(filename);
  writeMatrix(bin_file);
}
Model::Model(FILE *binfp)
{
	uint32_t nInputPlanes, nOutputPlanes;

	fread(&nInputPlanes, 4, 1, binfp);
	fread(&nOutputPlanes, 4, 1, binfp);

	this->nInputPlanes = nInputPlanes;
	this->nOutputPlanes = nOutputPlanes;
	this->kernelSize = 3;
	this->weights.clear();
	this->biases.clear();

	// setting weight matrices
	for (uint32_t oi=0; oi<nOutputPlanes; oi++) {
		for (uint32_t ii=0; ii<nInputPlanes; ii++) {
			cv::Mat writeMatrix(kernelSize, kernelSize, CV_32FC1);
			for (int yi=0; yi<3; yi++) {
				for (int xi=0; xi<3; xi++) {
					double v;
					fread(&v, 8, 1, binfp);
					writeMatrix.at<float>(yi, xi) = v;
				}
			}
			this->weights.push_back(std::move(writeMatrix));
		}
	}

	for (uint32_t oi=0; oi<nOutputPlanes; oi++) {
		double v;
		fread(&v, 8, 1, binfp);
		biases.push_back(v);
	}
}
예제 #4
0
void
FltExportVisitor::apply( osg::LOD& lodNode )
{
    _firstNode = false;
    ScopedStatePushPop guard( this, lodNode.getStateSet() );

    // LOD center - same for all children
    osg::Vec3d center = lodNode.getCenter();

    // Iterate children of the LOD and write a separate LOD record for each,
    // with that child's individual switchIn and switchOut properties
    for ( size_t i = 0; i < lodNode.getNumChildren(); ++i )
    {
        osg::Node* lodChild = lodNode.getChild(i);

        // Switch-in/switch-out distances may vary per child
        double switchInDist = lodNode.getMaxRange(i);
        double switchOutDist = lodNode.getMinRange(i);

        writeLevelOfDetail( lodNode, center, switchInDist, switchOutDist);
        writeMatrix( lodNode.getUserData() );
        writeComment( lodNode );

        // Traverse each child of the LOD
        writePushTraverseWritePop( *lodChild );
    }

}
예제 #5
0
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;
}
예제 #6
0
//function for multipling two matrices
int mulMatrix(matrix A,matrix B,FILE *fp)
{
	int i,j,k;
	double temp;
	matrix output;
	
	if(A.col!=B.row)				//first matrix's column must be equal to second matrix's row
		return 1;					//return error	
	
	output.row=A.row;				//result matrix will have row count of first matrix...
	output.col=B.col;				//and column count of second matrix
	
	for(i=0;i<A.row;i++)			//for each row...
	{
		for(j=0;j<B.col;j++)		//for each column...
		{
			temp=0;					//set temporary sum to 0
			for(k=0;k<A.col;k++)	//for each data to be sum this round...
			{
				temp+=(A.data[i][k]*B.data[k][j]);	//add sum to temp
			}
			output.data[i][j]=temp;	//save temp to data[][]
		}
	}
	
	writeMatrix(output,fp);			//call writeMatrix() to save the struct to file
	return 0;						//return success
}	
예제 #7
0
int read(Matrix *matrix)
{
     int i,j,rows,cols;
     float value;

     do
     {
     printf("Inserire numero rows: ");
     scanf("%d",&rows);
     }
     while(rows<=0);
     do
     {
     printf("Inserire numero cols: ");
     scanf("%d",&cols);
     }
     while(cols<=0);

     initMatrix(matrix, rows, cols);

     for(i=0; i<readRows(*matrix); i++)
         for(j=0; j<readColumns(*matrix); j++)
         {
             printf("Inserisci value(%d,%d): ", i, j);
             scanf("%f",&value);
             writeMatrix(matrix, i, j, value);
         }

     return 0;
}
예제 #8
0
파일: matrix.c 프로젝트: Xmister/Kigyo
int refreshMatrix(char* m[], kigyo** k) {
#ifdef ANSI
    return writeMatrix (m,k);
#else	
	int i,j;
	for (i=0; i<Y; i++) {
		for (j=0; j<X; j++) {
				if ( mold[i][j] != m[i][j] ) {
					gotoxy(j+1,i+1);
					kiir("%c",m[i][j]);
					mold[i][j]=m[i][j];
				}
		}
	}
	gotoxy(X+14,1);
	kiir("%3d",k[0][0].pont);
	if ( getMulti() ) {
		gotoxy(X+14,2);
		kiir("%3d",k[1][0].pont);
	}
	gotoxy(X+7,4);
	kiir("%3d",getEtel());
#ifdef LINUX
	refresh();
#endif
	return 0;
#endif
}
int main(int argc, char** argv){
	
	int i, status;
	pid_t forkId;
	pid_t * processId;
	

	init(argc,argv);


    //int j;
    //for(j=0; j < 10; j++){

	//get time here
	struct timeval tvBegin, tvEnd, tvDiff;
	
	
	
	processId = (pid_t *)malloc(sizeof(pid_t) * (numUnixProcess - 1));
	if(NULL == processId){
		printf("error");
		exit(1);
	}
	
	gettimeofday(&tvBegin, NULL);	
	printf("starting...\n");
	////////////////////////////////////////////////////////////////////
	for(i = 1; i < numUnixProcess; i++){
			forkId = fork();
			
			if(forkId != 0){
				//processo pai
				UnixProcessFunction(0);
			}else{
				//processo forked
				UnixProcessFunction(i);
				exit(0);
			}
			//printf("\nProcesso %d\n", forkId);
			processId[i-1] = forkId;			
	}
	
	waitpid(forkId, &status, 0);
	
	////////////////////////////////////////////////////////////////////
	//get time here
	gettimeofday(&tvEnd, NULL);  
	
	printf("finish\n");		
	
	//print time diff
	timeval_subtract(&tvDiff, &tvEnd, &tvBegin);
    printf("\n\tTime elapsed = %ld.%06ld\n", tvDiff.tv_sec, tvDiff.tv_usec);
	//}
    
    writeMatrix("out.txt",matrixResult,mResultlines,mResultcolumns);

	return 1;
}
예제 #10
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;
}
예제 #11
0
파일: ledmatrix.c 프로젝트: Azema/ledmatrix
/**
 * send the viewport data to the output
 *
 * @param matrix Matrix object
 */
void matrixSendViewport(LEDMATRIX* matrix)
{
	if (matrix->debugMode) {
		matrixDebugViewport(matrix);
	} else {
#ifdef __arm__
	writeMatrix(matrix->viewport, matrix->nbMatrix, matrix->viewportWidth/matrix->nbMatrix, matrix->viewportHeight*8);
#endif
	}
}
예제 #12
0
void fileManager::writeDistBlock (const unsigned int blockID1, const unsigned int blockID2, const std::vector<std::vector<float> >& dBlock) const {

    if( dBlock.empty()){
        std::cerr<< "ERROR @ fileManager::writeDistBlock(): block is empty, no file was written"<<std::endl;
        return;
    }
    std::string blockFilename = getBlockFilename( blockID1, blockID2 );
    writeMatrix( blockFilename, VTFloat32, dBlock, m_zipFlag );
    return;
}// end fileManager::writeDistBlock() -----------------------------------------------------------------
예제 #13
0
 vector<vector<int>> generateMatrix(int n) {
     vector<vector<int>> v;
     v.resize(n);
     for (int i = 0; i < n; ++i) {
         v[i].resize(n);
     }
     int count = 1;
     writeMatrix(count, v, 0, n, 0, n);
     return v;
 }
예제 #14
0
void
FltExportVisitor::apply( osg::ProxyNode& node )
{
    _firstNode = false;
    ScopedStatePushPop guard( this, node.getStateSet() );

    writeExternalReference( node );
    writeMatrix( node.getUserData() );
    writeComment( node );
}
예제 #15
0
void
FltExportVisitor::apply( osg::LightSource& node )
{
    _firstNode = false;
    ScopedStatePushPop guard( this, node.getStateSet() );

    writeLightSource( node );
    writeMatrix( node.getUserData() );
    writeComment( node );
    writePushTraverseWritePop( node );
}
예제 #16
0
void
FltExportVisitor::apply( osg::Group& node )
{
    ScopedStatePushPop guard( this, node.getStateSet() );

    if (_firstNode)
    {
        // On input, a FLT header creates a Group node.
        // On export, we always write a Header record, but then the first Node
        //   we export is the Group that was created from the original input Header.
        // On successive roundtrips, this results in increased redundant top-level Group nodes/records.
        // Avoid this by NOT outputting anything for a top-level Group node.
        _firstNode = false;
        traverse( node );
        return;
    }

    // A Group node could indicate one of many possible records.
    //   Header record -- Don't need to support this here. We always output a header.
    //   Group record -- HIGH
    //   Child of an LOD node -- HIGH Currently write out a Group record regardless.
    //   InstanceDefinition/InstanceReference -- MED --  multiparented Group is an instance
    //   Extension record -- MED
    //   Object record -- MED
    //   LightPointSystem record (if psgSim::MultiSwitch) -- LOW

    osgSim::MultiSwitch* multiSwitch = dynamic_cast<osgSim::MultiSwitch*>( &node );
    if (multiSwitch)
    {
        writeSwitch( multiSwitch );
    }

    else
    {
        osgSim::ObjectRecordData* ord =
            dynamic_cast< osgSim::ObjectRecordData* >( node.getUserData() );
        if (ord)
        {
            // This Group should write an Object Record.
            writeObject( node, ord );
        }
        else
        {
            // Handle other cases here.
            // For now, just output a Group record.
            writeGroup( node );
        }
    }

    writeMatrix( node.getUserData() );
    writeComment( node );
    writePushTraverseWritePop( node );
}
예제 #17
0
// Anzeigefunktion
void showAll()
{ 
  clearMatrix();
  byte matrixSize = getMatrixSize(); 
  for (int i = 0; i < matrixSize; i++) 
  {
    setMatrix(i, 65535);
  }
  writeMatrix();  
  
  return;
}
예제 #18
0
void Writer::writeClustersCenters(const std::string &filename_,
								  const cv::Mat &centers_,
								  const DescriptorParamsPtr &descriptorParams_,
								  const ClusteringParams &clusteringParams_,
								  const CloudSmoothingParams &smoothingParams_)
{
	std::vector<std::string> metadata;
	metadata.push_back(descriptorParams_->toString());
	metadata.push_back(clusteringParams_.toString());
	metadata.push_back(smoothingParams_.toString());

	writeMatrix(filename_, centers_, metadata);
}
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
dft_PolyLinProbMgr<Scalar,MatrixType>::
solve
()
{

#ifdef KDEBUG
  printf("\n\n\n\ndft_PolyLinProbMgr::solve()\n\n\n\n");
#endif

  // Solve the Schur complement system
#ifdef SUPPORTS_STRATIMIKOS
  SolveStatus<double> status = lows_->solve(Thyra::NOTRANS, *thyraRhs_, thyraLhs_.ptr());
#else
  try {
    solver_->solve();
  }
  catch (Belos::StatusTestError& e) {
    std::cout << "Belos failed to solve the linear problem! Belos threw exception "
	      << e.what() << std::endl;
  }
#endif

  // Compute the rest of the solution
  schurOperator_->ComputeX1(*rhs1_, *lhs2_, *lhs1_);

  if (debug_)
  {
    RCP<VEC> tmpRhs = rcp(new VEC(globalRowMap_));
    RCP<VEC> tmprhs1 = tmpRhs->offsetViewNonConst(block1RowMap_, 0)->getVectorNonConst(0);
    RCP<VEC> tmprhs2 = tmpRhs->offsetViewNonConst(block2RowMap_, block1RowMap_->getNodeNumElements())->getVectorNonConst(0);

    schurOperator_->ApplyGlobal(*lhs1_, *lhs2_, *tmprhs1, *tmprhs2);

    tmpRhs->update(-STS::one(), *globalRhs_, STS::one());
    Scalar resid = STS::zero();
    resid = tmpRhs->norm2();
    std::cout << "Global Residual for solution = " << resid << std::endl;
    bool writeMatrixNow = false;
    if (writeMatrixNow)
    {
      writeMatrix("A.dat", "GlobalMatrix", "GlobalMatrix");
      BLPM::writeLhs("x.dat");
      BLPM::writeRhs("b.dat");
      BLPM::writePermutation("p.dat");
    }
  }

} //end Solve
예제 #21
0
void
NOX::Epetra::DebugTools::writeOperator( std::string baseName, const Epetra_Operator & op, FORMAT_TYPE outFormat )
{
  NOX_EPETRA_OP_TYPE opTyp = get_operator_type( &op );

  if( NONE == opTyp )
    return;

  // Now get (or compute? - could be a user-option ) the matrix


  switch( opTyp )
  {
    case MATRIX_FREE      :
      Epetra_CrsMatrix * tmpMatrix;
      tmpMatrix = compute_matrix_using_operator( &op );
      writeMatrix( baseName, *tmpMatrix );
      delete tmpMatrix;
      break;

    case FINITE_DIFFERENCE       :
    case FINITE_DIFFERENCE_COLORNG :
      writeMatrix( baseName, dynamic_cast<const NOX::Epetra::FiniteDifference &>(op).getUnderlyingMatrix(), outFormat );
      break;

    case CRS_MATRIX      :
      writeMatrix( baseName, dynamic_cast<const Epetra_CrsMatrix &>(op), outFormat );
      break;

    default              :
      std::string msg = "Could not get a valid Matrix from incoming Epetra_Operator."; // of type " + opTyp + ".";
      throw msg;
  }

  return;
}
예제 #22
0
void LayerAndroid::dumpLayer(FILE* file, int indentLevel) const
{
    writeHexVal(file, indentLevel + 1, "layer", (int)this);
    writeIntVal(file, indentLevel + 1, "layerId", m_uniqueId);
    writeIntVal(file, indentLevel + 1, "haveClip", m_haveClip);
    writeIntVal(file, indentLevel + 1, "isFixed", isPositionFixed());

    writeFloatVal(file, indentLevel + 1, "opacity", getOpacity());
    writeSize(file, indentLevel + 1, "size", getSize());
    writePoint(file, indentLevel + 1, "position", getPosition());
    writePoint(file, indentLevel + 1, "anchor", getAnchorPoint());

    writeMatrix(file, indentLevel + 1, "drawMatrix", m_drawTransform);
    writeMatrix(file, indentLevel + 1, "transformMatrix", m_transform);
    writeRect(file, indentLevel + 1, "clippingRect", SkRect(m_clippingRect));

    if (m_content) {
        writeIntVal(file, indentLevel + 1, "m_content.width", m_content->width());
        writeIntVal(file, indentLevel + 1, "m_content.height", m_content->height());
    }

    if (m_fixedPosition)
        return m_fixedPosition->dumpLayer(file, indentLevel);
}
예제 #23
0
void LedMatrix::scrollMatrixOnce(int offset) {
  int n;

if (offset >= fontWidth)
	return;

uint8_t temp = offscreen[offset];

for(n=moduleNum;n>0;n--) {
temp = modules[n-1].scrollMatrixOnce(temp); // n-1 since the matrix is 0 based
}


  writeMatrix();
  usleep(12500);
}
예제 #24
0
//function to transpose the matrix
void transMatrix(matrix A,FILE *fp)
{
	int i,j;
	matrix output;
	
	output.row=A.col;				//set output matrix size (inverse of original)
	output.col=A.row;
	
	for(i=0;i<A.row;i++)			//for each row...
	{
		for(j=0;j<A.col;j++)		//for each column...
			output.data[j][i]=A.data[i][j];		//set output data (inverse of original)
	}
	
	writeMatrix(output,fp);			//call writeMatrix() to save the struct to file
}
예제 #25
0
//function for multiplying matrix with scalar
void mulScaMatrix(matrix A,double mul,FILE *fp)
{
	int i,j;
	matrix output;
	
	output.row=A.row;				//set output matrix size
	output.col=A.col;
	
	for(i=0;i<A.row;i++)			//for each row...
	{	
		for(j=0;j<A.col;j++)		//for each column...
			output.data[i][j]=A.data[i][j]*mul;		//multiply current data with mul and save to data[][]
	}
	
	writeMatrix(output,fp);			//call writeMatrix() to save the struct to file
}
예제 #26
0
void mexFunction(int nlhs, mxArray * plhs[], int nrhs, const mxArray* prhs[]) {

  if (nrhs != 2) { 
    mexErrMsgTxt("writematrix: wrong number of input parameters");
  }

  char * inputBuf;

  double * data = mxGetPr(prhs[0]);
  int n = mxGetM(prhs[0]);
  int d = mxGetN(prhs[0]);
  if(mxIsChar(prhs[1])) {
    inputBuf = mxArrayToString(prhs[1]);
  }
  writeMatrix(data, n, d, inputBuf); 
}
예제 #27
0
void
FltExportVisitor::apply( osg::Transform& node )
{
    _firstNode = false;
    ScopedStatePushPop guard( this, node.getStateSet() );

    osgSim::DOFTransform* dof = dynamic_cast<osgSim::DOFTransform*>( &node );

    if (dof)
    {
        writeDegreeOfFreedom( dof);
    }

    writeMatrix( node.getUserData() );
    writeComment( node );
    writePushTraverseWritePop( node );
}
예제 #28
0
//function for subtracting matrices
int subMatrix(matrix A,matrix B,FILE *fp)
{
	int i,j;
	matrix output;
	
	if(A.row!=B.row||A.col!=B.col)					//size checking	
		return 1;									//return error
	
	output.row=A.row;								//set output matrix size
	output.col=A.col;
	
	for(i=0;i<A.row;i++)							//for each row...
	{
		for(j=0;j<A.col;j++)						//for each column...
			output.data[i][j]=A.data[i][j]-B.data[i][j];	//subtract current data from A and B then save to output
	}
	
	writeMatrix(output,fp);		//call writeMatrix() to save the struct to file	
	return 0;					//return success
}
예제 #29
0
// Anzeige je Frame
void showPong()
{
  int i;
  
  clearMatrix();
  
  // Linie für das obere Paddle anzeigen
  writeLine(pong.paddleUp.posX, pong.paddleUp.posY, pong.paddleUp.posX + PADDLEWIDTH - 1, pong.paddleUp.posY);

  // Linie für das untere Paddle anzeigen
  writeLine(pong.paddleDown.posX, pong.paddleDown.posY, pong.paddleDown.posX + PADDLEWIDTH - 1, pong.paddleDown.posY);  
  
  // Ball anzeigen  
  setLED(pong.ball.posX, pong.ball.posY);
  
  // Die Matrix auf die LEDs multiplexen
  writeMatrix();
  
  return;
}
예제 #30
0
void Writer::writeDescriptorsCache(const cv::Mat &descriptors_,
								   const std::string &cacheLocation_,
								   const std::string &cloudInputFilename_,
								   const double normalEstimationRadius_,
								   const DescriptorParamsPtr &descriptorParams_,
								   const CloudSmoothingParams &smoothingParams_)
{
	if (!boost::filesystem::exists(cacheLocation_))
		if (system(("mkdir " + cacheLocation_).c_str()) != 0)
			LOGW << "Can't create cache folder";

	std::string destination = cacheLocation_ + Utils::getCalculationConfigHash(cloudInputFilename_, normalEstimationRadius_, descriptorParams_, smoothingParams_);

	std::vector<std::string> metadata;
	metadata.push_back("normalEstimationRadius:" + boost::lexical_cast<std::string>(normalEstimationRadius_));
	metadata.push_back(descriptorParams_->toString());
	metadata.push_back(smoothingParams_.toString());

	writeMatrix(destination, descriptors_, metadata);
}