VectorXd SparseSystem::solve() const {
  requireDebug(num_rows() >= num_cols(), "SparseSystem::solve: cannot solve system, not enough constraints");
  requireDebug(num_rows() == num_cols(), "SparseSystem::solve: system not triangular");
  int n = num_cols();
  VectorXd result(n);
  for (int row=n-1; row>=0; row--) {
    const SparseVector& rowvec = get_row(row);
    // start with rhs...
    double terms = _rhs(row);
    double diag;

    // ... and subtract already solved variables multiplied with respective coefficient from R
    // We assume that the SpareSystem is triangular
    SparseVectorIter iter(rowvec);
    iter.get(diag); // we can check return value it should be == row
    iter.next();
    for (; iter.valid(); iter.next()) {
      double v;
      int col = iter.get(v);
      terms = terms - result(col)*v;
    }
    // divide result by diagonal entry of R
    result(row) = terms / diag;
  }
  return result;
}
Example #2
0
void db_row_set_w::setup_child_phase_2()
{
	if ((num_rows() > 0) & (num_cols() > 0))
	{
		// Resize the list of column locks, with default state unlocked.

		col_locks.resize(num_cols(), DB_UNLOCKED);
		
		// Collect information about database tables, columns and primary keys.

		init_db_info();

		// If a table has no primary key, then make that table and all of its
		// columns non-writeable.

		row_set_is_writable = false;
		for (unsigned int i = 0; i < my_tables.size(); i++)
		{
			if (my_tables[i].keys.size() == 0)
			{
				my_tables[i].is_writable = false;
				for (unsigned int j = 0; j < my_tables[i].cols.size(); j++)
					col_locks[my_tables[i].cols[j]] = DB_LOCKED_PERM;
			}
			else
			{
				my_tables[i].is_writable = true;
				row_set_is_writable      = true;
			}				
		}
	}
}
Example #3
0
std::string Table<T>::to_latex() const
{
	Table<std::string>	strTable(num_rows(), num_cols());

	std::stringstream os;
	os << "\\begin{table}\n\\centering\n";
	os << "\\begin{tabular}{";
	for(size_t i=0; i < num_cols(); i++)
		os << get_col_sep(i) << get_col_alignment(i);
	os << get_col_sep(num_cols());
	os << "}\n";


	for(size_t i_row = 0; i_row < num_rows(); ++i_row)
	{
		if(get_row_sep(i_row) != ' ')
			os << "\\hline \n";

		for(size_t i_col = 0; i_col < num_cols(); ++i_col)
		{
			if(i_col != 0) os << " & ";
			os << EntryToString(*this, i_row, i_col);
		}

		os << " \\\\\n";
	}
	if(get_row_sep(num_rows())  != ' ')
		os << "\\hline \n";
	os << "\\end{tabular}\n";
	os << "\\end{table}\n";
	return os.str();
}
Example #4
0
    inline void gen_matrix_copy(const MatrixSrc& src, MatrixDest& dest, bool with_reset)
    {
	MTL_THROW_IF(num_rows(src) != num_rows(dest) || num_cols(src) != num_cols(dest), incompatible_size());

	if (with_reset)
	    detail::zero_with_sparse_src(dest, typename traits::category<MatrixSrc>::type());
	
	typename traits::row<MatrixSrc>::type             row(src); 
	typename traits::col<MatrixSrc>::type             col(src); 
	typename traits::const_value<MatrixSrc>::type     value(src); 
	typedef typename traits::range_generator<tag::major, MatrixSrc>::type  cursor_type;
	
	//std::cout << "Slot size is " << detail::copy_inserter_size<Updater>::apply(src, dest) << "\n";
	matrix::inserter<MatrixDest, Updater>   ins(dest, detail::copy_inserter_size<Updater>::apply(src, dest));
	for (cursor_type cursor = begin<tag::major>(src), cend = end<tag::major>(src); 
	     cursor != cend; ++cursor) {
	    // std::cout << dest << '\n';
	    
	    typedef typename traits::range_generator<tag::nz, cursor_type>::type icursor_type;
	    for (icursor_type icursor = begin<tag::nz>(cursor), icend = end<tag::nz>(cursor); 
		 icursor != icend; ++icursor) {
		//std::cout << "in " << row(*icursor) << ", " << col(*icursor) << " insert " << value(*icursor) << '\n';
		ins(row(*icursor), col(*icursor)) << value(*icursor); }
	}
    }
