19 std::vector<unsigned short>::clear();
20 std::vector<unsigned short>::reserve(nclusters);
22 for(
size_t i=0; i<nclusters; ++i) {
34 throw CMTException(Form(
"<<%s>> Two input clusters identical (%d)",__FUNCTION__,index1));
37 if( index1 >= this->
size() || index2 >= this->
size() )
39 throw CMTException(Form(
"Input cluster index (%d and/or %d) out of range",index1,index2));
41 auto out_index1 = this->at(index1);
42 auto out_index2 = this->at(index2);
44 if(out_index1 == out_index2)
45 throw CMTException(Form(
"Cluster %d and %d already merged!",index1,index2));
47 if(out_index2 < out_index1) std::swap(out_index1,out_index2);
54 unsigned short index2)
59 throw CMTException(Form(
"<<%s>> Two input clusters identical (%d)",__FUNCTION__,index1));
62 if( index1 >= this->
size() || index2 >= this->
size() )
64 throw CMTException(Form(
"Input cluster index (%d and/or %d) out of range",index1,index2));
66 auto out_index1 = this->at(index1);
67 auto out_index2 = this->at(index2);
69 if(out_index1 == out_index2)
return true;
71 if(out_index2 < out_index1) std::swap(out_index1,out_index2);
82 throw CMTException(Form(
"<<%s>> Two input clusters identical (%d)",__FUNCTION__,index1));
85 if( index1 >= this->
size() || index2 >= this->
size() )
87 throw CMTException(Form(
"Input cluster index (%d and/or %d) out of range",index1,index2));
89 auto out_index1 = this->at(index1);
90 auto out_index2 = this->at(index2);
92 if(out_index1 == out_index2)
return;
94 if(out_index2 < out_index1) std::swap(out_index1,out_index2);
98 throw CMTException(Form(
"Clusters (%d,%d) correspond to output (%d,%d) which is prohibited to merge",
100 out_index1,out_index2));
105 for(
auto &v : (*
this)) {
107 if( v == out_index1 || v == out_index2 )
109 else if( v > out_index2 )
117 for(
size_t index=0; index < out_index1; ++index) {
119 size_t tmp_out_index1 = out_index1 - index;
120 size_t tmp_out_index2 = out_index2 - index;
127 for(
size_t in_index=tmp_out_index2;
148 for(
size_t in_index = 1;
152 if( (in_index + out_index1) < out_index2 ) {
161 _prohibit_merge.at(in_index + out_index1).at(out_index2 - (in_index+out_index1))
187 for(
size_t index = out_index1+1;
190 for(
size_t in_index = (out_index2 - index);
201 for(
size_t index = out_index2;
206 for(
size_t in_index = 0;
225 for(
auto const& v : *
this)
229 std::cout<<
"Prohibit Status:"<<std::endl;
232 for(
auto const &b : bs) {
246 if( index1 >= this->
size() || index2 >= this->
size() )
247 throw CMTException(Form(
"Invalid cluster index: %d or %d",index1,index2));
249 return this->at(index1) == this->at(index2);
256 if( index1 >= this->
size() )
257 throw CMTException(Form(
"Invalid cluster index: %d ",index1));
259 auto out_index = this->at(index1);
260 std::vector<unsigned short> result;
262 for(
size_t i=0; i<this->
size(); ++i)
263 if( this->at(i) == out_index ) result.push_back(i);
274 for(
size_t i=0; i<this->
size(); ++i)
275 result.at(
this->at(i)).push_back(i);
281 std::vector<std::vector<unsigned short> > my_result;
283 if(my_result.size() != another.size()) {
284 throw CMTException(Form(
"Input has an incompatible size (%zu != %zu)",
292 std::vector<std::vector<unsigned short> > another_result;
294 if(another_result.size() >= my_result.size())
295 throw CMTException(Form(
"The input has equal or more number of output clusters (%zu>=%zu)",
296 another_result.size(),
301 for(
auto const& ares : another_result) {
303 if(ares.size()==1)
continue;
306 unsigned short target = my_result.at(ares.at(0)).at(0);
308 for(
auto const &res_index : ares) {
310 for(
auto const &orig_index : my_result.at(res_index)) {
312 if(target == orig_index)
continue;
314 else this->
Merge(target,orig_index);
std::size_t size(FixedBins< T, C > const &) noexcept
Class def header for a class CMergeBookKeeper.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Class def header for exception classes in CMTException.
BEGIN_PROLOG could also be cout