本文整理汇总了C++中std::valarray类的典型用法代码示例。如果您正苦于以下问题:C++ valarray类的具体用法?C++ valarray怎么用?C++ valarray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了valarray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MonomDegreeOrder
bool ReedMullerCoder::MonomDegreeOrder(const std::valarray<bool>& lhs, const std::valarray<bool>& rhs) {
if (lhs.size() != rhs.size()) {
return 0;
}
if (Weight(lhs) < Weight(rhs)) {
return 1;
}
if (Weight(lhs) > Weight(rhs)) {
return 0;
}
for (int i = rhs.size() - 1; i >= 0; --i) {
if (lhs[i] > rhs[i]) {
return 1;
}
if (lhs[i] < rhs[i]) {
return 0;
}
}
return false;
}
示例2: CEREAL_SAVE_FUNCTION_NAME
//! Saving for std::valarray arithmetic types, using binary serialization, if supported
template<class Archive, class T> inline typename std::enable_if<
traits::is_output_serializable<BinaryData<T>, Archive>::value
&& std::is_arithmetic<T>::value, void>::type CEREAL_SAVE_FUNCTION_NAME(
Archive & ar, std::valarray<T> const & valarray) {
ar(make_size_tag(static_cast<size_type>(valarray.size()))); // number of elements
ar(binary_data(&valarray[0], valarray.size() * sizeof(T))); // &valarray[0] ok since guaranteed contiguous
}
示例3: find_histogram
int find_histogram(const std::valarray<T>& vol, std::valarray<int>& hist, unsigned int bins,
T& min, T& max)
{
// size and zero the histogram
hist.resize(bins); hist = 0;
if(min == max) { min = vol.min(); max = vol.max(); }
int validsize(-1);
if(min != max) {
double fA = bins / double(max - min);
double fB = (bins * -min) / double(max - min);
validsize = 0;
for(unsigned int i = 0; i < vol.size(); ++i) {
unsigned int idx = unsigned(fA * vol[i] + fB);
++hist[ std::max(unsigned(0), std::min(idx, bins - 1)) ];
++validsize;
}
}
return validsize;
}
示例4: addData
void addData(const std::valarray<T>& statData,
const std::valarray<T> binData)
{
size_t s = statData.size();
if (s!=binData.size())
{
SparseBinnedStatsException e("Input arrays not the same length.");
GPSTK_THROW(e);
}
bool thisRejected;
for (size_t i=0; i<s; i++)
{
thisRejected=true;
for (size_t j=0; j<bins.size(); j++)
{
if ( bins[j].within(binData[i]) )
{
stats[j].Add(statData[i]);
thisRejected = false;
}
}
if (thisRejected)
rejectedCount++;
else
usedCount++;
}
};
示例5: dist
double dist(const std::valarray<double>& a, const std::valarray<double>& b) const
{
#ifdef DEBUG
if (a.size()!=b.size()) ERROR("Vector size mismatch in distance.");
#endif
return pdist(&a[0],&b[0],a.size());
}
示例6: set_points
void set_points(const FMatrix<double>& nP, const FMatrix<double>& np, const std::valarray<double>& nw=std::valarray<double>(0))
{
if ((n=nP.rows())<1 || (D=nP.cols())<1) ERROR("Hi-dimensional array has inconsistent sizes.");
if (np.rows()!=n || (d=np.cols())<1 || d>D) ERROR("Low-dimensional array has inconsistent sizes.");
P=nP; p=np; ftainted=true;
w.resize(n); if (nw.size()==0) w=1.0; else w=nw;
}
示例7: addData
void addData(const std::valarray<T>& statData,
const std::valarray<T>& binDataX,
const std::valarray<T>& binDataY)
{
size_t s = statData.size();
if ( (s!=binDataX.size()) || (s!=binDataY.size()) )
{
DenseBinnedStatsException e("Input arrays not the same length.");
GPSTK_THROW(e);
}
T thisX, thisY;
for (size_t i=0; i<s; i++)
{
thisX = binDataX[i];
thisY = binDataY[i];
if ( (thisX < minX) || (thisX > maxX ) ||
(thisY < minY) || (thisY > maxY) )
rejectedCount++;
else
{
size_t ibin = static_cast<size_t>(std::floor((thisX - minX)*stats.size()/(maxX-minX)));
size_t jbin = static_cast<size_t>(std::floor((thisY-minY)*(stats[ibin].size()/(maxY-minY))));
stats[ibin][jbin].Add(statData[i]);
// find right bin and Add()
usedCount++;
}
}
};
示例8: RandomTestOctic
void RandomTestOctic(std::valarray<T> & coefficients, std::valarray<T> & solutions)
{
solutions.resize(8);
for (int ii=0; ii<8; ii++)
solutions[ii] = Random<T>::Generate();
const T& s0 = solutions[0];
const T& s1 = solutions[1];
const T& s2 = solutions[2];
const T& s3 = solutions[3];
const T& s4 = solutions[4];
const T& s5 = solutions[5];
const T& s6 = solutions[6];
const T& s7 = solutions[7];
coefficients.resize(8); // omitting the 1, so it's monic
coefficients[0] = s0*s1*s2*s3*s4*s5*s6*s7;
coefficients[1] = - s7*(s6*(s5*(s4*(s3*(s2*(s0 + s1) + s0*s1) + s0*s1*s2) + s0*s1*s2*s3) + s0*s1*s2*s3*s4) + s0*s1*s2*s3*s4*s5) - s0*s1*s2*s3*s4*s5*s6;
coefficients[2] = s7*(s6*(s4*(s3*(s2*(s0 + s1) + s0*s1) + s0*s1*s2) + s5*(s4*(s2*(s0 + s1) + s0*s1 + s3*(s0 + s1 + s2)) + s3*(s2*(s0 + s1) + s0*s1) + s0*s1*s2) + s0*s1*s2*s3) + s5*(s4*(s3*(s2*(s0 + s1) + s0*s1) + s0*s1*s2) + s0*s1*s2*s3) + s0*s1*s2*s3*s4) + s6*(s5*(s4*(s3*(s2*(s0 + s1) + s0*s1) + s0*s1*s2) + s0*s1*s2*s3) + s0*s1*s2*s3*s4) + s0*s1*s2*s3*s4*s5;
coefficients[3] = - s7*(s4*(s3*(s2*(s0 + s1) + s0*s1) + s0*s1*s2) + s5*(s4*(s2*(s0 + s1) + s0*s1 + s3*(s0 + s1 + s2)) + s3*(s2*(s0 + s1) + s0*s1) + s0*s1*s2) + s6*(s5*(s2*(s0 + s1) + s0*s1 + s3*(s0 + s1 + s2) + s4*(s0 + s1 + s2 + s3)) + s4*(s2*(s0 + s1) + s0*s1 + s3*(s0 + s1 + s2)) + s3*(s2*(s0 + s1) + s0*s1) + s0*s1*s2) + s0*s1*s2*s3) - s6*(s4*(s3*(s2*(s0 + s1) + s0*s1) + s0*s1*s2) + s5*(s4*(s2*(s0 + s1) + s0*s1 + s3*(s0 + s1 + s2)) + s3*(s2*(s0 + s1) + s0*s1) + s0*s1*s2) + s0*s1*s2*s3) - s5*(s4*(s3*(s2*(s0 + s1) + s0*s1) + s0*s1*s2) + s0*s1*s2*s3) - s0*s1*s2*s3*s4;
coefficients[4] = s7*(s5*(s2*(s0 + s1) + s0*s1 + s3*(s0 + s1 + s2) + s4*(s0 + s1 + s2 + s3)) + s4*(s2*(s0 + s1) + s0*s1 + s3*(s0 + s1 + s2)) + s6*(s2*(s0 + s1) + s0*s1 + s5*(s0 + s1 + s2 + s3 + s4) + s3*(s0 + s1 + s2) + s4*(s0 + s1 + s2 + s3)) + s3*(s2*(s0 + s1) + s0*s1) + s0*s1*s2) + s4*(s3*(s2*(s0 + s1) + s0*s1) + s0*s1*s2) + s5*(s4*(s2*(s0 + s1) + s0*s1 + s3*(s0 + s1 + s2)) + s3*(s2*(s0 + s1) + s0*s1) + s0*s1*s2) + s6*(s5*(s2*(s0 + s1) + s0*s1 + s3*(s0 + s1 + s2) + s4*(s0 + s1 + s2 + s3)) + s4*(s2*(s0 + s1) + s0*s1 + s3*(s0 + s1 + s2)) + s3*(s2*(s0 + s1) + s0*s1) + s0*s1*s2) + s0*s1*s2*s3;
coefficients[5] = - s5*(s2*(s0 + s1) + s0*s1 + s3*(s0 + s1 + s2) + s4*(s0 + s1 + s2 + s3)) - s4*(s2*(s0 + s1) + s0*s1 + s3*(s0 + s1 + s2)) - s7*(s2*(s0 + s1) + s0*s1 + s5*(s0 + s1 + s2 + s3 + s4) + s3*(s0 + s1 + s2) + s6*(s0 + s1 + s2 + s3 + s4 + s5) + s4*(s0 + s1 + s2 + s3)) - s6*(s2*(s0 + s1) + s0*s1 + s5*(s0 + s1 + s2 + s3 + s4) + s3*(s0 + s1 + s2) + s4*(s0 + s1 + s2 + s3)) - s3*(s2*(s0 + s1) + s0*s1) - s0*s1*s2;
coefficients[6] = s2*(s0 + s1) + s0*s1 + s7*(s0 + s1 + s2 + s3 + s4 + s5 + s6) + s5*(s0 + s1 + s2 + s3 + s4) + s3*(s0 + s1 + s2) + s6*(s0 + s1 + s2 + s3 + s4 + s5) + s4*(s0 + s1 + s2 + s3);
coefficients[7] = - s0 - s1 - s2 - s3 - s4 - s5 - s6 - s7;
}
示例9: diff
void diff(const std::valarray<double>& a, const std::valarray<double>& b, std::valarray<double>& c) const
{
#ifdef DEBUG
if (a.size()!=b.size()) ERROR("Vector size mismatch in distance.");
#endif
c.resize(a.size()); pdiff(&a[0], &b[0], &c[0], a.size());
}
示例10: assert
const matrix<T,D,A>
operator * ( const std::valarray<T_>& lhs, const matrix<T,D,A>& rhs )
{
assert( rhs.row() == lhs.size() );
matrix<T,D,A> ans(1, lhs.row());
for ( std::size_t i = 0; i < rhs.col(); ++i )
ans[0][i] = std::inner_product( std::begin(lhs), std::begin(lhs)+rhs.row(), rhs.col_begin(i), T() );
return ans;
}
示例11: main
int main ()
{
const std::valarray<int> a;
a.cshift (1);
assert (0 == a.size ());
return 0;
}
示例12: is_equal
void is_equal(std::valarray<T> const &left, std::valarray<T> const &right)
{
BOOST_CHECK_EQUAL(left.size(), right.size());
if(left.size() == right.size())
{
for(std::size_t i = 0; i < left.size(); ++i)
{
is_equal_or_close(left[i], right[i]);
}
}
}
示例13: bar
//
// *b*it *ar*ithmetics (BAR)
//
template<class T> inline void bar(
const Perm_matrix<T>& pmat, //matrix of predefined permutations
const bitset_t& b, //bitset aka dummy coded data
std::valarray<T>& res) //results are written into res
{
assert (b.size() == pmat.bitMat_.front().size());
assert (res.size() == pmat.bitMat_.size());
for (size_t i=0; i<res.size(); i++) {
res[i] = (b & pmat.bitMat_[i]).count();
}
}
示例14: load
void load( Archive & ar, STD::valarray<U> &t, const unsigned int /*file_version*/ )
{
collection_size_type count;
ar >> BOOST_SERIALIZATION_NVP(count);
t.resize(count);
if (t.size()){
// explict template arguments to pass intel C++ compiler
ar >> serialization::make_array<U, collection_size_type>(
static_cast<U *>( boost::addressof(t[0]) ),
count
);
}
示例15: get_array_size
// returns the size of the index array represented by the genreralized slice
static std::size_t
get_array_size (const std::gslice &gsl)
{
const std::valarray<std::size_t> sizes = gsl.size ();
std::size_t asize = sizes.size () ? 1 : 0;
for (std::size_t i = 0; i != sizes.size (); ++i) {
asize *= sizes [i];
}
return asize;
}