Beispiel #1
0
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;
}
Beispiel #2
0
 NLDRNeighborList& operator=(const NLDRNeighborList& nn)
 {
     if (&nn==this) return *this;
     nlist.resize(nn.nlist.size()); nlist=nn.nlist;
     npoint.resize(nn.npoint.size()); npoint=nn.npoint;
     opts=nn.opts;
 }
//! 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
}
Beispiel #4
0
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;
}
Beispiel #5
0
	AsebaNode()
	{
		// create VM
		vm.nodeId = 0;
		bytecode.resize(512);
		vm.bytecode = &bytecode[0];
		vm.bytecodeSize = bytecode.size();
		
		stack.resize(64);
		vm.stack = &stack[0];
		vm.stackSize = stack.size();
		
		vm.variables = reinterpret_cast<sint16 *>(&variables);
		vm.variablesSize = sizeof(variables) / sizeof(sint16);
		
		AsebaVMInit(&vm);
		
		// fill description accordingly
		d.name = L"testvm";
		d.protocolVersion = ASEBA_PROTOCOL_VERSION;
		
		d.bytecodeSize = vm.bytecodeSize;
		d.variablesSize = vm.variablesSize;
		d.stackSize = vm.stackSize;
		
		/*d.namedVariables.push_back(TargetDescription::NamedVariable("id", 1));
		d.namedVariables.push_back(TargetDescription::NamedVariable("source", 1));
		d.namedVariables.push_back(TargetDescription::NamedVariable("args", 32));*/
	}
Beispiel #6
0
         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++;
            }

         };
Beispiel #7
0
        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()); 
        }
Beispiel #8
0
 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;
 }
Beispiel #9
0
         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++;
               }
            }

         };
Beispiel #10
0
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;
}
Beispiel #11
0
        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()); 
        }
Beispiel #12
0
 NLDRLLEReport& operator=(const NLDRLLEReport& nr)
 {
     if (&nr==this) return *this;
     hd_errors.resize(nr.hd_errors.size()); hd_errors=nr.hd_errors;  hd_error=nr.hd_error;
     ld_errors.resize(nr.ld_errors.size()); ld_errors=nr.ld_errors;  ld_error=nr.ld_error;
     deval.resize(nr.deval.size()); deval=nr.deval;  dp1eval=nr.dp1eval;
     return *this;
 }
Beispiel #13
0
 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;
 }
int main ()
{
    const std::valarray<int> a;

    a.cshift (1);

    assert (0 == a.size ());

    return 0;
} 
Beispiel #15
0
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]);
        }
    }
}
Beispiel #16
0
 //
 // *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();
     }
 }
Beispiel #17
0
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
        );
    }
Beispiel #18
0
// 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;
}
Beispiel #19
0
std::valarray<T> product(const std::valarray<T>& x, const valmatrix<T>& y)
{
    if (x.size() != y.size())
        std::logic_error("Non equal matrices.");

    std::valarray<T> result(x.size());
    for (size_t j = 0; j < x.size(); ++j)
        for (size_t k = 0; k < x.size(); ++k)
        {
            result[j] += x[k] * y[k][j];
        }
    return result;
}
int main ()
{
    const int vals[] = { 1, 0 };
    const std::size_t N = sizeof vals / sizeof *vals;

    const std::valarray<int> p (vals, N);

    assert (N == p.size ());

    const std::valarray<int> r = p [std::slice (0, 0, 1)];

    assert (0 == r.size ());
}
Beispiel #21
0
	virtual void incomingData(Dashel::Stream *stream)
	{
		uint16 temp;
		uint16 len;
		
		stream->read(&temp, 2);
		len = bswap16(temp);
		stream->read(&temp, 2);
		lastMessageSource = bswap16(temp);
		lastMessageData.resize(len+2);
		stream->read(&lastMessageData[0], lastMessageData.size());
		
		AsebaProcessIncomingEvents(&vm);
	}