Example #5
0
T& Table<T>::operator() (size_t rowInd, size_t colInd)
{
	if(rowInd >= num_rows())
		add_rows((rowInd + 1) - num_rows());

	if(colInd >= num_cols())
		add_cols((colInd + 1) - num_cols());

	return *m_data[rowInd][colInd];
}
Example #6
0
    typename boost::enable_if<boost::mpl::and_<mtl::traits::is_vector<Op1>,
					       mtl::traits::is_vector<Op2> >, 
			      bool>::type 
    inline operator==(const Op1& op1, const Op2& op2)
    {
	unsigned s1= num_rows(op1) * num_cols(op1), s2= num_rows(op2) * num_cols(op2); // ugly hack to fight with ADL
	if (s1 != s2)
	    return false;
	for (unsigned i= 0; i < s1; i++)
	    if (op1[i] != op2[i])
		return false;
	return true;
    }
Example #7
0
    void boost::qr_decompose(boost& Q, boost& R) const {
        float mag;
        float alpha;

        bnu::matrix<float> u(this->num_rows(), 1);
        bnu::matrix<float> v(this->num_rows(), 1);

        bnu::identity_matrix<float> I(this->num_rows());

        bnu::matrix<float> q = bnu::identity_matrix<float>(this->num_rows());
        bnu::matrix<float> r(data());

        for (int i = 0; i < num_rows(); i++) {
            bnu::matrix<float> p(num_rows(), num_rows());

            u.clear();
            v.clear();

            mag = 0.0;

            for (int j = i; j < num_cols(); j++) {
                u(j,0) = r(j, i);
                mag += u(j,0) * u(j,0);
            }

            mag = std::sqrt(mag);

            alpha = -1 * mag;

            mag = 0.0;

            for (int j = i; j < num_cols(); j++) {
                v(j,0) = j == i ? u(j,0) + alpha : u(j,0);
                mag += v(j,0) * v(j,0);
            }

            mag = std::sqrt(mag); // norm

            if  (mag < 0.0000000001) continue;

            v /= mag;

            p = I - (bnu::prod(v, bnu::trans(v))) * 2.0;
            q = bnu::prod(q, p);
            r = bnu::prod(p, r);
        }

        Q = boost(q);
        R = boost(r);
    }
