fixed bug in nrvec::concatme

This commit is contained in:
Jiri Pittner 2022-06-21 17:33:16 +02:00
parent e8641c2833
commit 2621f444e1
2 changed files with 17 additions and 4 deletions

13
t.cc
View File

@ -2539,7 +2539,7 @@ cout<<"big "<<xx1<<endl;
cout << "TEST "<<(xx<xx1) <<" "<<(xx>xx2) <<endl;
}
if(1)
if(0)
{
int seed;
int f=open("/dev/random",O_RDONLY);
@ -2574,6 +2574,15 @@ cout <<test;
cout <<"Error = "<<(expitszsz-test).norm()<<endl;
}
if(1)
{
NRVec<double> x({1,2,3});
NRVec<double> y({4,5,6});
//cout <<x.concat(y);
x.append(10.);
cout <<x;
x.concatme(y);
cout <<x;
}
}

8
vec.h
View File

@ -244,14 +244,18 @@ public:
//!concatenate vector into *this
void concatme(const NRVec &rhs)
{
NOT_GPU(*this);
if(rhs.nn==0) return;
int nnold=nn;
resize(nn+rhs.nn,true);
for(int i=0; i<rhs.nn; ++i) *(this)[nn+i] = rhs[i];
for(int i=0; i<rhs.nn; ++i) v[nnold+i] = rhs[i];
}
void append(const T &a) //not efficient if done repeatedly
{
NOT_GPU(*this);
int nnold=nn;
resize(nn+1,true);
(*this)[nn] = a;
v[nnold] = a;
}
//! determine the actual value of the reference counter