本文整理汇总了C++中array_type类的典型用法代码示例。如果您正苦于以下问题:C++ array_type类的具体用法?C++ array_type怎么用?C++ array_type使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了array_type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compare_rank_2_views
bool compare_rank_2_views(const array_type& y,
const array_type& y_exp,
const scalar_type rel_tol,
const scalar_type abs_tol,
Teuchos::FancyOStream& out)
{
typedef typename array_type::size_type size_type;
typename array_type::HostMirror hy = Kokkos::create_mirror_view(y);
typename array_type::HostMirror hy_exp = Kokkos::create_mirror_view(y_exp);
Kokkos::deep_copy(hy, y);
Kokkos::deep_copy(hy_exp, y_exp);
size_type num_rows = y.dimension_0();
size_type num_cols = y.dimension_1();
bool success = true;
for (size_type i=0; i<num_rows; ++i) {
for (size_type j=0; j<num_cols; ++j) {
scalar_type diff = std::abs( hy(i,j) - hy_exp(i,j) );
scalar_type tol = rel_tol*std::abs(hy_exp(i,j)) + abs_tol;
bool s = diff < tol;
out << "y_expected(" << i << "," << j << ") - "
<< "y(" << i << "," << j << ") = " << hy_exp(i,j)
<< " - " << hy(i,j) << " == "
<< diff << " < " << tol << " : ";
if (s)
out << "passed";
else
out << "failed";
out << std::endl;
success = success && s;
}
}
return success;
}
示例2: decode
static void decode(const array_type& _array, float& _t) {
float _sum = 0.0;
for (int i = 0; i < _array.size(); ++i) {
_sum += (_array[i] / 256.0) * std::pow(256.0,float(i-int(_array.size()/2)));
}
_t = _sum;
}
示例3: encode
static void encode(const float& _t, array_type& _array) {
for (int i = 0; i < _array.size(); ++i) {
float _n = _t / std::pow(256.0,float(i-int(_array.size()/2)));
float _intpart;
float _fractpart = std::modf (_n , &_intpart);
_array[i] = uint8_t(256.0*_fractpart);
}
}
示例4: test
virtual void test()
{
m_nPushError = 0;
for ( array_type::const_iterator it = m_arr.begin(); it != m_arr.end(); ++it ) {
if ( !m_Queue.push( SimpleValue( *it ) ))
++m_nPushError;
}
}
示例5: Integrate
Integrate( array_type & arg_output ,
const array_type & arg_left ,
const array_type & arg_right ) : output(arg_output) , left(arg_left) , right(arg_right)
{
numLeft = left.dimension(1);
numRight = right.dimension(1);
numPoints = left.dimension(2);
dim = left.dimension(3);
if(output.rank() == 2) numLeft = 1;
}
示例6: key
key_type key(const array_type & df, const std::size_t index) const
{
if (df.shape().second == 0)
{
return {0, 0};
}
else
{
const int prod_id = df[df.row(index)][0]; // TODO, hardcoded
const char segment = df[df.row(index)][8]; // TODO, hardcoded
return {prod_id, segment};
}
}
示例7: QL_REQUIRE
inline void TrBDF2Scheme<TrapezoidalScheme>::step(array_type& fn, Time t) {
using namespace ext::placeholders;
QL_REQUIRE(t-dt_ > -1e-8, "a step towards negative time given");
const Time intermediateTimeStep = dt_*alpha_;
array_type fStar = fn;
trapezoidalScheme_->setStep(intermediateTimeStep);
trapezoidalScheme_->step(fStar, t);
bcSet_.setTime(std::max(0.0, t-dt_));
bcSet_.applyBeforeSolving(*map_, fn);
const array_type f =
(1/alpha_*fStar - square<Real>()(1-alpha_)/alpha_*fn)/(2-alpha_);
if (map_->size() == 1) {
fn = map_->solve_splitting(0, f, -beta_);
}
else {
const ext::function<Disposable<Array>(const Array&)>
preconditioner(ext::bind(
&FdmLinearOpComposite::preconditioner, map_, _1, -beta_));
const ext::function<Disposable<Array>(const Array&)> applyF(
ext::bind(&TrBDF2Scheme<TrapezoidalScheme>::apply, this, _1));
if (solverType_ == BiCGstab) {
const BiCGStabResult result =
QuantLib::BiCGstab(applyF, std::max(Size(10), fn.size()),
relTol_, preconditioner).solve(f, f);
(*iterations_) += result.iterations;
fn = result.x;
} else if (solverType_ == GMRES) {
const GMRESResult result =
QuantLib::GMRES(applyF, std::max(Size(10), fn.size()/10u),
relTol_, preconditioner).solve(f, f);
(*iterations_) += result.errors.size();
fn = result.x;
}
else
QL_FAIL("unknown/illegal solver type");
}
bcSet_.applyAfterSolving(fn);
}
示例8: aInit
inline void TRBDF2<Operator>::step(array_type& a, Time t) {
Size i;
Array aInit(a.size());
for (i=0; i<a.size();i++) {
aInit[i] = a[i];
}
aInit_ = aInit;
for (i=0; i<bcs_.size(); i++)
bcs_[i]->setTime(t);
//trapezoidal explicit part
if (L_.isTimeDependent()) {
L_.setTime(t);
explicitTrapezoidalPart_ = I_ - 0.5*alpha_*dt_*L_;
}
for (i=0; i<bcs_.size(); i++)
bcs_[i]->applyBeforeApplying(explicitTrapezoidalPart_);
a = explicitTrapezoidalPart_.applyTo(a);
for (i=0; i<bcs_.size(); i++)
bcs_[i]->applyAfterApplying(a);
// trapezoidal implicit part
if (L_.isTimeDependent()) {
L_.setTime(t-dt_);
implicitPart_ = I_ + 0.5*alpha_*dt_*L_;
}
for (i=0; i<bcs_.size(); i++)
bcs_[i]->applyBeforeSolving(implicitPart_,a);
a = implicitPart_.solveFor(a);
for (i=0; i<bcs_.size(); i++)
bcs_[i]->applyAfterSolving(a);
// BDF2 explicit part
if (L_.isTimeDependent()) {
L_.setTime(t);
}
for (i=0; i<bcs_.size(); i++) {
bcs_[i]->applyBeforeApplying(explicitBDF2PartFull_);
}
array_type b0 = explicitBDF2PartFull_.applyTo(aInit_);
for (i=0; i<bcs_.size(); i++)
bcs_[i]->applyAfterApplying(b0);
for (i=0; i<bcs_.size(); i++) {
bcs_[i]->applyBeforeApplying(explicitBDF2PartMid_);
}
array_type b1 = explicitBDF2PartMid_.applyTo(a);
for (i=0; i<bcs_.size(); i++)
bcs_[i]->applyAfterApplying(b1);
a = b0+b1;
// reuse implicit part - works only for alpha=2-sqrt(2)
for (i=0; i<bcs_.size(); i++)
bcs_[i]->applyBeforeSolving(implicitPart_,a);
a = implicitPart_.solveFor(a);
for (i=0; i<bcs_.size(); i++)
bcs_[i]->applyAfterSolving(a);
}
示例9: int
std::unique_ptr<void, int (*)(BoosterHandle)>
fit(const array_type & train_data,
const std::vector<float> & train_y,
const std::map<const std::string, const std::string> & params,
_StopCondition stop_condition)
{
// prepare placeholder for raw matrix later used by xgboost
std::vector<float> train_vec = train_data.tovector();
std::cerr << "train_vec size: " << train_vec.size() << std::endl;
// assert(std::none_of(train_vec.cbegin(), train_vec.cend(), [](float x){return std::isnan(x);}));
std::unique_ptr<void, int (*)(DMatrixHandle)> tr_dmat(
XGDMatrixCreateFromMat(
train_vec.data(),
train_data.shape().first,
train_data.shape().second, XGB_MISSING),
XGDMatrixFree);
// attach response vector to tr_dmat
XGDMatrixSetFloatInfo(tr_dmat.get(), "label", train_y.data(), train_y.size());
const DMatrixHandle cache[] = {tr_dmat.get()};
// create Booster with attached tr_dmat
std::unique_ptr<void, int (*)(BoosterHandle)> booster(
XGBoosterCreate(cache, 1UL),
XGBoosterFree);
for (const auto & kv : params)
{
std::cerr << kv.first << " => " << kv.second << std::endl;
XGBoosterSetParam(booster.get(), kv.first.c_str(), kv.second.c_str());
}
for (int iter{0}; stop_condition() == false; ++iter)
{
XGBoosterUpdateOneIter(booster.get(), iter, tr_dmat.get());
}
return booster;
}
示例10: operator
// Verify:
KOKKOS_INLINE_FUNCTION
void operator()( size_t iwork, value_type & errors ) const
{
const size_t tile_dim0 = ( m_array.dimension_0() + TileLayout::N0 - 1 ) / TileLayout::N0;
const size_t tile_dim1 = ( m_array.dimension_1() + TileLayout::N1 - 1 ) / TileLayout::N1;
const size_t itile = iwork % tile_dim0;
const size_t jtile = iwork / tile_dim0;
if ( jtile < tile_dim1 ) {
tile_type tile = Kokkos::tile_subview( m_array, itile, jtile );
if ( tile( 0, 0 ) != ptrdiff_t( ( itile + jtile * tile_dim0 ) * TileLayout::N0 * TileLayout::N1 ) ) {
++errors;
}
else {
for ( size_t j = 0; j < size_t( TileLayout::N1 ); ++j ) {
for ( size_t i = 0; i < size_t( TileLayout::N0 ); ++i ) {
const size_t iglobal = i + itile * TileLayout::N0;
const size_t jglobal = j + jtile * TileLayout::N1;
if ( iglobal < m_array.dimension_0() && jglobal < m_array.dimension_1() ) {
if ( tile( i, j ) != ptrdiff_t( tile( 0, 0 ) + i + j * TileLayout::N0 ) ) ++errors;
//printf( "tile(%d, %d)(%d, %d) = %d\n", int( itile ), int( jtile ), int( i ), int( j ), int( tile( i, j ) ) );
}
}
}
}
}
}
示例11: prepare
void prepare( size_t nStart, size_t nEnd )
{
m_arr.reserve( nEnd - nStart );
for ( size_t i = nStart; i < nEnd; ++i )
m_arr.push_back( i );
std::random_shuffle( m_arr.begin(), m_arr.end() );
}
示例12: run
// Kernel
void run()
{
dist = sqrt(
(pow(points1, 2).rowwise() * alpha).rowwise().sum().replicate(1, nsample2).rowwise()
+ (pow(points2, 2).rowwise() * alpha).rowwise().sum().transpose()
- 2 * ((points1.rowwise() * alpha).matrix() * points2.matrix().transpose()).array()
);
}
示例13:
//-----------------------------------------------------------------//
handle_set(bool zhe = true, uint32_t fas = 0) : array_(), erase_set_(),
zero_handle_enable_(zhe) {
if(fas) {
array_.reserve(fas);
array_.clear();
}
if(zero_handle_enable_) array_.push_back(T());
}
示例14: insert
//-----------------------------------------------------------------//
handle_type insert(const T& st) {
handle_type h;
if(erase_set_.empty()) {
h = static_cast<handle_type>(array_.size());
array_.push_back(st);
} else {
set_it it = erase_set_.begin();
h = *it;
array_[h] = st;
erase_set_.erase(it);
}
return h;
}
示例15: insert_right
void insert_right(const char c) {
auto insert_point = s.end() - 1;
if( justify == Justify::Left ) {
insert_point = std::find_if(s.begin(), s.end(), [](const char& a) {
return a == ' ';
});
}
if( *insert_point != ' ' ) {
insert_point = shift_left();
}
*insert_point = c;
}