예제 #1
0
			AsynchronousBufferReaderList(
				in_iterator_type ina,
				in_iterator_type ine,
				uint64_t rnumbuffers = 16,
				uint64_t rbufsize = 32,
				uint64_t offset = 0)
			:
				C(ina,ine), ita(C.begin()), ite(C.end()), numbuffers(rnumbuffers), bufsize(rbufsize)
			{
				while ( ita != ite && offset >= ::libmaus2::util::GetFileSize::getFileSize(*ita) )
				{
					offset -= ::libmaus2::util::GetFileSize::getFileSize(*ita);
					ita++;
				}

				if ( ita != ite )
				{
					reader_ptr_type treader(new AsynchronousBufferReader(*ita, numbuffers,bufsize,offset));
					reader = UNIQUE_PTR_MOVE(treader);
				}
			}
예제 #2
0
double energy( const container_type &q , const container_type &p , const mass_type &masses )
{
    const size_t n = q.size();
    double en = 0.0;
    for( size_t i=0 ; i<n ; ++i )
    {
        en += 0.5 * norm( p[i] ) / masses[i];
        for( size_t j=0 ; j<i ; ++j )
        {
            double diff = abs( q[i] - q[j] );
            en -= gravitational_constant * masses[j] * masses[i] / diff;
        }
    }
    return en;
}
예제 #3
0
 void middle_point(double *x, double *y) const
 {
     // calculate mid point on path
     double x0=0;
     double y0=0;
     double x1=0;
     double y1=0;
   
     unsigned size = cont_.size();
     if (size == 1)
     {
         cont_.get_vertex(0,x,y); 
     }
     else if (size == 2)
     {
         cont_.get_vertex(0,&x0,&y0);
         cont_.get_vertex(1,&x1,&y1);
         *x = 0.5 * (x1 + x0);
         *y = 0.5 * (y1 + y0);    
     }
     else
     {
         double len=0.0;
         for (unsigned pos = 1; pos < size; ++pos)
         {
             cont_.get_vertex(pos-1,&x0,&y0);
             cont_.get_vertex(pos,&x1,&y1);
             double dx = x1 - x0;
             double dy = y1 - y0;
             len += std::sqrt(dx * dx + dy * dy);
         }
         double midlen = 0.5 * len;
         double dist = 0.0;
         for (unsigned pos = 1; pos < size;++pos)
         {
             cont_.get_vertex(pos-1,&x0,&y0);
             cont_.get_vertex(pos,&x1,&y1);
             double dx = x1 - x0;
             double dy = y1 - y0; 
             double seg_len = std::sqrt(dx * dx + dy * dy);
             if (( dist + seg_len) >= midlen)
             {
                 double r = (midlen - dist)/seg_len;
                 *x = x0 + (x1 - x0) * r;
                 *y = y0 + (y1 - y0) * r;
                 break;
             }
             dist += seg_len;
         }
     }  
 }
pair< double , double > calc_mean_field( const container_type &x )
{
    size_t n = x.size();
    double cos_sum = 0.0 , sin_sum = 0.0;
    for( size_t i=0 ; i<n ; ++i )
    {
        cos_sum += cos( x[i] );
        sin_sum += sin( x[i] );
    }
    cos_sum /= double( n );
    sin_sum /= double( n );

    double K = sqrt( cos_sum * cos_sum + sin_sum * sin_sum );
    double Theta = atan2( sin_sum , cos_sum );

    return make_pair( K , Theta );
}
예제 #5
0
    void operator()( const container_type &q , container_type &dpdt ) const
    {
        const size_t n = q.size();
        for( size_t i=0 ; i<n ; ++i )
        {
            dpdt[i] = 0.0;
            for( size_t j=0 ; j<i ; ++j )
            {
                point_type diff = q[j] - q[i];
                double d = abs( diff );
                diff *= ( gravitational_constant * m_masses[i] * m_masses[j] / d / d / d );
                dpdt[i] += diff;
                dpdt[j] -= diff;

            }
        }
    }
예제 #6
0
파일: main.cpp 프로젝트: CCJY/coliru
        void read()
        {
            if (is_)
            {
                if (std::getline(*is_, line))
                {
                    str.str(line);
                    
                    if (Count == -1)
                        temp.assign(
                        std::istream_iterator<Value, charT, traits>{str}, {});
                    else if (0 <= Count)
                        std::copy_n(
                            std::istream_iterator<Value, charT, traits>{str},
                            Count,
                            std::back_inserter(temp));
                }
                
                if (!*is_)
                    is_ = nullptr;

                str.clear();
            }
        }
예제 #7
0
		static std::size_t                           size(const container_type& p) { return p.size(); }
예제 #8
0
		static const_reverse_iterator                rend(const container_type& p) { return p.rend(); }
예제 #9
0
		static const_reverse_iterator                rbegin(const container_type& p) { return p.rbegin(); }
예제 #10
0
		static const_iterator                        end(const container_type& p) { return p.end(); }
예제 #11
0
		// TOOD: this can probably be removed
		void reset(void)
		{
			container.clear();
		}
