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 ConvergenceTable::save(const char* filename) const
{
  if (num_columns() == 0) throw Hermes::Exceptions::Exception("No data columns defined.");
  for (unsigned int i = 1; i < num_columns(); i++)
    if (columns[i].data.size() != num_rows())
      throw Hermes::Exceptions::Exception("Incompatible column sizes."); 
  
  FILE* f = fopen(filename, "w");
  if (f == NULL) throw Hermes::Exceptions::Exception("Error writing to %s.", filename);
    
  for (unsigned int i = 0; i < num_columns(); i++)
    fprintf(f, columns[i].label.c_str());
  fprintf(f, "\n");
  
  for (int j = 0; j < num_rows(); j++)
  {
    for (unsigned int i = 0; i < num_columns(); i++)
    {
      if (columns[i].data[j].data_type == Column::Entry::INT)
        fprintf(f, columns[i].format.c_str(), columns[i].data[j].ivalue);
      else if (columns[i].data[j].data_type == Column::Entry::DOUBLE)
        fprintf(f, columns[i].format.c_str(), columns[i].data[j].dvalue);
    }
    fprintf(f, "\n");
  }
  
  fclose(f);
  Hermes::Mixins::Loggable::Static::info("Convergence table saved to file '%s'.", filename);
}
Example #3
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 #4
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 #5
0
 static typename V::type eval(M const& m, tag::matrix)
 {
   using value_type = Value_t<M>;
   typename V::type vector(num_rows(m), value_type{0});
   for (size_t i = 0; i < num_rows(m); ++i)
     vector(i) = m(i,i);
   return vector;
 }
void Dataset::next() {
  if (ds_state == dsSelect) {
    fbof = false;
    if (frecno<num_rows()-1) {
      frecno++;
      feof = false;
    } else feof = true;
    if (num_rows()<=0) fbof = feof = true;
  }
}
Example #7
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];
}
 void operator() (const m_type& u, m_type& f)
 {
     for (int r= 0; r < num_rows(u); r++)
         for (int c= 0; c < num_columns(u); c++) {
             f(r, c)= 4 * u(r, c);
             if (r > 0) f(r, c)-= u(r-1, c);
             if (r < num_rows(u)-1) f(r, c)-= u(r+1, c);
             if (c > 0) f(r, c)-= u(r, c-1);
             if (c < num_columns(u)-1) f(r, c)-= u(r, c+1);
         }
 }
