本文整理汇总了C++中ublas::vector类的典型用法代码示例。如果您正苦于以下问题:C++ vector类的具体用法?C++ vector怎么用?C++ vector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了vector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: decodeBPSK
ublas::vector<int> decodeBPSK(const ublas::vector<double> &rx) {
ublas::vector<int> vHat(rx.size());
for (unsigned int i = 0; i < rx.size(); i++) {
vHat(i) = 0.5 * (sign(rx(i)) + 1);
}
return vHat;
}
示例2: getHomLength
const float NaoPose::getHomLength(const ublas::vector<float> &vec) {
float sum = 0.0f;
for (ublas::vector<float>::const_iterator i = vec.begin(); i != vec.end()
- 1; ++i) {
sum += *i * *i;
}
return sqrt(sum);
}
示例3: addVector
/**
* \f$U+=V \f$ where U and V are type
* uvlas::vector<T> and you
* want to specify WHERE to add
* the DenseVector<T> V
*/
void addVector ( const ublas::vector<value_type>& V,
const std::vector<size_type>& dof_indices )
{
FEELPP_ASSERT ( V.size() == dof_indices.size() ).error( "invalid dof indices" );
for ( size_type i=0; i<V.size(); i++ )
this->add ( dof_indices[i], V( i ) );
}
示例4: biterr
double biterr(const ublas::vector<int> &u, const ublas::vector<int> &v) {
int numErr = 0;
for (unsigned int i = 0; i < u.size(); i++) {
if (u(i) != v(i)) {
numErr++;
}
}
return static_cast<double>(numErr) / u.size();
}
示例5: cross
ublas::vector<T> cross( const ublas::vector<T> &a, const ublas::vector<T> &b )
{
BOOST_ASSERT(a.size() == 3);
BOOST_ASSERT(b.size() == 3);
ublas::vector<T> result(3);
result(0) = a(1) * b(2) - a(2) * b(1);
result(1) = a(2) * b(0) - a(0) * b(2);
result(2) = a(0) * b(1) - a(1) * b(0);
return result;
}
示例6: printVector
void printVector(const ublas::vector<T> &u) {
for (unsigned int i = 0; i < u.size(); i++) {
std::cout << u(i);
if (i + 1 < u.size()) {
std::cout << ", ";
}
}
std::cout << std::endl;
}
示例7: mod2
ublas::vector<int> mod2(const ublas::vector<int> &u) {
ublas::vector<int> v(u.size());
for (unsigned int i = 0; i < u.size(); i++) {
v(i) = u(i) % 2;
// modulus result can be negative if u(i) negative, depending on implementation
if (v(i) < 0) {
v(i) += 2;
}
}
return v;
}
示例8: diff
ScalarType diff(ublas::vector<ScalarType> & v1, viennacl::vector<ScalarType> & v2)
{
ublas::vector<ScalarType> v2_cpu(v2.size());
viennacl::backend::finish();
viennacl::copy(v2.begin(), v2.end(), v2_cpu.begin());
for (unsigned int i=0;i<v1.size(); ++i)
{
if ( std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) ) > 0 )
{
//if (std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) ) < 1e-10 ) //absolute tolerance (avoid round-off issues)
// v2_cpu[i] = 0;
//else
v2_cpu[i] = std::fabs(v2_cpu[i] - v1[i]) / std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) );
}
else
v2_cpu[i] = 0.0;
if (v2_cpu[i] > 0.0001)
{
//std::cout << "Neighbor: " << i-1 << ": " << v1[i-1] << " vs. " << v2_cpu[i-1] << std::endl;
std::cout << "Error at entry " << i << ": " << v1[i] << " vs. " << v2_cpu[i] << std::endl;
//std::cout << "Neighbor: " << i+1 << ": " << v1[i+1] << " vs. " << v2_cpu[i+1] << std::endl;
exit(EXIT_FAILURE);
}
}
return norm_inf(v2_cpu);
}
示例9: dirichlet_rnd
ublas::vector<double> dirichlet_rnd(const ublas::vector<int>& nz) {
//! Returns sample from a Dirichlet distribution with dimension k = len(nz).
int k = nz.size();
ublas::vector<double> A(k);
for (int i=0; i<k; ++i) {
A(i) = Rmath::rgamma(1+nz(i), 1);
}
return A/sum(A);
}
示例10: diff
ScalarType diff ( ublas::vector<ScalarType> & v1, viennacl::vector<ScalarType,Alignment> & v2 ) {
ublas::vector<ScalarType> v2_cpu ( v2.size() );
viennacl::copy( v2.begin(), v2.end(), v2_cpu.begin() );
for ( unsigned int i=0; i<v1.size(); ++i ) {
if ( std::max ( fabs ( v2_cpu[i] ), fabs ( v1[i] ) ) > 0 )
v2_cpu[i] = fabs ( v2_cpu[i] - v1[i] ) / std::max ( fabs ( v2_cpu[i] ), fabs ( v1[i] ) );
else
v2_cpu[i] = 0.0;
}
return norm_inf ( v2_cpu );
}
示例11:
/** returns the first n elites
* @param p_start start value of the elite values
* @param p_end end value of the elite values ([start, end) elite elements must be created)
* @param p_population const reference to the population
* @param p_rankIndex rank index (first index has the position of the population element, that has the smalles fitness value)
* @param p_elite vector with elite individual
**/
template<typename T, typename L> inline void bestof<T,L>::getElite( const std::size_t& p_start, const std::size_t& p_end, const std::vector< boost::shared_ptr< individual::individual<L> > >& p_population, const ublas::vector<T>&, const ublas::vector<std::size_t>& p_rankIndex, const ublas::vector<std::size_t>&, std::vector< boost::shared_ptr< individual::individual<L> > >& p_elite )
{
const std::size_t l_end = std::min(p_end, m_number);
std::size_t n = p_start;
for(std::size_t i=p_start; i < p_end; ++i) {
p_elite.push_back( p_population[p_rankIndex[p_rankIndex.size()-1-n]] );
n++;
if (n >= l_end)
n = p_start;
}
}
示例12: diff
ScalarType diff(ublas::vector<ScalarType> const & v1, VCLVectorType const & v2)
{
ublas::vector<ScalarType> v2_cpu(v2.size());
viennacl::backend::finish(); //workaround for a bug in APP SDK 2.7 on Trinity APUs (with Catalyst 12.8)
viennacl::copy(v2.begin(), v2.end(), v2_cpu.begin());
for (unsigned int i=0;i<v1.size(); ++i)
{
if (v2_cpu[i] != v1[i])
return 1;
}
return 0;
}
示例13: ranks
Serialization SDPSeriationGen::Impl::readout_plain(ublas::vector<double>& x,const AdjMat::AdjMatT& adj)
{
unsigned int n = x.size();
// tricky: make sure x > 0 at all times.
x += ublas::scalar_vector<double>(n, 1 - (*min_element(x.begin(),x.end())));
Serialization::RankT ranks(n);
std::vector<bool> done(n,false);
// find highest component of x
ublas::vector<double>::iterator it = BEST_ELEM(x);
int idx = std::distance(x.begin(),it);
L("Determine Actual Path through Graph.\n");
for(unsigned int i=0;i<n;i++){
ranks[i] = idx;
done[idx] = true;
*it = 0.0;
it = BEST_ELEM(x);
idx = std::distance(x.begin(),it);
}
return Serialization(ranks);
}
示例14: diff
ScalarType diff(ublas::vector<ScalarType> & v1, viennacl::vector<ScalarType> & v2)
{
ublas::vector<ScalarType> v2_cpu(v2.size());
viennacl::backend::finish(); //workaround for a bug in APP SDK 2.7 on Trinity APUs (with Catalyst 12.8)
viennacl::copy(v2.begin(), v2.end(), v2_cpu.begin());
for (std::size_t i=0;i<v1.size(); ++i)
{
if ( std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) ) > 0 )
v2_cpu[i] = std::fabs(v2_cpu[i] - v1[i]) / std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) );
else
v2_cpu[i] = 0.0;
}
return norm_inf(v2_cpu);
}
示例15: image2vector_2d
void image2vector_2d(const ublas::fixed_vector<size_t, 2> size, const float_accessor_t & image, ublas::vector<float_t> & vector)
{
if(image.size() != size)
throw Exception("Exception: Dimensions of image and grid do not agree in Image2Grid::image2vector().");
size_t n_x_vertices = size(0);
size_t n_y_vertices = size(1);
vector.resize(n_x_vertices * n_y_vertices, false);
for(size_t i = 0; i < n_x_vertices; i++)
for(size_t j = 0; j < n_y_vertices; ++j)
{
size_t vertex_index = i + j * n_x_vertices;
vector(vertex_index) = image[ublas::fixed_vector<size_t, 2>(i, j)];
}
}