예제 #12
0
  /*
   * Construction from triplets.
   * This is the main workhorse of the data structure, taking an unordered (potentially uncompressed)
   * vector of triplets and performing the required sorting to convert it into a sparse_bcsr ordering.
   * 
   * This function DOES MODIFY the input triplet vector "ts" (by sorting)
   */
  sparse_bcsr(const std::vector<triplet> & _ts) :  _brows(0), _bcols(0), _zero(0)
  {
    std::vector<triplet> ts(_ts);
    block_stride = BLOCK*BLOCK;
    assert(ts.size() > 0 && "Doesn't support empty matrices (yet)");

    //sort the triplets into bcsr order using the bcsr_compare struct
    std::sort(ts.begin(), ts.end(), bcsr_compare());
    
    size_type brows = std::get<0>(*ts.rbegin())/BLOCK+1;
    brow_ptr.resize(brows+1, size_type(0));

    size_type curr_brow = std::get<0>(ts[0])/BLOCK;
    size_type curr_bcol = std::get<1>(ts[0])/BLOCK;
  
    // count number of blocks (single pass thru tuples. saves mem alloc time from push_back calls)
    size_type nblocks = 1;
    for(size_type i=1; i<ts.size(); ++i) {
      if(curr_brow == std::get<0>(ts[i])/BLOCK &&
	 curr_bcol == std::get<1>(ts[i])/BLOCK) {
      }
      else {
	++nblocks;
      }
      curr_brow = std::get<0>(ts[i])/BLOCK;
      curr_bcol = std::get<1>(ts[i])/BLOCK;
    }
    
    // resize storage containers
    bcol_index.resize(nblocks, size_type(0));
    data.resize(nblocks*block_stride, value_type(0));

    //construct from triplets
    curr_brow = std::get<0>(ts[0])/BLOCK;
    curr_bcol = std::get<1>(ts[0])/BLOCK;
    
    //_rows = std::get<0>(ts[0])+1;
    //_cols = std::get<1>(ts[0])+1;
    
    for(size_type r=0; r<=curr_brow; ++r) {
      brow_ptr[r] = 0;
    }
    
    bcol_index[0] = curr_bcol;
    data[index(0, std::get<0>(ts[0])%BLOCK, std::get<1>(ts[0])%BLOCK)] = std::get<2>(ts[0]);
    
    size_type bidx = 0;
    for(size_type idx=1; idx<ts.size(); ++idx) {
      
      size_type I = std::get<0>(ts[idx])/BLOCK;
      size_type J = std::get<1>(ts[idx])/BLOCK;
      size_type i = std::get<0>(ts[idx])%BLOCK;
      size_type j = std::get<1>(ts[idx])%BLOCK;
      value_type val = std::get<2>(ts[idx]);
      

      //keep track of number of brows, bcols. 
      // not yet sure if I should enforce matrix sizes to be multiples of BLOCK
      _brows = (I+1)>_brows ? I+1 : _brows;
      _bcols = (J+1)>_bcols ? J+1 : _bcols;
      
      
      if(I==curr_brow && J==curr_bcol) {
	data[index(bidx, i, j)] += val;
      }
      else {
	++bidx;

	if(curr_brow != I) {
	  for(size_type r=curr_brow+1; r<=I; ++r) {
	    brow_ptr[r] = bidx;
	  }
	  
	  curr_brow = I;
	}
	curr_bcol = J;

	bcol_index[bidx] = J;
	data[index(bidx, i, j)] += val;
      }
    }
    
    brow_ptr[_brows] = nblocks;
  }
예제 #13
0
		static void                                  emplace_back(container_type& cont, const PointExpr& p) { cont.emplace_back(p); }
예제 #14
0
파일: main.cpp 프로젝트: CCJY/coliru
 static void sort(container_type<size_t> &front, comparator_type comp) {
   std::sort(front.begin(), front.end(), comp);
 }
예제 #15
0
 static typename result_of::const_handle_type<container_type, iterator_handle_tag>::type handle( container_type const & container, value_type const & value )
 {
   for (typename container_type::const_iterator it = container.begin(); it != container.end(); ++it)
     if ( &(*it) == &value ) return it;
   return container.end();
 }
예제 #16
0
 void set_handle_invalid( container_type const & container, handle_type & handle, iterator_handle_tag )
 { handle = container.end(); }
예제 #17
0
 typename container_type::size_type size()
 {
    return m_queue.size(); 
 }
예제 #18
0
 BigUInt(const container_type& array) : 
     data(array.begin(), array.end()) 
 {
 }
예제 #19
0
		void make_next(void)
		{
			container.push_back(fact());
		}
예제 #20
0
		static bool                                  empty(const container_type& p) { return p.empty(); }
예제 #21
0
		static void                                  pop_back(container_type& pointSequence) { pointSequence.pop_back(); }
예제 #22
0
		iterator end() {
			return container_.end();
		}
예제 #23
0
		static void                                  push_back(container_type& cont, const PointExpr& p) { cont.push_back(p); }
예제 #24
0
		const_iterator end() const {
			return container_.end();
		}
예제 #25
0
		iterator begin() {
			return container_.begin();
		}
예제 #26
0
void deltaFml (const container_type& positions, container_type& forces)
{
    forces.clear ();
    forces.push_back (2*(positions.at (0)+20));
    forces.push_back (2*(positions.at (1)-43));
}
예제 #27
0
		const_iterator begin() const {
			return container_.begin();
		}
예제 #28
0
파일: game.hpp 프로젝트: hamazy/shiritori
	void add(request_spec *spec, request_handler *handler)
	{
		request_handlers_.push_back(std::make_pair(spec, handler));
	}
예제 #29
0
 void operator() (container_type & src_container, viennagrid::view<base_container_type, handle_container_tag> & dst_view)
 {
     for (typename container_type::iterator it = src_container.begin(); it != src_container.end(); ++it)
         if (pred_( *it ))
             dst_view.insert_handle( it.handle() );
 }
예제 #30
0
		static const_iterator                        begin(const container_type& p) { return p.begin(); }