// run the initilized retina filter in order to perform gray image tone mapping, after this call all retina outputs are updated
void _runGrayToneMapping(const std::valarray<float> &grayImageInput, std::valarray<float> &grayImageOutput)
{
     // apply tone mapping on the multiplexed image
    // -> photoreceptors local adaptation (large area adaptation)
    _multiuseFilter->runFilter_LPfilter(grayImageInput, grayImageOutput, 0); // compute low pass filtering modeling the horizontal cells filtering to acess local luminance
    _multiuseFilter->setV0CompressionParameterToneMapping(1.f, grayImageOutput.max(), _meanLuminanceModulatorK*grayImageOutput.sum()/(float)_multiuseFilter->getNBpixels());
    _multiuseFilter->runFilter_LocalAdapdation(grayImageInput, grayImageOutput, _temp2); // adapt contrast to local luminance

    // -> ganglion cells local adaptation (short area adaptation)
    _multiuseFilter->runFilter_LPfilter(_temp2, grayImageOutput, 1); // compute low pass filtering (high cut frequency (remove spatio-temporal noise)
    _multiuseFilter->setV0CompressionParameterToneMapping(1.f, _temp2.max(), _meanLuminanceModulatorK*grayImageOutput.sum()/(float)_multiuseFilter->getNBpixels());
    _multiuseFilter->runFilter_LocalAdapdation(_temp2, grayImageOutput, grayImageOutput); // adapt contrast to local luminance

}
void BasicRetinaFilter::setProgressiveFilterConstants_CustomAccuracy(const float beta, const float tau, const float k, const std::valarray<float> &accuracyMap, const unsigned int filterIndex)
{

	if (accuracyMap.size()!=_filterOutput.size())
	{
		std::cerr<<"BasicRetinaFilter::setProgressiveFilterConstants_CustomAccuracy: error: input accuracy map does not match filter size, init skept"<<std::endl;
		return ;
	}

	// check if dedicated buffers are already allocated, if not create them
	if (_progressiveSpatialConstant.size()!=_filterOutput.size())
	{
		_progressiveSpatialConstant.resize(accuracyMap.size());
		_progressiveGain.resize(accuracyMap.size());
	}

	float _beta = beta+tau;
	float _alpha=k*k;
	float _mu=0.8f;
	if (k<=0)
	{
		std::cerr<<"BasicRetinaFilter::spatial filtering coefficient must be superior to zero, correcting value to 0.01"<<std::endl;
		//alpha0=0.0001;
	}
	unsigned int tableOffset=filterIndex*3;
	float _temp =  (1.0f+_beta)/(2.0f*_mu*_alpha);
	float _a=_filteringCoeficientsTable[tableOffset] = 1.0f + _temp - (float)sqrt( (1.0f+_temp)*(1.0f+_temp) - 1.0f);
	_filteringCoeficientsTable[tableOffset+1]=(1.0f-_a)*(1.0f-_a)*(1.0f-_a)*(1.0f-_a)/(1.0f+_beta);
	_filteringCoeficientsTable[tableOffset+2] =tau;

	//memset(_progressiveSpatialConstant, 255, _filterOutput.getNBpixels());
	for (unsigned int idColumn=0;idColumn<_filterOutput.getNBcolumns(); ++idColumn)
		for (unsigned int idRow=0;idRow<_filterOutput.getNBrows(); ++idRow)
		{
			// computing local spatial constant
			unsigned int index=idColumn+idRow*_filterOutput.getNBcolumns();
			float localSpatialConstantValue=_a*accuracyMap[index];
			if (localSpatialConstantValue>1)
				localSpatialConstantValue=1;

			_progressiveSpatialConstant[index]=localSpatialConstantValue;

			// computing local gain
			float localGain=(1.0f-localSpatialConstantValue)*(1.0f-localSpatialConstantValue)*(1.0f-localSpatialConstantValue)*(1.0f-localSpatialConstantValue)/(1.0f+_beta);
			_progressiveGain[index]=localGain;

			//std::cout<<commonFactor<<", "<<sqrt((_halfNBcolumns-1-idColumn)+(_halfNBrows-idRow-1))<<", "<<(_halfNBcolumns-1-idColumn)<<", "<<(_halfNBrows-idRow-1)<<", "<<localSpatialConstantValue<<std::endl;
		}
}
Beispiel #24
0
template <class T> FMatrix<U>::FMatrix(const std::valarray<std::valarray<T> >& s)
{
#ifdef DEBUG
    if (s.size()<1 || s[0].size()<1) ERROR("Trying to initialize FMatrix from empty valarray")
#endif 
    resize(s.size(), s[0].size());
    index_type k=0;
    for (index_type i=0; i<wr; ++i)
    {
#ifdef DEBUG
        if (s[i].size()!=wc) ERROR("Element "<<i<<" in valarray has wrong dimension")
#endif 
        for (index_type j=0; j<wc; ++j) data[k++]=(U)s[i][j];
    }
}
Beispiel #25
0
        unsigned long nneigh(unsigned long i) const 
        {
#ifdef DEBUG
            if (i>=npoint.size()) ERROR("Index out of bounds in neighbor list");
#endif
            return npoint[i+1]-npoint[i]; 
        } 
