本文整理汇总了C++中Vec::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ Vec::clear方法的具体用法?C++ Vec::clear怎么用?C++ Vec::clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vec
的用法示例。
在下文中一共展示了Vec::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST(VecOpr,Add_Sub){
Vec A;
Vec B;
for(int i=0;i<10;i++){
for(double c=-10;c<=10;c+=1){
EXPECT_TRUE(((A)+(B)).size()==A.size());
EXPECT_TRUE(((A)-(B)).size()==A.size());
}
A.push_back(Rand(engine));
B.push_back(Rand(engine));
}
A.clear();
B.clear();
for(int i=0;i<10;i++){
for(double c=-10;c<=10;c+=1){
Vec C=(A)+(B);
Vec D=(C)-(B);
for(size_t i=0,n=A.size();i<n;i++){
EXPECT_TRUE(D[i]==A[i]);
EXPECT_TRUE(C[i]==(A[i]+B[i]));
}
}
A.push_back(Rand(engine));
B.push_back(Rand(engine));
}
}
示例2: sortedUnique
void Lib::sortedUnique(int n, double *x, Vec& uv)
{
uv.clear();
if(n==0) return;
typedef std::vector<double>::size_type vec_sz;
//copy x into vector xv
Vec xv(n);
vec_sz nv = (vec_sz)n;
for(vec_sz i=0;i<nv;i++) xv[i] = *(x+i);
//sort xv
std::sort(xv.begin(),xv.end());
//get unique values of xv into uv
uv.push_back(xv[0]);
vec_sz nu = 1;
double ov = uv[0];
for(vec_sz i=1;i<nv;i++) {
if(xv[i] != ov) {
ov = xv[i];
uv.push_back(ov);
}
}
}
示例3: denormalize
/*
* This function tries to remove temporary variables in function `fn`
*
* A local variable is removed if:
*
* - It is def'd and use'd once
*
* - Its def is a PRIM_MOVE or PRIM_ASSIGN, with no possible
* communication
* - RHS and LHS are of same type and non-extern
*
* - Its use is a suitable primitive
* - Its use is not repeated(condition/increment statement of a loop)
*
* Denormalization uses helpers in util/exprAnalysis.cpp to decide if
* it's safe to move function calls and primitives.
*/
void denormalize(void) {
UseDefCastMap candidates;
Vec<Symbol*> deferredSyms;
SafeExprAnalysis analysisData;
if(fDenormalize) {
forv_Vec(FnSymbol, fn, gFnSymbols) {
// remove unused epilogue labels
removeUnnecessaryGotos(fn, true);
bool isFirstRound = true;
do {
candidates.clear();
deferredSyms.clear();
// if we are analyzing locals in a function for the first time,
// we look at all the symbols in the function. otherwise we only
// look at the ones deferred in the previous passes on the same
// function
if(isFirstRound) {
findCandidatesInFunc(fn, candidates, analysisData);
}
else {
findCandidatesInFuncOnlySym(fn, deferredSyms, candidates,
analysisData);
}
denormalizeOrDeferCandidates(candidates, deferredSyms);
isFirstRound = false;
} while(deferredSyms.count() > 0);
}
}
示例4: main
int main(){
int cases=0;
while(1){
int n,q;
cin>>n>>q;
if(n==0) break;
++cases;
cout<<"CASE# "<<cases<<":"<<endl;
marble.clear();
int k;
for(int i=0;i<n;++i) {cin>>k;marble.push_back(k);}
sort(marble.begin(),marble.end());
for(int i=0;i<q;i++){
cin>>k;
Vec::iterator it=lower_bound(marble.begin(),marble.end(), k);
if(it!=marble.end() && *it==k){
cout<<k<<" found at "<<it-marble.begin()+1<<endl;
}else{
cout<<k<<" not found"<<endl;
}
}
}
return 0;
}
示例5: acov
void Lib::acov(Vec& x,int nl, Vec& acov, bool cor)
{
typedef Vec::size_type ST;
double c;
int n = (int)x.size();
double m = mean(x);
acov.clear();
for(int i=0;i<=nl;i++)
{
c=0.0;
for(int j=0;j<(n-i);j++) c += (x[j]-m)*(x[j+i]-m);
acov.push_back(c);
}
if(cor)
{
double c0 = acov[0];
for(int i=0;i<=nl;i++)
{
acov[i] = acov[i]/c0;
}
}
else
for(int i=0;i<=nl;i++) acov[i] /= n;
}
示例6: alltoallPersonalized
void alltoallPersonalized(Matpair &buf, int* parents, Vec &nxFr, int size,const int &offset)
{
//how many pairs will be collected from other rank
nxFr.clear();
int sendCount[size];
int recCount[size];
for (int i=0;i<size;i++){
sendCount[i] = 0;
recCount[i] = 0;
}
commCount(buf,sendCount,size);
MPI_Barrier(MPI_COMM_WORLD);
MPI_Alltoall(sendCount,1,MPI_INT,recCount,1, MPI_INT, MPI_COMM_WORLD);
int sendDispl[size];
int recDispl[size];
scan(sendCount, sendDispl,size);
scan(recCount,recDispl,size);
int sendS = sendDispl[size-1]+sendCount[size-1];
int recS = recDispl[size-1]+recCount[size-1];
int sendPar[sendS],recPar[recS],sendNode[sendS],recNode[recS];
vecpair2arrays(buf,sendPar,sendNode,size);
MPI_Alltoallv(sendPar,sendCount,sendDispl,MPI_INT,recPar,recCount,recDispl,MPI_INT,MPI_COMM_WORLD);
MPI_Alltoallv(sendNode,sendCount,sendDispl,MPI_INT,recNode,recCount,recDispl,MPI_INT,MPI_COMM_WORLD);
nextFr(recPar,recNode,recS,offset,parents,nxFr);
}
示例7: Move_AutoGrownMemIO_to_valvec
static void Move_AutoGrownMemIO_to_valvec(AutoGrownMemIO& io, Vec& v) {
BOOST_STATIC_ASSERT(sizeof(typename Vec::value_type) == 1);
BOOST_STATIC_ASSERT(sizeof(v[0]) == 1);
v.clear();
v.risk_set_size(io.tell());
v.risk_set_data((typename Vec::value_type*)io.buf());
v.risk_set_capacity(io.size());
io.risk_release_ownership();
}
示例8: main
int main(){
int kase =0;
while(true){
int c,s,q;
cin>>c>>s>>q;
if (c==0) break;
++kase;
edges.clear();
for(int i=0;i<s;++i){
Edge e;
cin>>e.from>>e.to>>e.weight;
edges.push_back(e);
}
sort(edges.begin(), edges.end());
for(int i=1;i<=c;++i){
nodes[i].parent = nodes+i;
nodes[i].count = 0;
nodes[i].edges.clear();
}
int count =0;
for(Vec::iterator it = edges.begin(); count< c-1 && it!= edges.end(); ++it){
Node *rs = getRoot(it->from), *rt = getRoot(it->to);
if(rs == rt) continue;
if (rs->count > rt->count){
rt->parent = rs;
rs->count+=rt->count;
} else {
rs->parent = rt;
rt->count += rs->count;
}
++count;
nodes[it->from].edges.push_back(*it);
int tmp = it->to;
it->to = it->from; it->from =tmp;
nodes[it->from].edges.push_back(*it);
}
if (kase >1) cout<<endl;
cout<<"Case #"<<kase<<endl;
for(int i=0;i<q; ++i){
int s,t;
cin>>s>>t;
CalcResult result = calc(s,t,0);
if (result.reached) {
cout<<result.value<<endl;
} else {
cout<<"no path"<<endl;
}
}
}
return 0;
}
示例9: batchMeans
void Lib::batchMeans(Vec& x, int bsize, Vec& means)
{
means.clear();
int n = (int)x.size();
bool someleft = (n>=bsize);
int nbatch=0;
while(someleft)
{
double sum = 0.0;
int off = nbatch*bsize;
for(int i=0;i<bsize;i++) sum += x[off+i];
means.push_back(sum/bsize);
nbatch += 1;
someleft = (n>=(bsize)*(nbatch+1));
}
}
示例10: TestTransform
void TestTransform()
{
typedef vector<int> Vec;
Vec test1;
Vec checked1;
Vec checked;
for(int i = 1; i < 5; i++)
{
test1.push_back (i * i); // test1: 1 4 9 16
checked1.push_back (i * i);
}
//vector<int> test2(test1.size());
//transform(test1.begin(), test1.end(), test2.begin(), [](int i){return ++i;}); // test2: 2 5 10 17
Vec test2p;
transform(test1.begin(), test1.end(), back_inserter(test2p), [](int i){return ++i;}); // test2: 2 5 10 17
cout << "Unary operation, the first is the same: ";
checked.push_back(2);
checked.push_back(5);
checked.push_back(10);
checked.push_back(17);
CHECK_RESULTS(IsEqual(test1, checked1));
cout << "Unary operation, the second has changed: ";
CHECK_RESULTS(IsEqual(test2p, checked));
cout << "Binary operation, the first is the same: ";
checked.clear();
checked.push_back(3);
checked.push_back(9);
checked.push_back(19);
checked.push_back(33);
transform(test1.begin(), test1.end(), test2p.begin(), test2p.begin(), [](int i, int j){return i + j;}); // test1: 3 9 19 33
CHECK_RESULTS(IsEqual(test1, checked1));
cout << "Binary operation, the second has changed: ";
CHECK_RESULTS(IsEqual(test2p, checked));
cout << "No elements: ";
test1.erase(test1.begin(), test1.end());
checked.erase(checked.begin(), checked.end());
test2p.erase(test2p.begin(), test2p.end());
transform(test1.begin(), test1.end(), back_inserter(test2p),[](int i){return ++i;});
CHECK_RESULTS(IsEqual(test2p, checked));
}
示例11: main
int main() {
string s;
while(getline(cin,s)) {
cout<<s<<endl;
istringstream iss(s);
pancake.clear();
int k;
while(iss>>k) {
pancake.push_back(k);
}
Vec dest(pancake);
sort(dest.begin(),dest.end());
for(int i=pancake.size()-1; i>=0; i--) {
if(pancake[i]==dest[i]) continue;
int j;
for(j=0; j<i; j++) if(pancake[j]==dest[i]) break;
if(j!=0) flip(j);
flip(i);
}
cout<<'0'<<endl;
}
return 0;
}
示例12: AcceptEventStart
virtual void AcceptEventStart()override{times.clear();}
示例13: clear
void clear() { path_length_valid = false; vec.clear(); }
示例14: init
void init(){
vw.clear(); vw.resize(N);
pf.clear(); pf.resize(N);
vf.clear(); vf.resize(N);
th.clear(); th.resize(N);
}
示例15: clear
void clear() {
v1.clear();
v2.clear();
}