Reading from an ascii file and filling boost matrix

Root version : 6.12/06
OS platform : CentOS 7.3
Compiler : gcc6.2

Dear co-rooters,

I am trying to do a rather simple task.
I am reading a file with numbers and from these number I want to fill a symmetric boos matrix.

My code is the following

#include <iostream>
#include <fstream>
#include <vector>
#include <iomanip>
#include "TROOT.h"
#include "TGraph.h"
#include "TH1.h"
#include "TH2.h"
#include "TMath.h"
#include "TMatrixF.h"
#include "TMatrixFSym.h"
#include "TMatrixFSparse.h"
#include "TVector.h"
#include "TMatrixTSym.h"
#include "TString.h"
#include "TRandom.h"

#include </usr/include/boost/numeric/ublas/matrix.hpp>
#include </usr/include/boost/numeric/ublas/matrix_sparse.hpp>
#include </usr/include/boost/numeric/ublas/symmetric.hpp>
#include <boost/numeric/ublas/banded.hpp>
#include </usr/include/boost/numeric/ublas/io.hpp>

//#include ""

using namespace std;
using namespace boost::numeric::ublas;

boost::numeric::ublas::symmetric_matrix<float> fill_symmetric (boost::numeric::ublas::symmetric_matrix<float> m_sym, float* filler, int size_FILLER){

	float* in = filler;
	for (size_t i=0; i<m_sym.size1(); ++ i)
    		for (size_t j = 0; j <= i && in != &filler[size_FILLER+1]; ++ j)
        		m_sym (i, j) = *in++;
	return m_sym;


void test(){

	// () Read the correlation Matrix
	float covariance;
	float *covariance_EVAL = new float[6];
	int   index=0;
	std::ifstream myfile;"TEST_MT18_CorMat.dat");
		myfile >> covariance;
		if (!myfile.good()) break;
		covariance_EVAL[index] = covariance;
		cout << covariance << "\t" << covariance_EVAL[index] << endl;

// (4) Define the types of T-objects that will be used
	symmetric_matrix<float, upper> COV_EVAL (3, 3);
	COV_EVAL = fill_symmetric( COV_EVAL, covariance_EVAL, 3);
	std::cout << COV_EVAL << std::endl;	


The output of my code is the following

1	    0
0.46	1.83475e-32
1	    0
0.4	    4.48416e-44
0.46	0
1	    1.35926e-43

The problem is that the matrix is supposed to be filled in a different way so as to have the following values


Although the values are parsed correctly, they are stored strangely in the array.
Any idea on how to solve this issue?

Thank you very much in advance!

A sample file is the following

    // ...
    std::cout << covariance << "\t" << covariance_EVAL[(index - 1)] << std::endl;
  // ...
  COV_EVAL = fill_symmetric(COV_EVAL, covariance_EVAL, 6);
  // ...

Oh you are so right!!!
Thank you very much for your help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.