Exemple #1
0
void checkDenseMatrixEqual(M1 const& m1, M2 const& m2){
	BOOST_REQUIRE_EQUAL(m1.size1(),m2.size1());
	BOOST_REQUIRE_EQUAL(m1.size2(),m2.size2());
	//indexed access
	for(std::size_t i = 0; i != m2.size1(); ++i){
		for(std::size_t j = 0; j != m2.size2(); ++j){
			BOOST_CHECK_EQUAL(m1(i,j),m2(i,j));
		}
	}
	//iterator access rows
	for(std::size_t i = 0; i != m2.size1(); ++i){
		typedef typename M1::const_row_iterator Iter;
		BOOST_REQUIRE_EQUAL(m1.row_end(i)-m1.row_begin(i), m1.size2());
		std::size_t k = 0;
		for(Iter it = m1.row_begin(i); it != m1.row_end(i); ++it,++k){
			BOOST_CHECK_EQUAL(k,it.index());
			BOOST_CHECK_EQUAL(*it,m2(i,k));
		}
		//test that the actual iterated length equals the number of elements
		BOOST_CHECK_EQUAL(k, m1.size2());
	}
	//iterator access columns
	for(std::size_t i = 0; i != m2.size2(); ++i){
		typedef typename M1::const_column_iterator Iter;
		BOOST_REQUIRE_EQUAL(m1.column_end(i)-m1.column_begin(i), m1.size1());
		std::size_t k = 0;
		for(Iter it = m1.column_begin(i); it != m1.column_end(i); ++it,++k){
			BOOST_CHECK_EQUAL(k,it.index());
			BOOST_CHECK_EQUAL(*it,m2(k,i));
		}
		//test that the actual iterated length equals the number of elements
		BOOST_CHECK_EQUAL(k, m1.size1());
	}
}
Exemple #2
0
void checkDenseVectorAssignment(V1& v1, V2 const& v2){
	BOOST_REQUIRE_EQUAL(v1.size(),v2.size());
	//indexed access
	for(std::size_t i = 0; i != v2.size(); ++i){
		v1(i) = 0;
		BOOST_CHECK_EQUAL(v1(i),0);
		v1(i) = v2(i);
		BOOST_CHECK_EQUAL(v1(i),v2(i));
		v1(i) = 0;
		BOOST_CHECK_EQUAL(v1(i),0);
	}
	//iterator access rows
	typedef typename V1::iterator Iter;
	BOOST_REQUIRE_EQUAL(v1.end()-v1.begin(), v1.size());
	std::size_t k = 0;
	for(Iter it = v1.begin(); it != v1.end(); ++it,++k){
		BOOST_CHECK_EQUAL(k,it.index());
		*it = 0;
		BOOST_CHECK_EQUAL(v1(k),0);
		*it = v2(k);
		BOOST_CHECK_EQUAL(v1(k),v2(k));
		*it = 0;
		BOOST_CHECK_EQUAL(v1(k),0);
	}
	//test that the actual iterated length equals the number of elements
	BOOST_CHECK_EQUAL(k, v2.size());
}
Exemple #3
0
  double log_probability(Iter const & iter, int target) const {
    double log_prob = _func->log_probability(iter, target);

    if (std::isnan(log_prob))
      throw QHMMException("NaN detected", "log_probability", true, _stateID, -1, iter.index(), -1);

    return log_prob;
  }
Exemple #4
0
Iter
PhoneBook::searchIndex(const long index, Iter i)
{
    for ( ; i != _records.end(); i++)
        if (i->index()==index)
            return i;
    return i;
}
Exemple #5
0
  double log_probability(Iter const & iter) const {
    double log_prob = _func->log_probability(iter);

    if (std::isnan(log_prob))
      throw QHMMException("NaN detected", "log_probability", false, _stateID, _slotID, iter.index(), iter.emission(_slotID)); // TODO: support higher dimensions!

    return log_prob;
  }