5 #include <KrisLibrary/errors.h> 15 IndexSet(
const std::vector<int>& indices);
16 operator std::vector<int> ()
const;
17 int operator [] (
int i)
const;
18 inline bool IsRange()
const {
return imin<=imax; }
20 int Find(
int index)
const;
22 template <
class T>
void GetElements(
const T& x,T& xind)
const;
23 template <
class T>
void SetElements(
const T& xind,T& x)
const;
26 std::vector<int> indices;
30 void IndexSet::GetElements(
const T& x,T& xind)
const 34 std::copy(x.begin()+imin,x.begin()+imax,xind.begin());
36 for(
size_t i=0;i<indices.size();i++)
37 xind[i] = x[indices[i]];
42 void IndexSet::SetElements(
const T& xind,T& x)
const 44 Assert((
size_t)xind.size()==Size());
47 Assert(imax < (
int)x.size());
48 std::copy(xind.begin(),xind.end(),x.begin()+imin);
51 for(
size_t i=0;i<indices.size();i++) {
52 Assert(indices[i] >= 0 && indices[i] < (
int)x.size());
53 x[indices[i]] = xind[i];
void copy(const T &a, T *out, int n)
Definition: arrayutils.h:34
A generic set of indices, either listed explicitly or in a range. If imax < imin, this indicates that...
Definition: IndexSet.h:10