Beispiel #26
0
std::valarray<double> SourceTermsWind::dUdt(const std::valarray<double> &Uin)
{
  this->prepare_integration();

  std::valarray<double> Lsrc(Uin.size());
  //  std::valarray<double> &P = Mara->PrimitiveArray;

  for (int i=0; i<stride[0]; i+=NQ) {

    int N[3];
    absolute_index_to_3d(i/NQ, N);

    double x[3] = {
      Mara->domain->x_at(N[0]),
      Mara->domain->y_at(N[1]),
      Mara->domain->z_at(N[2]) };

    double L0[5] = {0, 0, 0, 0, 0};
    double L = 0.05;
    double R = sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);

    L0[ddd] = 1e1 * (1.0 - R/L > 0.0 ? 1.0 - R/L : 0.0);
    L0[tau] = 1e3 * (1.0 - R/L > 0.0 ? 1.0 - R/L : 0.0);

    for (int q=0; q<NQ; ++q) {
      Lsrc[i+q] += L0[q];
    }
  }

  return Lsrc;
}
Beispiel #27
0
 frame& operator=(const frame& nf) 
 {
     if (&nf==this) return *this;
     nat=nf.nat; comment=nf.comment; 
     ats.resize(nf.ats.size()); ats=nf.ats;
     return *this;
 }
// constructor that copies input data (1D valarray) into a column vector
Matrix::Matrix(std::valarray<double> vals) {
  nrows = vals.size();
  ncols = 1;
  data.resize(1);
  for (size_t i=0; i<nrows; i++)
    data[0][i] = vals[i];
}
Beispiel #29
0
void halve(std:: valarray<float> &imap, int inx, int iny, std:: valarray<float> &omap) {
    if(inx % 2) {
        // it is odd
        std:: cout << " nx of the input map is odd " << std:: endl;
        std:: cout << " I cannot process ... I will STOP here!!! " << std:: endl;
        exit(1);
    }
    if(iny % 2) {
        // it is odd
        std:: cout << " ny of the input map is odd " << std:: endl;
        std:: cout << " I cannot process ... I will STOP here!!! " << std:: endl;
        exit(1);
    }

    int nx = inx/2;
    int ny = iny/2;

    omap.resize(nx*ny);
    for(int i=0; i<nx; i++) for(int j=0; j<ny; j++) {
            omap[i+nx*j] = (imap[(2*i)+inx*(2*j)] +
                            imap[(2*i+1)+inx*(2*j)] +
                            imap[(2*i)+inx*(2*j+1)] +
                            imap[(2*i+1)+inx*(2*j+1)])/4;

        }
}
Beispiel #30
0
void A2Kt(const toolbox::FMatrix<double>& A, double dt, std::valarray<double>& K)
{
    int n=A.rows();
    toolbox::FMatrix<double> la(n-1,n-1), le, len(n-1,n-1);
    len*=0.;
    for(int i=1; i<n;++i)
    {
        len(i-1,i-1)=1.;
        for(int j=1; j<n;++j)
            la(i-1,j-1)=A(i,j);
    }
    la*=(-dt);
    toolbox::exp(la,le,1e-20);
    K=0; K[0]=A(0,0)/dt; 
    for (int s=0;s<K.size();++s)
    {
        for(int i=1; i<n;++i)
            for(int j=1; j<n;++j)
        {
            K[s]-=A(0,i)*A(j,0)*len(i-1,j-1);
        }
        mult(len,le,la); len=la;
    }
    K[0]*=2.;
}