本文整理汇总了C++中typenamestd::vector::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ vector::begin方法的具体用法?C++ vector::begin怎么用?C++ vector::begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类typenamestd::vector
的用法示例。
在下文中一共展示了vector::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: merge_sort_vector
static void merge_sort_vector(vector<T> *vect) {
if (vect->size() <= 1) {
return;
}
typename std::vector<T>::size_type mid = vect->size() / 2;
typename std::vector<T> left(vect->begin(), vect->begin() + mid);
typename std::vector<T> right(vect->begin() + mid, vect->end());
merge_sort_vector(&left);
merge_sort_vector(&right);
merge(
left.begin(), left.end(), right.begin(), right.end(), vect->begin());
}
示例2: write
void write( OutputIterator result ) const
{
const CharT dquo = widen< CharT >( '\"' );
const CharT comma = widen< CharT >( ',' );
const CharT lf = widen< CharT >( '\n' );
for ( typename std::vector< std::vector< string_type > >::const_iterator r_iter( records_.begin() ), r_last( records_.end() );
r_iter != r_last;
++r_iter )
{
for ( typename std::vector< string_type >::const_iterator f_iter( r_iter->begin() ), f_last( r_iter->end() );
f_iter != f_last;
++f_iter )
{
std::string field;
bool need_escape = false;
for ( typename string_type::const_iterator s_iter( f_iter->begin() ), s_last( f_iter->end() );
s_iter != s_last;
++s_iter )
{
CharT ch = *s_iter;
if ( ch == dquo )
{
field.push_back( dquo );
need_escape = true;
}
else if ( ch == comma || ch == lf )
{
need_escape = true;
}
field.push_back( ch );
}
if ( need_escape )
{
field = dquo + field + dquo;
}
result = std::copy( field.begin(), field.end(), result );
if ( boost::next( f_iter ) != f_last )
{
*result++ = comma;
}
}
*result++ = lf;
}
}
示例3:
property_t(const std::vector<std::vector<T> >& mtx) {
vector matrix;
for(typename std::vector<std::vector<T> >::const_iterator i = mtx.begin(); i != mtx.end(); ++i) {
vector row;
for(typename std::vector<T>::const_iterator j = i->begin(); j != i->end(); ++j)
row.push_back(*j);
matrix.push_back(row);
}
property_base::operator= <vector>(matrix);
}
示例4: shiftGrid
void shiftGrid( std::vector<std::vector<Point2> >& grid, const Point2& shift )
{
for( typename std::vector<std::vector<Point2> >::iterator itv = grid.begin(), itvEnd = grid.end();
itv != itvEnd;
++itv )
{
for( typename std::vector<Point2>::iterator it = itv->begin(), itEnd = itv->end();
it != itEnd;
++it )
{
*it += shift;
}
}
}
示例5: minimum_cycle_ratio
inline typename FloatTraits::value_type
minimum_cycle_mean(const Graph &g, VertexIndexMap vim,
EdgeWeightMap ewm, EdgeIndexMap eim,
std::vector<typename graph_traits<Graph>::edge_descriptor>* pcc = 0,
FloatTraits ft = FloatTraits())
{
typedef typename remove_const<
typename property_traits<EdgeWeightMap>::value_type
>::type Weight;
typename std::vector<Weight> ed_w2(boost::num_edges(g), 1);
return minimum_cycle_ratio(g, vim, ewm,
make_iterator_property_map(ed_w2.begin(), eim),
pcc, ft);
}
示例6: fillImageWithDecompostion
void fillImageWithDecompostion(const std::vector<Curve> & contours,
png::image<png::rgb_pixel> & output)
{
// Color map for the DLL
const png::rgb_pixel pixelColors[4] = {
// redPixel
png::rgb_pixel(255,0,0),
// greenPixel
png::rgb_pixel(0,255,0),
// bluePixel
png::rgb_pixel(0,0,255),
// yellowPixel
png::rgb_pixel(255,255,0)
};
typedef typename DLL::Segment<DLL_Type> DLLSegment;
Utils::GreedyDecomposition<DLLSegment> decompositor;
unsigned int nbDLL = 0;
for (typename std::vector<Curve>::const_iterator contourItor = contours.begin();
contourItor != contours.end(); ++contourItor) {
// decompose the current contour
typename std::vector<DLLSegment> dlls = decompositor.decomposeCurve(*contourItor);
// color each DLL segment into the output image
// and display the points coordinates of the DLL segment on the console
unsigned int colorIndex = 3;
for (typename std::vector<DLLSegment>::const_iterator dllItor = dlls.begin();
dllItor != dlls.end(); ++dllItor) {
const Curve & curve = dllItor->getCurve();
if (verbose)
std::cout << "DLL " << ++nbDLL << ":\t" << *dllItor
<< "\n\tPoints: ";
for(typename Curve::const_iterator coordItor = curve.begin();
coordItor != curve.end();
++coordItor) {
output.set_pixel(coordItor->first, coordItor->second,
pixelColors[colorIndex]);
if (verbose)
std::cout << "(" << coordItor->first << ","
<< coordItor->second << ") ";
}
if (verbose)
std::cout << std::endl;
colorIndex = (colorIndex + 1) % 3;
}
}
}
示例7: buildList
void
Datasegments<Scalar>::
buildList ( M3& KMat, Scalar* centers, int nSegments, typename std::vector< PatchCenter<Scalar> >& projPatchCenters)
{
projPatchCenters.clear();
projPatchCenters.resize( nSegments );
// first project current solutions:
for (int i=0;i<nSegments;i++)
{
P3 p0 = KMat * P3( ¢ers[3*i] );// center is in camera coords
p0 /= p0[2];
// projPatchCenters[i] = PatchCenter<Scalar>( int(p0[0]-0.5), int (p0[1]-0.5), P3( ¢ers[3*i] ), i );
projPatchCenters[i] = PatchCenter<Scalar>( int(floor(p0[0]-0.5)), int (floor(p0[1]-0.5)), p0, i );
}
std::sort( projPatchCenters.begin(), projPatchCenters.end() );
// need also a map where a certain segment is now, to start searching
}
示例8: if
template<class T> void ArgvToString(const std::vector<T> &argv, T &args)
{
// Clear the string
args.clear();
typename std::vector<T>::const_iterator i;
typename T::const_iterator j;
int ch;
for(i = argv.begin(); i != argv.end(); ++i)
{
for(j = i->begin(); j != i->end(); ++j)
{
ch = *j;
// No quoting, only escaping
// Handle \, ", ', \n, \r, \t., ' '
if (ch == '\\' || ch == '\"' || ch == '\'' || ch == ' ')
{
args += '\\';
}
else if (ch == '\n')
{
args += '\\';
ch = 'n';
}
else if (ch == '\r')
{
args += '\\';
ch = 'r';
}
else if (ch == '\t')
{
args += '\\';
ch = 't';
}
args += ch;
}
args += ' ';
}
}
示例9: lock
template < typename IN_PORT_TYPE > int vector_sink_s_base::_analyzerServiceFunction( typename std::vector< gr_istream< IN_PORT_TYPE > > &istreams ) {
typedef typename std::vector< gr_istream< IN_PORT_TYPE > > _IStreamList;
boost::mutex::scoped_lock lock(serviceThreadLock);
if ( validGRBlock() == false ) {
// create our processing block
createBlock();
LOG_DEBUG( vector_sink_s_base, " FINISHED BUILDING GNU RADIO BLOCK");
}
// process any Stream ID changes this could affect number of io streams
processStreamIdChanges();
if ( !validGRBlock() || istreams.size() == 0 ) {
LOG_WARN(vector_sink_s_base, "NO STREAMS ATTACHED TO BLOCK..." );
return NOOP;
}
// resize data vectors for passing data to GR_BLOCK object
_input_ready.resize( istreams.size() );
_ninput_items_required.resize( istreams.size());
_ninput_items.resize( istreams.size());
_input_items.resize(istreams.size());
_output_items.resize(0);
//
// RESOLVE: need to look at forecast strategy,
// 1) see how many read items are necessary for N number of outputs
// 2) read input data and see how much output we can produce
//
//
// Grab available data from input streams
//
typename _IStreamList::iterator istream = istreams.begin();
int nitems=0;
for ( int idx=0 ; istream != istreams.end() && serviceThread->threadRunning() ; idx++, istream++ ) {
// note this a blocking read that can cause deadlocks
nitems = istream->read();
if ( istream->overrun() ) {
LOG_WARN( vector_sink_s_base, " NOT KEEPING UP WITH STREAM ID:" << istream->streamID );
}
// RESOLVE issue when SRI changes that could affect the GNU Radio BLOCK
if ( istream->sriChanged() ) {
LOG_DEBUG( vector_sink_s_base, "SRI CHANGED, STREAMD IDX/ID: "
<< idx << "/" << istream->pkt->streamID );
}
}
LOG_TRACE( vector_sink_s_base, "READ NITEMS: " << nitems );
if ( nitems <= 0 && !_istreams[0].eos() ) return NOOP;
bool exitServiceFunction = false;
bool eos = false;
int nout = 0;
while ( nout > -1 && !exitServiceFunction && serviceThread->threadRunning() ) {
eos = false;
nout = _forecastAndProcess( eos, istreams );
if ( nout > -1 ) {
// we chunked on data so move read pointer..
istream = istreams.begin();
for ( ; istream != istreams.end(); istream++ ) {
int idx=std::distance( istreams.begin(), istream );
// if we processed data for this stream
if ( _input_ready[idx] ) {
size_t nitems = 0;
try {
nitems = gr_sptr->nitems_read( idx );
}
catch(...){}
if ( nitems > istream->nitems() ) {
LOG_WARN( vector_sink_s_base, "WORK CONSUMED MORE DATA THAN AVAILABLE, READ/AVAILABLE " << nitems << "/" << istream->nitems() );
nitems = istream->nitems();
}
istream->consume( nitems );
LOG_TRACE( vector_sink_s_base, " CONSUME READ DATA ITEMS/REMAIN " << nitems << "/" << istream->nitems());
}
}
gr_sptr->reset_read_index();
}
// check for not enough data return
if ( nout == -1 ) {
// check for end of stream
istream = istreams.begin();
for ( ; istream != istreams.end() ; istream++) if ( istream->eos() ) eos=true;
if ( eos ) {
LOG_TRACE( vector_sink_s_base, " DATA NOT READY, EOS:" << eos );
//.........这里部分代码省略.........
示例10: get
int
main()
{
using namespace boost;
//===========================================================================
// Declare the graph type and object, and some property maps.
typedef adjacency_list<vecS, vecS, directedS, property<vertex_name_t, std::string, property<vertex_color_t, default_color_type> >, property<edge_name_t, std::string, property<edge_weight_t, int> > > Graph;
typedef graph_traits<Graph> Traits;
typedef Traits::vertex_descriptor Vertex;
typedef Traits::edge_descriptor Edge;
typedef Traits::vertices_size_type size_type;
typedef std::map<std::string, Vertex> NameVertexMap;
NameVertexMap name2vertex;
Graph g;
typedef property_map<Graph, vertex_name_t>::type NameMap;
property_map<Graph, edge_name_t>::type link_name = get(edge_name, g);
//===========================================================================
// Read the data file and construct the graph.
Edge edge;
bool inserted;
tie(edge, inserted) = add_edge(0,1,g);
put(vertex_name, g, source(edge,g),"0");
put(vertex_name, g, target(edge,g),"1");
tie(edge, inserted) = add_edge(1,2,g);
put(vertex_name, g, source(edge,g),"1");
put(vertex_name, g, target(edge,g),"2");
tie(edge, inserted) = add_edge(1,3,g);
put(vertex_name, g, source(edge,g),"1");
put(vertex_name, g, target(edge,g),"3");
tie(edge, inserted) = add_edge(3,4,g);
put(vertex_name, g, source(edge,g),"3");
put(vertex_name, g, target(edge,g),"4");
tie(edge, inserted) = add_edge(3,5,g);
put(vertex_name, g, source(edge,g),"3");
put(vertex_name, g, target(edge,g),"5");
tie(edge, inserted) = add_edge(2,4,g);
put(vertex_name, g, source(edge,g),"2");
put(vertex_name, g, target(edge,g),"4");
tie(edge, inserted) = add_edge(4,6,g);
put(vertex_name, g, source(edge,g),"4");
put(vertex_name, g, target(edge,g),"6");
//===========================================================================
std::vector< std::vector<Edge> > paths;
Graph tmp_g = g;
Vertex src = 0;
Vertex goal = 6;
bool more = true;
do
{
std::vector<Edge> path;
OptSolPathEstimator<Graph> ospe(goal,&path);
try
{
depth_first_visit(tmp_g,src,ospe,get(vertex_color,tmp_g));
}
catch(FoundGoalSignal fgs)
{ };
if( !path.empty() )
{
more = true;// possible there are more goal-reached paths
paths.push_back(path);
// Delete the last edge of path in the tmp_g
remove_edge(path.back(),tmp_g);
// Reset all vertex_color in tmp_g to white
boost::graph_traits<Graph>::vertex_iterator vi, vi_end;
for (boost::tie(vi,vi_end) = vertices(tmp_g); vi != vi_end; ++vi)
put(vertex_color,tmp_g,*vi,color_traits<boost::default_color_type>::white());
}
else
{
more = false;
}
}
while(more);
cerr << "paths.size()= " << paths.size() << endl;
for(typename std::vector< std::vector<Edge> >::const_iterator i=paths.begin(); i!=paths.end(); ++i)
{
cerr << "Path " << i-paths.begin() << endl;
for(std::vector<Edge>::const_iterator j=i->begin(); j!=i->end(); ++j)
//.........这里部分代码省略.........
示例11: comp
OutputIterator
sloan_ordering(Graph& g,
typename graph_traits<Graph>::vertex_descriptor s,
typename graph_traits<Graph>::vertex_descriptor e,
OutputIterator permutation,
ColorMap color,
DegreeMap degree,
PriorityMap priority,
Weight W1,
Weight W2)
{
//typedef typename property_traits<DegreeMap>::value_type Degree;
typedef typename property_traits<PriorityMap>::value_type Degree;
typedef typename property_traits<ColorMap>::value_type ColorValue;
typedef color_traits<ColorValue> Color;
typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
typedef typename std::vector<typename graph_traits<Graph>::vertices_size_type>::iterator vec_iter;
typedef typename graph_traits<Graph>::vertices_size_type size_type;
typedef typename property_map<Graph, vertex_index_t>::const_type VertexID;
//Creating a std-vector for storing the distance from the end vertex in it
typename std::vector<typename graph_traits<Graph>::vertices_size_type> dist(num_vertices(g), 0);
//Wrap a property_map_iterator around the std::iterator
boost::iterator_property_map<vec_iter, VertexID, size_type, size_type&> dist_pmap(dist.begin(), get(vertex_index, g));
breadth_first_search
(g, e, visitor
(
make_bfs_visitor(record_distances(dist_pmap, on_tree_edge() ) )
)
);
//Creating a property_map for the indices of a vertex
typename property_map<Graph, vertex_index_t>::type index_map = get(vertex_index, g);
//Sets the color and priority to their initial status
unsigned cdeg;
typename graph_traits<Graph>::vertex_iterator ui, ui_end;
for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui)
{
put(color, *ui, Color::white());
cdeg=get(degree, *ui)+1;
put(priority, *ui, W1*dist[index_map[*ui]]-W2*cdeg );
}
//Priority list
typedef indirect_cmp<PriorityMap, std::greater<Degree> > Compare;
Compare comp(priority);
std::list<Vertex> priority_list;
//Some more declarations
typename graph_traits<Graph>::out_edge_iterator ei, ei_end, ei2, ei2_end;
Vertex u, v, w;
put(color, s, Color::green()); //Sets the color of the starting vertex to gray
priority_list.push_front(s); //Puts s into the priority_list
while ( !priority_list.empty() )
{
priority_list.sort(comp); //Orders the elements in the priority list in an ascending manner
u = priority_list.front(); //Accesses the last element in the priority list
priority_list.pop_front(); //Removes the last element in the priority list
if(get(color, u) == Color::green() )
{
//for-loop over all out-edges of vertex u
for (boost::tie(ei, ei_end) = out_edges(u, g); ei != ei_end; ++ei)
{
v = target(*ei, g);
put( priority, v, get(priority, v) + W2 ); //updates the priority
if (get(color, v) == Color::white() ) //test if the vertex is inactive
{
put(color, v, Color::green() ); //giving the vertex a preactive status
priority_list.push_front(v); //writing the vertex in the priority_queue
}
}
}
//Here starts step 8
*permutation++ = u; //Puts u to the first position in the permutation-vector
put(color, u, Color::black() ); //Gives u an inactive status
//for loop over all the adjacent vertices of u
for (boost::tie(ei, ei_end) = out_edges(u, g); ei != ei_end; ++ei) {
v = target(*ei, g);
if (get(color, v) == Color::green() ) { //tests if the vertex is inactive
put(color, v, Color::red() ); //giving the vertex an active status
put(priority, v, get(priority, v)+W2); //updates the priority
//for loop over alll adjacent vertices of v
for (boost::tie(ei2, ei2_end) = out_edges(v, g); ei2 != ei2_end; ++ei2) {
//.........这里部分代码省略.........
示例12: findPeaks
void FindPeaksMD::findPeaks(typename MDEventWorkspace<MDE, nd>::sptr ws)
{
if (nd < 3)
throw std::invalid_argument("Workspace must have at least 3 dimensions.");
progress(0.01, "Refreshing Centroids");
// TODO: This might be slow, progress report?
// Make sure all centroids are fresh
ws->getBox()->refreshCentroid();
typedef IMDBox<MDE,nd>* boxPtr;
if (ws->getNumExperimentInfo() == 0)
throw std::runtime_error("No instrument was found in the MDEventWorkspace. Cannot find peaks.");
// TODO: Do we need to pick a different instrument info?
ExperimentInfo_sptr ei = ws->getExperimentInfo(0);
// Instrument associated with workspace
Geometry::Instrument_const_sptr inst = ei->getInstrument();
// Find the run number
int runNumber = ei->getRunNumber();
// Check that the workspace dimensions are in Q-sample-frame or Q-lab-frame.
eDimensionType dimType;
std::string dim0 = ws->getDimension(0)->getName();
if (dim0 == "H")
{
dimType = HKL;
throw std::runtime_error("Cannot find peaks in a workspace that is already in HKL space.");
}
else if (dim0 == "Q_lab_x")
{
dimType = QLAB;
}
else if (dim0 == "Q_sample_x")
dimType = QSAMPLE;
else
throw std::runtime_error("Unexpected dimensions: need either Q_lab_x or Q_sample_x.");
// Find the goniometer rotation matrix
Mantid::Kernel::Matrix<double> goniometer(3,3, true); // Default IDENTITY matrix
try
{
goniometer = ei->mutableRun().getGoniometerMatrix();
}
catch (std::exception & e)
{
g_log.warning() << "Error finding goniometer matrix. It will not be set in the peaks found." << std::endl;
g_log.warning() << e.what() << std::endl;
}
/// Arbitrary scaling factor for density to make more manageable numbers, especially for older file formats.
signal_t densityScalingFactor = 1e-6;
// Calculate a threshold below which a box is too diffuse to be considered a peak.
signal_t thresholdDensity = 0.0;
thresholdDensity = ws->getBox()->getSignalNormalized() * DensityThresholdFactor * densityScalingFactor;
g_log.notice() << "Threshold signal density: " << thresholdDensity << std::endl;
// We will fill this vector with pointers to all the boxes (up to a given depth)
typename std::vector<boxPtr> boxes;
// Get all the MDboxes
progress(0.10, "Getting Boxes");
ws->getBox()->getBoxes(boxes, 1000, true);
// TODO: Here keep only the boxes > e.g. 3 * mean.
typedef std::pair<double, boxPtr> dens_box;
// Map that will sort the boxes by increasing density. The key = density; value = box *.
typename std::multimap<double, boxPtr> sortedBoxes;
progress(0.20, "Sorting Boxes by Density");
typename std::vector<boxPtr>::iterator it1;
typename std::vector<boxPtr>::iterator it1_end = boxes.end();
for (it1 = boxes.begin(); it1 != it1_end; it1++)
{
boxPtr box = *it1;
double density = box->getSignalNormalized() * densityScalingFactor;
// Skip any boxes with too small a signal density.
if (density > thresholdDensity)
sortedBoxes.insert(dens_box(density,box));
}
// List of chosen possible peak boxes.
std::vector<boxPtr> peakBoxes;
prog = new Progress(this, 0.30, 0.95, MaxPeaks);
int64_t numBoxesFound = 0;
// Now we go (backwards) through the map
// e.g. from highest density down to lowest density.
typename std::multimap<double, boxPtr>::reverse_iterator it2;
typename std::multimap<double, boxPtr>::reverse_iterator it2_end = sortedBoxes.rend();
for (it2 = sortedBoxes.rbegin(); it2 != it2_end; it2++)
{
//.........这里部分代码省略.........
示例13: lock
template < typename IN_PORT_TYPE, typename OUT_PORT_TYPE > int randomizer_base::_transformerServiceFunction( typename std::vector< gr_istream< IN_PORT_TYPE > > &istreams ,
typename std::vector< gr_ostream< OUT_PORT_TYPE > > &ostreams )
{
typedef typename std::vector< gr_istream< IN_PORT_TYPE > > _IStreamList;
typedef typename std::vector< gr_ostream< OUT_PORT_TYPE > > _OStreamList;
boost::mutex::scoped_lock lock(serviceThreadLock);
if ( validGRBlock() == false ) {
// create our processing block, and setup property notifiers
createBlock();
LOG_DEBUG( randomizer_base, " FINISHED BUILDING GNU RADIO BLOCK");
}
//process any Stream ID changes this could affect number of io streams
processStreamIdChanges();
if ( !validGRBlock() || istreams.size() == 0 || ostreams.size() == 0 ) {
LOG_WARN( randomizer_base, "NO STREAMS ATTACHED TO BLOCK..." );
return NOOP;
}
_input_ready.resize( istreams.size() );
_ninput_items_required.resize( istreams.size() );
_ninput_items.resize( istreams.size() );
_input_items.resize( istreams.size() );
_output_items.resize( ostreams.size() );
//
// RESOLVE: need to look at forecast strategy,
// 1) see how many read items are necessary for N number of outputs
// 2) read input data and see how much output we can produce
//
//
// Grab available data from input streams
//
typename _OStreamList::iterator ostream;
typename _IStreamList::iterator istream = istreams.begin();
int nitems=0;
for ( int idx=0 ; istream != istreams.end() && serviceThread->threadRunning() ; idx++, istream++ ) {
// note this a blocking read that can cause deadlocks
nitems = istream->read();
if ( istream->overrun() ) {
LOG_WARN( randomizer_base, " NOT KEEPING UP WITH STREAM ID:" << istream->streamID );
}
if ( istream->sriChanged() ) {
// RESOLVE - need to look at how SRI changes can affect Gnu Radio BLOCK state
LOG_DEBUG( randomizer_base, "SRI CHANGED, STREAMD IDX/ID: "
<< idx << "/" << istream->pkt->streamID );
setOutputStreamSRI( idx, istream->pkt->SRI );
}
}
LOG_TRACE( randomizer_base, "READ NITEMS: " << nitems );
if ( nitems <= 0 && !_istreams[0].eos() ) {
return NOOP;
}
bool eos = false;
int nout = 0;
bool workDone = false;
while ( nout > -1 && serviceThread->threadRunning() ) {
eos = false;
nout = _forecastAndProcess( eos, istreams, ostreams );
if ( nout > -1 ) {
workDone = true;
// we chunked on data so move read pointer..
istream = istreams.begin();
for ( ; istream != istreams.end(); istream++ ) {
int idx=std::distance( istreams.begin(), istream );
// if we processed data for this stream
if ( _input_ready[idx] ) {
size_t nitems = 0;
try {
nitems = gr_sptr->nitems_read( idx );
} catch(...){}
if ( nitems > istream->nitems() ) {
LOG_WARN( randomizer_base, "WORK CONSUMED MORE DATA THAN AVAILABLE, READ/AVAILABLE "
<< nitems << "/" << istream->nitems() );
nitems = istream->nitems();
}
istream->consume( nitems );
LOG_TRACE( randomizer_base, " CONSUME READ DATA ITEMS/REMAIN " << nitems << "/" << istream->nitems());
}
}
gr_sptr->reset_read_index();
}
// check for not enough data return
if ( nout == -1 ) {
// check for end of stream
//.........这里部分代码省略.........
示例14: generatePartitionSizeHistogram
void generatePartitionSizeHistogram(typename std::vector<T>& localVector, std::string filename, MPI_Comm comm = MPI_COMM_WORLD)
{
/*
* Approach :
* 1. Do a global sort by keyLayer (Partition id).
* 2. Compute the information Partition_Id:Size for boundary partitions (Avoid duplication).
* 3. Do an all_gather of boundary values plugged with ranks.
* 4. All boundary partitions should be owned by minimum rank that shares it.
* 5. Locally compute the largest partition size and do MPI_Allreduce
* with MPI_MAX.
* 6. Build the histogram locally.
* 7. Finally do MPI_Reduce over whole histogram to root node.
* 8. Write the output to file
*/
int p;
int rank;
MPI_Comm_size(comm, &p);
MPI_Comm_rank(comm, &rank);
static layer_comparator<keyLayer, T> pccomp;
//Sort the vector by each tuple's keyLayer element
mxx::sort(localVector.begin(), localVector.end(), pccomp, comm, false);
//Iterate over tuples to compute boundary information
bool iownLeftBucket, iownRightBucket, onlySingleLocalPartition;
//Type of tuple to communicate : (Partition Id, rank, size)
typedef std::tuple<uint32_t, int, uint64_t> tupletypeforbucketSize;
std::vector<tupletypeforbucketSize> toSend;
toSend.resize(2);
//Find the left most bucket
auto leftBucketRange = findRange(localVector.begin(), localVector.end(), *(localVector.begin()), pccomp);
std::get<0>(toSend[0]) = std::get<keyLayer>(*localVector.begin());
std::get<1>(toSend[0]) = rank;
std::get<2>(toSend[0]) = leftBucketRange.second - leftBucketRange.first;
//Find the right most bucket
auto rightBucketRange = findRange(localVector.rbegin(), localVector.rend(), *(localVector.rbegin()), pccomp);
std::get<0>(toSend[1]) = std::get<keyLayer>(*localVector.rbegin());
std::get<1>(toSend[1]) = rank;
std::get<2>(toSend[1]) = rightBucketRange.second - rightBucketRange.first;
//If we have only single partition, make sure we are not creating duplicates
if(std::get<0>(toSend[0]) == std::get<0>(toSend[1]))
{
//Make second send element's size zero
std::get<2>(toSend[1]) = 0;
onlySingleLocalPartition = true;
}
else
onlySingleLocalPartition = false;
//Gather all the boundary information
auto allBoundaryPartitionSizes = mxx::allgather_vectors(toSend, comm);
uint64_t leftBucketSize = 0;
uint64_t rightBucketSize = 0;
//Need to parse boundary information that matches the partitionIds we have
static layer_comparator<0, tupletypeforbucketSize> pccomp2;
auto leftBucketBoundaryRange = std::equal_range(allBoundaryPartitionSizes.begin(), allBoundaryPartitionSizes.end(), toSend[0], pccomp2);
//Check if this processor owns this bucket
if(std::get<1>(*(leftBucketBoundaryRange.first)) == rank)
{
iownLeftBucket = true;
for(auto it = leftBucketBoundaryRange.first; it != leftBucketBoundaryRange.second; it++)
{
leftBucketSize += std::get<2>(*it);
}
}
else
iownLeftBucket = false;
auto rightBucketBoundaryRange = std::equal_range(allBoundaryPartitionSizes.begin(), allBoundaryPartitionSizes.end(), toSend[1], pccomp2);
//Check if this processor owns right partition
if(std::get<1>(*rightBucketBoundaryRange.first) == rank && !onlySingleLocalPartition)
{
iownRightBucket = true;
for(auto it = rightBucketBoundaryRange.first; it != rightBucketBoundaryRange.second; it++)
{
rightBucketSize += std::get<2>(*it);
}
}
else
iownRightBucket = false;
//Map from partition size to count
typedef std::map <uint64_t, uint32_t> MapType;
MapType localHistMap;
for(auto it = localVector.begin(); it!= localVector.end();) // iterate over all segments.
{
auto innerLoopBound = findRange(it, localVector.end(), *it, pccomp);
//Left most bucket
//.........这里部分代码省略.........
示例15: fromPointCloud
void fromPointCloud( const typename std::vector<Celer::Vector4<Real> >& points,
const Celer::Vector3<Real>& first_basis,
const Celer::Vector3<Real>& second_basis,
const Celer::Vector3<Real>& third_basis )
{
// Reference :
// Geometric Tools, LLC
// Copyright (c) 1998-2012
// Distributed under the Boost Software License, Version 1.0.
// Wm5ContBox3.cpp
basis_[0] = first_basis;
basis_[1] = second_basis;
basis_[2] = third_basis;
for ( typename std::vector<Celer::Vector4<Real> >::const_iterator new_point = points.begin(); new_point != points.end(); new_point++)
{
BoundingBox3<Real> box( std::min ( min_.x , new_point->x ) ,
std::min ( min_.y , new_point->y ) ,
std::min ( min_.z , new_point->z ) ,
std::max ( max_.x , new_point->x ) ,
std::max ( max_.y , new_point->y ) ,
std::max ( max_.z , new_point->z ) );
// std::cout << min( );
// std::cout << max( );
// std::cout << " new_point " << *new_point;
*this = *this + box;
}
Celer::Vector3<Real> diff = points[0].toVector3() - this->center();
Celer::Vector3<Real> pmin ( ( diff * basis_[0] ) , ( diff * basis_[1] ) , (diff * basis_[2]) );
Celer::Vector3<Real> pmax = pmin;
for ( typename std::vector<Celer::Vector4<Real> >::const_iterator new_point = points.begin(); new_point != points.end(); new_point++)
{
// diff = points[i] - box.Center;
// for ( int j = 0; j < 3; ++j )
// {
// Real dot = diff.Dot ( box.Axis[j] );
// if ( dot < pmin[j] )
// {
// pmin[j] = dot;
// }
// else if ( dot > pmax[j] )
// {
// pmax[j] = dot;
// }
// }
}
// for ( int i = 1; i < numPoints; ++i )
// {
// }
// min_ += ( ( (Real) 0.5 ) * ( pmin[0] + pmax[0] ) ) * box.Axis[0] + ( ( (Real) 0.5 ) * ( pmin[1] + pmax[1] ) ) * box.Axis[1] + ( ( (Real) 0.5 ) * ( pmin[2] + pmax[2] ) ) * box.Axis[2];
}