本文整理汇总了C++中VectorType::size方法的典型用法代码示例。如果您正苦于以下问题:C++ VectorType::size方法的具体用法?C++ VectorType::size怎么用?C++ VectorType::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VectorType
的用法示例。
在下文中一共展示了VectorType::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ParallelFor
void ParallelFor(const VectorType& items, const FuncType& func)
{
using SizeType = decltype(items.size());
SizeType totalCount = items.size();
auto lock = AcquireLock();
SizeType offset = 0;
for (int i = 0; i < m_ThreadCount; i++) {
SizeType count = totalCount / static_cast<SizeType>(m_ThreadCount);
if (static_cast<SizeType>(i) < totalCount % static_cast<SizeType>(m_ThreadCount))
count++;
EnqueueUnlocked(lock, [&items, func, offset, count, this]() {
for (SizeType j = offset; j < offset + count; j++) {
RunTaskFunction([&func, &items, j]() {
func(items[j]);
});
}
});
offset += count;
}
ASSERT(offset == items.size());
}
示例2: model
VectorType model(const VectorType& uv, VectorType& x)
{
VectorType y; //Change this to use expression template
int m = Base::values();
int n = Base::inputs();
eigen_assert(uv.size()%2 == 0);
eigen_assert(uv.size() == n);
eigen_assert(x.size() == m);
y.setZero(m);
int half = n/2;
VectorBlock<const VectorType> u(uv, 0, half);
VectorBlock<const VectorType> v(uv, half, half);
Scalar coeff;
for (int j = 0; j < m; j++)
{
for (int i = 0; i < half; i++)
{
coeff = (x(j)-i)/v(i);
coeff *= coeff;
if (coeff < 1. && coeff > 0.)
y(j) += u(i)*std::pow((1-coeff), 2);
}
}
return y;
}
示例3: p_serialSolvePrep
/// Gather the RHS and initial estimate vectors
void p_serialSolvePrep(const VectorType& b, VectorType& x) const
{
// make a buffer for value transfer between vectors
if (p_valueBuffer.empty()) {
p_valueBuffer.resize(b.size());
}
// always collect the RHS vector
if (!p_serialRHS) {
p_serialRHS.reset(b.localClone());
} else {
b.getAllElements(&p_valueBuffer[0]);
p_serialRHS->setElementRange(0, b.size() - 1, &p_valueBuffer[0]);
}
// Collect the initial guess, if it's not zero
if (!p_serialSolution) {
if (!p_guessZero) {
p_serialSolution.reset(x.localClone());
} else {
p_serialSolution.reset(p_serialRHS->clone());
}
} else {
if (!p_guessZero) {
x.getAllElements(&p_valueBuffer[0]);
p_serialSolution->setElementRange(0, x.size() - 1, &p_valueBuffer[0]);
}
}
}
示例4: variable_index_out_of_bounds_exception
numeric_type
operator()(VectorType const & v) const
{
if(id_ >= v.size())
throw variable_index_out_of_bounds_exception(id_, v.size());
return get_from_vector(v, id_);
}
示例5: householder_vector
void householder_vector(VectorType & v, vcl_size_t start)
{
typedef typename VectorType::value_type ScalarType;
ScalarType x_norm = norm_lcl(v, v.size());
ScalarType alpha = -sign(v[start]) * x_norm;
v[start] += alpha;
normalize(v, v.size());
}
示例6: apply
void apply(VectorType & vec) const
{
assert(vec.size() == diag_A_inv.size());
for (size_t i=0; i<vec.size(); ++i)
{
vec[i] *= diag_A_inv[i];
}
}
示例7: operator
numeric_type operator()(VectorType const & v) const
{
std::vector<double> stl_v(v.size());
for (std::size_t i=0; i<v.size(); ++i)
stl_v[i] = v[i];
return this->eval(stl_v);
}
示例8: selectUnion
Selector selectUnion( const VectorType & union_vector )
{
Selector selector;
if (union_vector.size() > 0) {
selector = dereference_if_pointer(union_vector[0]);
for (unsigned i = 1 ; i < union_vector.size() ; ++i) {
selector |= dereference_if_pointer(union_vector[i]);
}
}
return selector;
}
示例9: copy
void copy(const VectorType & cpu_vector,
vector_slice<vector<SCALARTYPE> > & gpu_vector_slice )
{
if (cpu_vector.size() > 0)
{
std::vector<SCALARTYPE> temp_buffer(gpu_vector_slice.stride() * gpu_vector_slice.size());
viennacl::backend::memory_read(gpu_vector_slice.handle(), sizeof(SCALARTYPE)*gpu_vector_slice.start(), sizeof(SCALARTYPE)*temp_buffer.size(), &(temp_buffer[0]));
for (vcl_size_t i=0; i<cpu_vector.size(); ++i)
temp_buffer[i * gpu_vector_slice.stride()] = cpu_vector[i];
viennacl::backend::memory_write(gpu_vector_slice.handle(), sizeof(SCALARTYPE)*gpu_vector_slice.start(), sizeof(SCALARTYPE)*temp_buffer.size(), &(temp_buffer[0]));
}
}
示例10:
template<typename VectorType> void map_static_methods(const VectorType& m)
{
typedef typename VectorType::Index Index;
typedef typename VectorType::Scalar Scalar;
Index size = m.size();
Scalar* array1 = internal::aligned_new<Scalar>(size);
Scalar* array2 = internal::aligned_new<Scalar>(size);
Scalar* array3 = new Scalar[size+1];
Scalar* array3unaligned = internal::UIntPtr(array3)%EIGEN_MAX_ALIGN_BYTES == 0 ? array3+1 : array3;
VectorType::MapAligned(array1, size) = VectorType::Random(size);
VectorType::Map(array2, size) = VectorType::Map(array1, size);
VectorType::Map(array3unaligned, size) = VectorType::Map(array1, size);
VectorType ma1 = VectorType::Map(array1, size);
VectorType ma2 = VectorType::MapAligned(array2, size);
VectorType ma3 = VectorType::Map(array3unaligned, size);
VERIFY_IS_EQUAL(ma1, ma2);
VERIFY_IS_EQUAL(ma1, ma3);
internal::aligned_delete(array1, size);
internal::aligned_delete(array2, size);
delete[] array3;
}
开发者ID:muhammedabdelnasser,项目名称:Vehicle-Steering-Using-Model-Predictive-Control,代码行数:25,代码来源:mapped_matrix.cpp
示例11: UpdateCallback
void DiscretePolicyManager::UpdateCallback( const ros::TimerEvent& event )
{
StampedFeatures inputs;
if( !_inputStreams.ReadStream( event.current_real, inputs ) )
{
ROS_WARN_STREAM( "Could not read input stream." );
return;
}
// Generate probability mass function values
_networkInput.SetOutput( inputs.features );
_networkInput.Invalidate();
_networkInput.Foreprop();
VectorType pmf = _network->GetProbabilitySource().GetOutput();
// Sample from PMF
std::vector<double> weights( pmf.data(), pmf.data() + pmf.size() );
std::vector<unsigned int> draws;
NaiveWeightedSample( weights, 1, draws, _engine );
unsigned int actionIndex = draws[0];
// Convert single index into multiple indices
std::vector<unsigned int> indices;
indices = multibase_long_div( actionIndex, _interface->GetOutputSizes() );
_interface->SetOutput( indices );
// TODO name policy
DiscreteParamAction action( event.current_real,
inputs.features,
actionIndex );
_actionPub.publish( action.ToMsg() );
}
示例12: vectorSum
template<typename VectorType> void vectorSum(const VectorType& w)
{
typedef typename VectorType::Scalar Scalar;
int size = w.size();
VectorType v = VectorType::Random(size);
for(int i = 1; i < size; i++)
{
Scalar s = Scalar(0);
for(int j = 0; j < i; j++) s += v[j];
VERIFY_IS_APPROX(s, v.start(i).sum());
}
for(int i = 0; i < size-1; i++)
{
Scalar s = Scalar(0);
for(int j = i; j < size; j++) s += v[j];
VERIFY_IS_APPROX(s, v.end(size-i).sum());
}
for(int i = 0; i < size/2; i++)
{
Scalar s = Scalar(0);
for(int j = i; j < size-i; j++) s += v[j];
VERIFY_IS_APPROX(s, v.segment(i, size-2*i).sum());
}
}
示例13:
template<typename VectorType> void map_class_vector(const VectorType& m)
{
typedef typename VectorType::Scalar Scalar;
int size = m.size();
// test Map.h
Scalar* array1 = ei_aligned_new<Scalar>(size);
Scalar* array2 = ei_aligned_new<Scalar>(size);
Scalar* array3 = new Scalar[size+1];
Scalar* array3unaligned = std::size_t(array3)%16 == 0 ? array3+1 : array3;
Map<VectorType, Aligned>(array1, size) = VectorType::Random(size);
Map<VectorType>(array2, size) = Map<VectorType>(array1, size);
Map<VectorType>(array3unaligned, size) = Map<VectorType>((const Scalar*)array1, size); // test non-const-correctness support in eigen2
VectorType ma1 = Map<VectorType>(array1, size);
VectorType ma2 = Map<VectorType, Aligned>(array2, size);
VectorType ma3 = Map<VectorType>(array3unaligned, size);
VERIFY_IS_APPROX(ma1, ma2);
VERIFY_IS_APPROX(ma1, ma3);
ei_aligned_delete(array1, size);
ei_aligned_delete(array2, size);
delete[] array3;
}
示例14:
// Constant vector tests.
TEST_F(SmallVectorTest, ConstVectorTest) {
const VectorType constVector;
EXPECT_EQ(0u, constVector.size());
EXPECT_TRUE(constVector.empty());
EXPECT_TRUE(constVector.begin() == constVector.end());
}
示例15: symmEig
template<typename MatrixType> void generalized_eigensolver_real(const MatrixType& m)
{
typedef typename MatrixType::Index Index;
/* this test covers the following files:
GeneralizedEigenSolver.h
*/
Index rows = m.rows();
Index cols = m.cols();
typedef typename MatrixType::Scalar Scalar;
typedef typename NumTraits<Scalar>::Real RealScalar;
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
typedef Matrix<RealScalar, MatrixType::RowsAtCompileTime, 1> RealVectorType;
typedef typename std::complex<typename NumTraits<typename MatrixType::Scalar>::Real> Complex;
MatrixType a = MatrixType::Random(rows,cols);
MatrixType b = MatrixType::Random(rows,cols);
MatrixType a1 = MatrixType::Random(rows,cols);
MatrixType b1 = MatrixType::Random(rows,cols);
MatrixType spdA = a.adjoint() * a + a1.adjoint() * a1;
MatrixType spdB = b.adjoint() * b + b1.adjoint() * b1;
// lets compare to GeneralizedSelfAdjointEigenSolver
GeneralizedSelfAdjointEigenSolver<MatrixType> symmEig(spdA, spdB);
GeneralizedEigenSolver<MatrixType> eig(spdA, spdB);
VERIFY_IS_EQUAL(eig.eigenvalues().imag().cwiseAbs().maxCoeff(), 0);
VectorType realEigenvalues = eig.eigenvalues().real();
std::sort(realEigenvalues.data(), realEigenvalues.data()+realEigenvalues.size());
VERIFY_IS_APPROX(realEigenvalues, symmEig.eigenvalues());
}