inline void smat_smat_mult(const MatrixA& a, const MatrixB& b, MatrixC& c, Assign, 
			   tag::col_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= double(a.nnz()) / num_rows(a), avb= double(b.nnz()) / num_rows(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, MatrixA>::type  a_cursor_type;
    a_cursor_type a_cursor = begin<tag::col>(a), a_cend = end<tag::col>(a); 

    typedef typename traits::range_generator<tag::row, MatrixB>::type  b_cursor_type;
    b_cursor_type b_cursor = begin<tag::row>(b);

    for (unsigned ca= 0; a_cursor != a_cend; ++ca, ++a_cursor, ++b_cursor) {

	// Iterate over non-zeros of A's 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

	    // Iterate over non-zeros of B's 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;		
	    }
	}
    }
}
Example #10
0
inline void smat_smat_mult(const MatrixA& A, const MatrixB& B, MatrixC& C, Assign, 
			   tag::col_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= double(A.nnz()) / num_rows(A), avb= double(B.nnz()) / num_rows(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, MatrixA>::type  A_cursor_type;
    A_cursor_type A_cursor = begin<tag::col>(A), A_cend = end<tag::col>(A); 

    typedef typename traits::range_generator<tag::row, MatrixB>::type  B_cursor_type;
    B_cursor_type B_cursor = begin<tag::row>(B);

    for (unsigned ca= 0; A_cursor != A_cend; ++ca, ++A_cursor, ++B_cursor) {

	// Iterate over non-zeros of A's 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

	    // Iterate over non-zeros of B's 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;		
	    }
	}
    }
}
Example #11
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 #12
0
void test_rows() {
  // Create a table named "Table".
  auto db = grnxx::open_db("");
  auto table = db->create_table("Table");

  // Append the first row.
  grnxx::Int row_id = table->insert_row();
  assert(row_id.raw() == 0);
  assert(table->num_rows() == 1);
  assert(table->max_row_id().match(row_id));
  assert(!table->test_row(grnxx::Int(-1)));
  assert(table->test_row(grnxx::Int(0)));
  assert(!table->test_row(grnxx::Int(1)));

  // Append two more rows.
  assert(table->insert_row().raw() == 1);
  assert(table->insert_row().raw() == 2);
  assert(table->num_rows() == 3);
  assert(table->max_row_id().raw() == 2);
  assert(table->test_row(grnxx::Int(0)));
  assert(table->test_row(grnxx::Int(1)));
  assert(table->test_row(grnxx::Int(2)));
  assert(!table->test_row(grnxx::Int(3)));

  // Remove the second row.
  table->remove_row(grnxx::Int(1));
  assert(table->num_rows() == 2);
  assert(table->max_row_id().raw() == 2);
  assert(table->test_row(grnxx::Int(0)));
  assert(!table->test_row(grnxx::Int(1)));
  assert(table->test_row(grnxx::Int(2)));
  assert(!table->test_row(grnxx::Int(3)));

  // Remove the first row.
  table->remove_row(grnxx::Int(0));
  assert(table->num_rows() == 1);
  assert(table->max_row_id().raw() == 2);
  assert(!table->test_row(grnxx::Int(0)));
  assert(!table->test_row(grnxx::Int(1)));
  assert(table->test_row(grnxx::Int(2)));
  assert(!table->test_row(grnxx::Int(3)));

  // Remove the third row.
  table->remove_row(grnxx::Int(2));
  assert(table->num_rows() == 0);
  assert(table->max_row_id().is_na());
  assert(!table->test_row(grnxx::Int(0)));
  assert(!table->test_row(grnxx::Int(1)));
  assert(!table->test_row(grnxx::Int(2)));
  assert(!table->test_row(grnxx::Int(3)));
}
Example #13
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 #14
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 save_construct_data(
    Archive & ar, const DistributedBoxCollection<DIM> * t, const unsigned int file_version)
{
    // Save the number of rows that each process owns, so that on loading we can resume with
    // good load balance
    int num_local_rows = (int)(t->GetNumRowsOfBoxes());
    std::vector<int> num_rows(PetscTools::GetNumProcs());
    MPI_Gather(&num_local_rows, 1, MPI_INT, &num_rows[0], 1, MPI_INT, 0, PETSC_COMM_WORLD);

    if (PetscTools::AmMaster())
    {
        bool are_boxes_set = t->GetAreLocalBoxesSet();
        ar << are_boxes_set;

        c_vector<double, 2*DIM> domain_size = t->rGetDomainSize();
        for (unsigned i=0; i<2*DIM; i++)
        {
            ar << domain_size[i];
        }

        double box_width = t->GetBoxWidth();
        ar << box_width;

        unsigned num_procs = PetscTools::GetNumProcs();
        ar << num_procs;

        std::vector<int> const const_num_rows = num_rows;
        ar << const_num_rows;
    }
}
Example #16
0
    inline void execute(query_context& context) {
        if (m_random_seed != -1) {
            random::get_source().seed(m_random_seed + thread::thread_id());
        }
        while(1) {
            auto rows = context.get_next(0);
            if (rows == nullptr)
                break;
            auto output = context.get_output_buffer();
            output->resize(1, rows->num_rows());

            auto iter = rows->cbegin();
            auto output_iter = output->begin();
            while(iter != rows->cend()) {
                auto outval = m_transform_fn((*iter));
                if (m_output_type == flex_type_enum::UNDEFINED ||
                        outval.get_type() == m_output_type ||
                        outval.get_type() == flex_type_enum::UNDEFINED) {
                    (*output_iter)[0] = outval;
                } else {
                    flexible_type f(m_output_type);
                    f.soft_assign(outval);
                    (*output_iter)[0] = f;
                }
                ++output_iter;
                ++iter;
            }
            context.emit(output);
        }
    }
Example #17
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;
			}				
		}
	}
}
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 #19
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 #20
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));
     }
 };
void SparseSystem::add_row(const SparseVector& new_row, double new_r) {
  ensure_num_cols(new_row.last()+1);

  append_new_rows(1);
  int row = num_rows() - 1;
  _rhs(row) = new_r;
  set_row(row, new_row);
}
Example #22
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 #23
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 #24
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 #25
0
void Dataset::prev() {
  if (ds_state == dsSelect) {
    feof = false;
    if (frecno) {
      frecno--;
      fbof = false;
    } else fbof = true;
    if (num_rows()<=0) fbof = feof = true;
  }
}
int main(int, char**)
{
    mtl::dense_vector<double> x(10);
    unsigned int size1 = num_rows(x);
    unsigned int size2 = mtl::num_rows(x);              // does not compile with friend definition
    unsigned int size3 = mtl::num_rows(x);      // does not compile with friend definition either

    std::cout << size1 + size2 + size3 << "\n";

    return 0; 
}
Example #27
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 #28
0
	static void apply(matrix_expression<MatrixExprT> const& me, UnaryFunctorT f)
	{
		typedef typename matrix_traits<MatrixExprT>::size_type size_type;

		size_type nr = num_rows(me);
		size_type nc = num_columns(me);
		for (size_type r = 0; r < nr; ++r)
		{
			for (size_type c = 0; c < nc; ++c)
			{
				f(me()(r,c));
			}
		}
	}
Example #29
0
Song::Song(int id) {
	MYSQL_RES* res = query("SELECT id, title, path, type FROM song WHERE id = '" + esc(intString(id)) + "'");

	if (num_rows(res)) {
		MYSQL_ROW row = next_res(res);

		this->id = stringInt(row[0]);
		this->title = row[1];
		this->path = row[2];
		this->type = row[3];
	}

	free_res(res);
}
int _database::getUsers(MYSQL *conn, int num, std::mutex &t_mutex)
{
	std::stringstream ss;
	ss << num;
	t_mutex.lock();
	if (!query(conn, "SELECT * FROM `users` WHERE `Online`='" + ss.str() + "'"))
	{
		t_mutex.unlock();
		return 0;
	}
	t_mutex.unlock();
	MYSQL_RES *res = store_result(conn);
	return (int) num_rows(res);
}