Example #8
0
inline void smat_smat_mult(const MatrixA& A, const MatrixB& B, MatrixC& C, Assign, 
			   tag::row_major,  // orientation A 
			   tag::row_major)  // orientation B
{
    if (Assign::init_to_zero) set_to_zero(C);
    
    // Average numbers of non-zeros per row
    double ava= num_cols(A) ? double(A.nnz()) / num_cols(A) : 0, 
	   avb= num_rows(B) ? double(B.nnz()) / num_rows(B) : 0; 

    // Define Updater type corresponding to assign mode
    typedef typename Collection<MatrixC>::value_type                            C_value_type;
    typedef typename operations::update_assign_mode<Assign, C_value_type>::type Updater;

    // Reserve 20% over the average's product for entries in C
    matrix::inserter<MatrixC, Updater>     ins(C, int( ava * avb * 1.4 ));

    typename traits::row<MatrixA>::type             row_A(A); 
    typename traits::col<MatrixA>::type             col_A(A); 
    typename traits::const_value<MatrixA>::type     value_A(A); 

    typename traits::col<MatrixB>::type             col_B(B); 
    typename traits::const_value<MatrixB>::type     value_B(B); 

    typedef typename traits::range_generator<tag::row, MatrixA>::type  cursor_type;
    cursor_type cursor = begin<tag::row>(A), cend = end<tag::row>(A); 
    for (unsigned ra= 0; cursor != cend; ++ra, ++cursor) {
	// Iterate over non-zeros of each row of A
	typedef typename traits::range_generator<tag::nz, cursor_type>::type icursor_type;
	for (icursor_type icursor = begin<tag::nz>(cursor), icend = end<tag::nz>(cursor); icursor != icend; ++icursor) {
	    typename Collection<MatrixA>::size_type     ca= col_A(*icursor);   // column of non-zero
	    typename Collection<MatrixA>::value_type    va= value_A(*icursor); // value of non-zero
 
	    // Get cursor corresponding to row 'ca' in matrix B
	    typedef typename traits::range_generator<tag::row, MatrixB>::type  B_cursor_type;
	    B_cursor_type B_cursor = begin<tag::row>(B);
	    B_cursor+= ca;

	    // Iterate over non-zeros of this row 
	    typedef typename traits::range_generator<tag::nz, B_cursor_type>::type ib_cursor_type;
	    for (ib_cursor_type ib_cursor = begin<tag::nz>(B_cursor), ib_cend = end<tag::nz>(B_cursor); 
		 ib_cursor != ib_cend; ++ib_cursor) {
		typename Collection<MatrixB>::size_type     cb= col_B(*ib_cursor);   // column of non-zero
		typename Collection<MatrixB>::value_type    vb= value_B(*ib_cursor); // value of non-zero
		ins(ra, cb) << va * vb;		
	    }
	}
    }
}
inline void smat_smat_mult(const MatrixA& a, const MatrixB& b, MatrixC& c, Assign, 
			   tag::col_major,  // orientation a 
			   tag::col_major)  // orientation b
{
    if (Assign::init_to_zero) set_to_zero(c);
    
    // Average numbers of non-zeros per column
    double ava= double(a.nnz()) / num_cols(a), avb= double(b.nnz()) / num_cols(b); 

    // Define Updater type corresponding to assign mode
    typedef typename Collection<MatrixC>::value_type                            c_value_type;
    typedef typename operations::update_assign_mode<Assign, c_value_type>::type Updater;

    // Reserve 20% over the average's product for entries in c
    matrix::inserter<MatrixC, Updater>     ins(c, int( ava * avb * 1.2 ));

    typename traits::row<MatrixA>::type             row_a(a); 
    typename traits::col<MatrixA>::type             col_a(a); 
    typename traits::const_value<MatrixA>::type     value_a(a); 

    typename traits::row<MatrixB>::type             row_b(b); 
    typename traits::col<MatrixB>::type             col_b(b); 
    typename traits::const_value<MatrixB>::type     value_b(b); 

    typedef typename traits::range_generator<tag::col, MatrixB>::type  cursor_type;
    cursor_type cursor = begin<tag::col>(b), cend = end<tag::col>(b); 
    for (unsigned cb= 0; cursor != cend; ++cb, ++cursor) {
	// Iterate over non-zeros of each column of B
	typedef typename traits::range_generator<tag::nz, cursor_type>::type icursor_type;
	for (icursor_type icursor = begin<tag::nz>(cursor), icend = end<tag::nz>(cursor); icursor != icend; ++icursor) {
	    typename Collection<MatrixB>::size_type     rb= row_b(*icursor);   // row of non-zero
	    typename Collection<MatrixB>::value_type    vb= value_b(*icursor); // value of non-zero
 
	    // Get cursor corresponding to column 'rb' in matrix A
	    typedef typename traits::range_generator<tag::col, MatrixA>::type  a_cursor_type;
	    a_cursor_type a_cursor = begin<tag::col>(a);
	    a_cursor+= rb;

	    // Iterate over non-zeros of this column
	    typedef typename traits::range_generator<tag::nz, a_cursor_type>::type ia_cursor_type;
	    for (ia_cursor_type ia_cursor = begin<tag::nz>(a_cursor), ia_cend = end<tag::nz>(a_cursor); 
		 ia_cursor != ia_cend; ++ia_cursor) {
		typename Collection<MatrixA>::size_type     ra= row_a(*ia_cursor);   // row of non-zero
		typename Collection<MatrixA>::value_type    va= value_a(*ia_cursor); // value of non-zero
		ins(ra, cb) << va * vb;		
	    }
	}
    }
}
  void printShortResults(const MatrixType& matrix, IterationType& iter, const SolverOptions& options)
  {
    const double elapsed = getTime() - startTime;
    const char d = ':';

    std::cout.precision(5);
    std::cout.setf(std::ios::fixed);
    std::cout << d;
    std::cout << "lib=desola" << d;
    std::cout << "mat=" << getLeaf(options.getFile()) << d;
    std::cout << "mat_n=" << num_cols(matrix) << d;
    std::cout << "compiler=" << getCompiler() << d;
    std::cout << "code_cache=" << getStatus(configManager.codeCachingEnabled()) << d;
    std::cout << "fusion=" << getStatus(configManager.loopFusionEnabled()) << d;
    std::cout << "contraction=" << getStatus(configManager.arrayContractionEnabled()) << d;
    std::cout << "liveness=" << getStatus(configManager.livenessAnalysisEnabled()) << d;
    std::cout << "iterations=" << iter.iterations() << d;
    std::cout << "compile_time=" << statsCollector.getCompileTime() << d;
    std::cout << "compile_count=" << statsCollector.getCompileCount() << d;
    std::cout << "total_time=" << elapsed << d;
    std::cout << "flop=" << statsCollector.getFlops() << d;
    std::cout << "high_level_fusion=" << getStatus(configManager.highLevelFusionEnabled()) << d;
    std::cout << "single_for_loop_sparse=" << getStatus(configManager.singleForLoopSparseIterationEnabled()) << d;
    std::cout << "specialise_sparse=" << getStatus(configManager.sparseSpecialisationEnabled()) << d;

    if (options.useSparse())
      std::cout << "nnz=" << nnz(matrix) << d;

    std::cout << std::endl;
  }
  void printLongResults(const MatrixType& matrix, IterationType& iter, const SolverOptions& options)
  {
    const double elapsed = getTime() - startTime;
    std::cout.precision(5);
    std::cout.setf(std::ios::fixed);
    std::cout << "Library: desola" << std::endl;
    std::cout << "Matrix: " << getLeaf(options.getFile()) << std::endl;
    std::cout << "Matrix Size: " << num_cols(matrix) << std::endl;
    std::cout << "Compiler: " << getCompiler() << std::endl;
    std::cout << "Code Caching: " << getStatus(configManager.codeCachingEnabled()) << std::endl;
    std::cout << "Loop Fusion: " << getStatus(configManager.loopFusionEnabled()) << std::endl;
    std::cout << "Array Contraction: " << getStatus(configManager.arrayContractionEnabled()) << std::endl;
    std::cout << "Iterations: " << iter.iterations() << std::endl;
    std::cout << "Liveness Analysis: " << getStatus(configManager.livenessAnalysisEnabled()) << std::endl;
    std::cout << "Time per Iteration: " << elapsed / iter.iterations() << " seconds" << std::endl;
    std::cout << "Compile Time: " << statsCollector.getCompileTime() << " seconds" << std::endl;
    std::cout << "Compile Count: " << statsCollector.getCompileCount() << std::endl;
    std::cout << "Total Time: " << elapsed << " seconds" << std::endl;
    std::cout << "FLOPs: " << statsCollector.getFlops() << std::endl;
    std::cout << "High-Level Fusion: " << getStatus(configManager.highLevelFusionEnabled()) << std::endl;
    std::cout << "Single For-Loop Sparse Iteration: " << getStatus(configManager.singleForLoopSparseIterationEnabled()) << std::endl;
    std::cout << "Sparse Row Length Specialisation: " << getStatus(configManager.sparseSpecialisationEnabled()) << std::endl;

    if (options.useSparse())
      std::cout << "NNZ: " << nnz(matrix) << std::endl;

    if (configManager.livenessAnalysisEnabled())
      std::cout << std::endl << "Warning: FLOPs figure may be misleading with liveness analysis enabled." << std::endl;
  }
