added: a helper for interleaving vectors

This commit is contained in:
Arne Morten Kvarving
2015-12-16 13:02:30 +01:00
committed by Knut Morten Okstad
parent 6958acfed7
commit c9218f7f17
2 changed files with 24 additions and 0 deletions

View File

@@ -400,3 +400,18 @@ void utl::merge (std::vector<Real>& a1, const std::vector<Real>& a2,
if (std::find(k1.begin(),k1.end(),k2[i]) == k1.end())
a1.push_back(a2[i]);
}
void utl::interleave(const std::vector<Real>& v1, const std::vector<Real>& v2,
std::vector<Real>& out, size_t n1, size_t n2)
{
out.resize(v1.size()+v2.size());
auto it_v1 = v1.begin();
auto it_v2 = v2.begin();
for (auto it_out = out.begin(); it_out != out.end();
it_out += n1+n2, it_v1 += n1, it_v2 += n2) {
std::copy(it_v1, it_v1+n1, it_out);
std::copy(it_v2, it_v2+n2, it_out+n1);
}
}

View File

@@ -152,6 +152,15 @@ namespace utl
const std::vector<Real>& in, std::vector<Real>& out,
size_t offset_in = 0, int shift_idx = 0);
//! \brief Interleave vectors
//! \param[in] v1 The first array
//! \param[in] v2 The second array
//! \param[out] out The output array
//! \param[in] n1 Number of entries per node in first vector
//! \param[in] n2 Number of entries per node in second vector
void interleave(const std::vector<Real>& v1, const std::vector<Real>& v2,
std::vector<Real>& out, size_t n1 = 1, size_t n2 = 1);
//! \brief Searches for a real value in an ordered array of reals.
//! \param[in] a The array of real values
//! \param[in] v The value to search for