Example #12
0
 static matrix<T,MemoryBlock> apply( transpose_view<matrix<T,MemoryBlock> > const& v) {
     typedef typename transpose_view<matrix<T,MemoryBlock> >::const_col_element_iterator const_col_element_iterator;
     std::vector<std::pair<const_col_element_iterator,const_col_element_iterator> > columns;
     for(std::size_t i=0; i < num_cols(v); ++i)
         columns.push_back(col(v,i));
     return matrix<T,MemoryBlock>(columns);
 }
Example #13
0
    void at(size_type i, boost::mpl::false_)
    {
	value_type tmp(math::zero(w[i+Offset]));
	for (size_type j= 0; j < num_cols(A); j++) 
	    tmp+= A[i][j] * v[j];
	Assign::first_update(w[i+Offset], tmp);
    }
void SparseMatrix::save_pattern_eps(const string& file_name) const {
  int x = num_cols();
  int y = num_rows();
  // find a scale factor that yields valid EPS coordinates
  int m = max(x,y);
  double scale = 1.;
  for (; scale*m >= 10000.; scale*=0.1);
  // create file
  ofstream out(file_name.c_str());
  out << "%!PS-Adobe-3.0 EPSF-3.0\n"
      "%%BoundingBox: 0 0 " << x*scale << " " << y*scale << "\n"
      "/BP{" << scale << " " << -scale << " scale 0 " << -y << " translate}bind def\n"
      "BP\n"
      "150 dict begin\n"
      "/D/dup cvx def/S/stroke cvx def\n"
      "/L/lineto cvx def/M/moveto cvx def\n"
      "/RL/rlineto cvx def/RM/rmoveto cvx def\n"
      "/GS/gsave cvx def/GR/grestore cvx def\n"
      "/REC{M 0 1 index RL 1 index 0 RL neg 0 exch RL neg 0 RL}bind def\n"
      "0 0 150 setrgbcolor\n"
      "0.01 setlinewidth\n";
  for (int row=0; row<_num_rows; row++) {
    for (SparseVectorIter iter(*_rows[row]); iter.valid(); iter.next()) {
      double val;
      int col = iter.get(val);
      out << "1 1 " << col << " " << row << " REC GS fill GR S" << endl;
    }
  }
  out.close();
}
Example #15
0
	Vector inline solve(const Matrix& A, const Vector& b, tag::compressed2D)
	{
		vampir_trace<3035> tracer;
	    Vector x(num_cols(A));
	    umfpack_solve(A, x, b);
	    return x;
	}
Example #16
0
void db_row_set_w::lock_perm(unsigned int col)
{
	if (!(col < num_cols()))
		throw std::out_of_range("Bad column number in db_row_set_w::lock_perm");
	
	col_locks[col] = DB_LOCKED_PERM;
}
Example #17
0
      Requires_t<mtl::traits::is_distributed<VectorT>>
    initVector(VectorT& x) const
    {
#ifdef HAVE_PARALLEL_MTL4
      x.init_distribution(col_distribution(*fullMatrix), num_cols(*fullMatrix));
#endif
      set_to_zero(x);
    }
Example #18
0
 boost boost::get_col(const int col_n) const {
     if(col_n < 0 || col_n >= num_cols()) {
         throw std::range_error("Column index out of bound");
     } else {
         bnu::matrix<float> column = bnu::subrange(data(), 0, num_rows(), col_n, col_n+1);
         return std::move(boost(column));
     }
 };
Example #19
0
 boost boost::mult(const boost& rhs) const {
     if (rhs.num_rows() != num_cols()) {
         throw std::invalid_argument("Column of left matrix does not match row of right matrix");
     } else {
         bnu::matrix<float> prod(num_rows(), rhs.num_cols());
         bnu::noalias(prod) = bnu::prod(this->data(), rhs.data());
         return std::move(boost(prod));
     }
 }
Example #20
0
    inline void matrix_copy_ele_times(const MatrixSrc& src, MatrixDest& dest)
    {
	MTL_THROW_IF(num_rows(src) != num_rows(dest) || num_cols(src) != num_cols(dest), incompatible_size());

	typename traits::row<MatrixDest>::type             row(dest); 
	typename traits::col<MatrixDest>::type             col(dest); 
	typename traits::value<MatrixDest>::type           value(dest); 
	typedef typename traits::range_generator<tag::major, MatrixDest>::type  cursor_type;
	typedef typename traits::range_generator<tag::nz, cursor_type>::type icursor_type;
	
	for (cursor_type cursor = begin<tag::major>(dest), cend = end<tag::major>(dest); cursor != cend; ++cursor)
	    for (icursor_type icursor = begin<tag::nz>(cursor), icend = end<tag::nz>(cursor); icursor != icend; ++icursor)
		value(*icursor, value(*icursor) * src[row(*icursor)][col(*icursor)]);
#if 0   // copy would result in a*0 = a and 0*b = b!!!!
	gen_matrix_copy< operations::update_times<typename MatrixDest::value_type> >(src, dest, false);
#endif
	crop(dest);
    }
Example #21
0
    void operator() (Matrix& H, const Vector& y, const Vector& s)
    {
	typedef typename mtl::Collection<Vector>::value_type value_type;
	assert(num_rows(H) == num_cols(H));
	Vector     a(s - H * y);
	value_type gamma= 1 / dot (y, y);
        MTL_THROW_IF(gamma == 0.0, unexpected_orthogonality());
    
        H+= gamma * a * trans(y) + gamma * y * trans(a) - dot(a, y) * gamma * gamma * y * trans(y);
   }
Example #22
0
void db_row_set_w::init_db_info()
{
	for (unsigned int col = 0; col < num_cols(); col++)
	{
		db_col_desc const *col_desc_p = col_desc(col);

		// Both the database column name and the table name will be needed to
		// write any changes to this column back into the database. If either
		// has not been set, then make the column non-writable.

		if (col_desc_p->name_in_db().empty() | col_desc_p->table().empty())
		{
			col_locks[col] = DB_LOCKED_PERM;
		}
		else
		{
			// Find this table in list of tables referenced in the row set.
			// Add it, if it's not already there.

			int i_table = -1;
			for (unsigned int i = 0; i < my_tables.size(); i++)
			{
				if (col_desc_p->table() == my_tables[i].name)
				{
					i_table = i;
					break;
				}
			}
			if (i_table == -1)
			{
				my_tables.push_back({ col_desc_p->table(), false });
				i_table = my_tables.size() - 1;
			}

			// Add this column number to the list of columns referenced from this table.

			my_tables[i_table].cols.push_back(col);

			// If this column is part of a primary key, then add it to the list of
			// primary keys for the table.

			if (col_desc_p->is_pri_key())
			{
				my_tables[i_table].keys.push_back(col);

				// If the key is set to auto-increment, then let the database server set the value.

				if (col_desc_p->is_auto_inc())
				{
					col_locks[col] = DB_LOCKED_PERM;
				}
			}
		}
	}
}
Example #23
0
int main() {
  using value_type = double;

  const unsigned N = 5;
  const unsigned M = 5;
  const unsigned r = 3;

  flens::matrix<value_type> A(N,M);
#if 0
  A = 2.0;
#endif
#if 1
  for (unsigned i = 0; i < num_rows(A); ++i)
    for (unsigned j = 0; j < num_cols(A); ++j)
      A(i,j) = fmmtl::random<value_type>::get();
#endif
#if 0
  A[1][1] = 1;
  A[1][3] = 2;
  A[3][1] = 1;
  A[3][3] = 4;
#endif

  std::cout << "A = \n" << A << std::endl;

  flens::matrix<double> U, V;

  std::tie(U, V) = adaptive_cross_approx(A, 1e-10, r);

  std::cout << "FINAL RANK = " << num_cols(U) << std::endl;
  std::cout << "U = \n" << U << std::endl;
  std::cout << "V = \n" << V << std::endl;
  std::cout << "UV = \n" << flens::matrix<value_type>(U*V) << std::endl;

  flens::matrix<value_type> Res;
  Res = A - U*V;

  std::cout << "Residual = \n" << Res << std::endl;
  std::cout << "norm_F = " << frobenius_norm(Res) << std::endl;

  return 0;
}
Example #24
0
std::ostream& Table<T>::stream(std::ostream& os) const
{
	const Table<T> &table = *this;
//	we'll fill a fresh table with strings of the given table
//	At the same time we'll find the max-width of each column
	Table<std::string>	strTable(num_rows(), num_cols());
	std::vector<size_t> colSizes(num_cols(), 0);

	for(size_t i_row = 0; i_row < num_rows(); ++i_row){
		for(size_t i_col = 0; i_col < num_cols(); ++i_col){
			strTable(i_row, i_col) = EntryToString(table, i_row, i_col);
			colSizes[i_col] = std::max(colSizes[i_col], strTable(i_row, i_col).size());
		}
	}

	size_t totalRowLength=0;
	for(size_t i_col = 0; i_col < num_cols(); ++i_col)
	{
		totalRowLength++;
		totalRowLength += colSizes[i_col] + 2;
	}
	totalRowLength++;

//	now print each row
	for(size_t i_row = 0; i_row < num_rows(); ++i_row)
	{
		if(get_row_sep(i_row) != 0x00 && get_row_sep(i_row) != ' ')
			os << repeat(get_row_sep(i_row), totalRowLength) << "\n";
		for(size_t i_col = 0; i_col < num_cols(); ++i_col)
		{
			os << get_col_sep(i_col);
			size_t l = colSizes[i_col] + 1;
			size_t s = strTable(i_row, i_col).size();
			os << " ";
			if(get_col_alignment(i_col) == 'r')
				os << std::setw(l) << std::right << strTable(i_row, i_col);
			else if(get_col_alignment(i_col) == 'l')
				os << std::setw(l) << std::left << strTable(i_row, i_col);
			else
				os << repeat(' ', (l-s)/2) << std::setw(l-(l-s)/2) << std::left << strTable(i_row, i_col);
		}
		os << get_col_sep(num_cols()) << std::endl;
	}
	if(get_row_sep(num_cols()) != 0x00 && get_row_sep(num_cols()) != ' ')
		os << repeat(get_row_sep(num_cols()), totalRowLength) << "\n";
	return os;
}
Example #25
0
 boost boost::get_cols(const int start, const int end) const {
     if (start < 0 || end > num_cols()) {
         throw std::range_error("Column index out of bound");
         throw;
     } else if (start > end){
         throw std::invalid_argument("Start column greater than end column");
     } else {
         bnu::matrix<float> columns = bnu::subrange(data(), 0, num_rows(), start, end);
         return boost(columns);
     }
 }
Example #26
0
std::string Table<T>::to_csv(const char *seperator) const
{
	std::stringstream os;
	for(size_t i_row = 0; i_row < num_rows(); ++i_row)
	{
		for(size_t i_col = 0; i_col < num_cols(); ++i_col)
		{
			if(i_col != 0) os << " " << seperator << " ";
			os << EntryToString(*this, i_row, i_col);
		}

		os << "\n";
	}
	return os.str();
}
Example #27
0
bool db_row_set_w::unlock(unsigned int col)
{
	if (!(col < num_cols()))
		throw std::out_of_range("Bad column number in db_row_set_w::unlock");

	if (col_locks[col] != DB_LOCKED_PERM)
	{
		col_locks[col] = DB_UNLOCKED;
		return true;
	}
	else
	{
		return false;
	}
}
  void printLongResults(const MatrixType& matrix, IterationType& iter, const SolverOptions& options)
  {
    const double elapsed = getTime() - startTime;
    std::cout.precision(5);
    std::cout.setf(std::ios::fixed);
    std::cout << "Library: MTL" << std::endl;
    std::cout << "Matrix: " << getLeaf(options.getFile()) << std::endl;
    std::cout << "Matrix Size: " << num_cols(matrix) << std::endl;
    std::cout << "Iterations: " << iter.iterations() << std::endl;
    std::cout << "Time per Iteration: " << elapsed / iter.iterations() << " seconds" << std::endl;
    std::cout << "Total Time: " << elapsed << " seconds" << std::endl;

    if (options.useSparse())
      std::cout << "NNZ: " << nnz(matrix) << std::endl;
  }
Example #29
0
void colt_add_source::get_value(int rec_num)
{
	int cols = num_cols();

	if(elements.IsItem(rec_num)) {
		colt_datatype *new_cell = colt_add_cell[cols-1];
		new_cell->set_value(elements[rec_num]);
		new_cell->format(value);
	}
	colt_datatype **rec = colt_operator::cells(rec_num);

	if(!rec)
		return;

	colt_parser parse(code_string, rec, col_headers(), cols-1);

	colt_base *exp_object = parse.parse(1);

	exp_object->process_all();

	coltthru *thru = (coltthru *) exp_object->get_destination();

	colt_datatype *new_cell = colt_add_cell[cols-1];

	if(thru->is_a(colt_class_cthru))
		new_cell->set_type(COLT_DT_CTHRU);
	else if(thru->is_a(colt_class_sort))
		new_cell->set_type(COLT_DT_SORT);
	else if(thru->is_a(colt_class_thru))
		new_cell->set_type(COLT_DT_THRU);
	else if(thru->is_a(colt_class_range))
		new_cell->set_type(COLT_DT_RANGE);
	else if(thru->is_a(colt_class_bitmap))
		new_cell->set_type(COLT_DT_BITMAP);
	else {
		perror("Add column must add a thru object.\n");
		exit(1);
	}

	elements.AddItem(rec_num, thru);
//	new_cell->set_value(thru);
	new_cell->value_type = (colt_datatype::value_type_t *) thru;
	new_cell->format(value);
	if(colt_add_cell[cols-1])
		colt_add_cell[cols-1]->value_type = (colt_datatype::value_type_t *) thru;
//		colt_add_cell[cols-1]->set_value(thru);
}
Example #30
0
 /**
  * Indicates which column needs to be flipped
  * with 50% chance
  * @return vector indicating indices of vectors to be flipped
  */
  std::vector<bool> flip_signs() const {
      std::vector<bool> indices(this->num_cols());
      std::random_device rd;
      std::mt19937 gen(rd());
      std::uniform_int_distribution<> dis(1, 2);
      int n_cols = num_cols();
      for(int i=0; i< n_cols; i++){
          int num = dis(gen);
          if (num == 2){
              indices[i] = true;
          }
          else{
              indices[i] = false;
          }
      }
      return indices;
  }