34 #ifndef _H_BLOCKORDERER
35 #define _H_BLOCKORDERER
37 #include "SBDTree.hpp"
38 #include "Triplet.hpp"
42 #define NORMAL_DS 2 //ICRS
43 #define HORIZONTAL_DS -2 //ICCS
44 #define VERTICAL_DS 2 //ICRS
47 template<
typename T >
62 void prefix(
const unsigned long int index ) {
71 std::cerr <<
"BlockOrderer:: Unknown or unset traverse mode!" << std::endl;
77 void infix(
const unsigned long int index ) {
86 std::cerr <<
"BlockOrderer:: Unknown or unset traverse mode!" << std::endl;
92 void postfix(
const unsigned long int index ) {
101 std::cerr <<
"BlockOrderer:: Unknown or unset traverse mode!" << std::endl;
102 exit( EXIT_FAILURE );
113 unsigned long int cur = root;
149 std::cerr <<
"BlockOrderer::traverse: Reached what should be unreachable code!" << std::endl;
151 exit( EXIT_FAILURE );
169 void pre_height (
const unsigned long int index );
172 void in_height (
const unsigned long int index );
185 virtual void pre_readout (
const unsigned long int index ) = 0;
188 virtual void in_readout (
const unsigned long int index ) = 0;
191 virtual void post_readout(
const unsigned long int index ) = 0;
197 std::vector< std::vector< Triplet< T > > > *
output;
204 unsigned long int bb_r_lo, bb_r_hi, bb_c_lo, bb_c_hi, r_lo, r_hi, c_lo, c_hi;
208 return ( triplet.
i() >= r_lo && triplet.
i() < r_hi && triplet.
j() >= bb_c_lo && triplet.
j() < c_lo );
213 unsigned long int bb_r_lo, bb_r_hi, bb_c_lo, bb_c_hi, r_lo, r_hi, c_lo, c_hi;
217 return ( triplet.
i() >= r_lo && triplet.
i() < r_hi && triplet.
j() >= c_hi && triplet.
j() < bb_c_hi );
222 unsigned long int bb_r_lo, bb_r_hi, bb_c_lo, bb_c_hi, r_lo, r_hi, c_lo, c_hi;
226 return ( triplet.
i() >= bb_r_lo && triplet.
i() < r_lo && triplet.
j() >= c_lo && triplet.
j() < c_hi );
231 unsigned long int bb_r_lo, bb_r_hi, bb_c_lo, bb_c_hi, r_lo, r_hi, c_lo, c_hi;
235 return ( triplet.
i() >= r_hi && triplet.
i() < bb_r_hi && triplet.
j() >= c_lo && triplet.
j() < c_hi );
240 unsigned long int bb_r_lo, bb_r_hi, bb_c_lo, bb_c_hi, r_lo, r_hi, c_lo, c_hi;
244 return ( triplet.
i() >= r_lo && triplet.
i() < r_hi && triplet.
j() >= c_lo && triplet.
j() < c_hi );
258 std::cerr <<
"Warning: BlockOrderer::output was somehow not reset to NULL!" << std::endl;
264 std::vector< unsigned long int > &r_hierarchy, std::vector< unsigned long int > &c_hierarchy,
265 std::vector< unsigned long int > &r_bounds, std::vector< unsigned long int > &c_bounds,
266 std::vector< signed char > *
datatype ) {
268 if( c_hierarchy.size() != r_hierarchy.size() ) {
269 std::cerr <<
"Error: Hierarchy vector is not of equal size!" << std::endl;
270 exit( EXIT_FAILURE );
276 std::vector< std::vector< Triplet< T > > > ret;
279 std::cout <<
"BlockOrderer, phase I (build tree)" << std::endl;
283 tree =
new SBDTree( r_hierarchy, c_hierarchy, r_bounds, c_bounds );
286 std::cout <<
"BlockOrderer, phase II (build height map and dictionary)" << std::endl;
292 for(
unsigned long int i=0; i<
tree->
size(); ++i )
height[ i ] = ULONG_MAX;
293 std::map< unsigned long int, unsigned long int > row_translate, col_translate;
298 for(
unsigned long int i=0; i<
tree->
size(); ++i ) assert(
height[ i ] != ULONG_MAX );
301 unsigned long int lo, hi;
302 for(
unsigned long int i=0; i<
tree->
size(); ++i ) {
306 row_translate[ hi ] = i;
309 col_translate[ hi ] = i;
314 std::cout <<
"BlockOrderer, phase III (assign triplets)" << std::endl;
319 std::vector< Triplet< double > >::const_iterator it = input.begin();
320 for( ; it != input.end(); ++it ) {
321 assert( row_translate.upper_bound( it->i() ) != row_translate.end() );
322 assert( col_translate.upper_bound( it->j() ) != col_translate.end() );
323 const unsigned long int i = row_translate.upper_bound( it->i() )->second;
324 const unsigned long int j = col_translate.upper_bound( it->j() )->second;
325 assert( i < tree->size() );
326 assert( j < tree->size() );
328 items[ i ].push_back( *it );
334 items[ i ].push_back( *it );
336 items[ j ].push_back( *it );
341 std::cout <<
"BlockOrderer, phase IV (read out tree & return)" << std::endl;
350 this->datatype = NULL;
351 unsigned int checksum = 0;
352 for(
unsigned int i=0; i<ret.size(); i++ )
353 checksum += ret[ i ].size();
354 if( checksum != input.size() ) {
355 std::cerr <<
"Lost nonzeroes during readout (" << checksum <<
" while expecting " << input.size() <<
")";
356 std::cerr <<
", breaking off process..." << std::endl;
357 std::cerr <<
"(This is problably due to (too many) empty separators)" << std::endl;
358 exit( EXIT_FAILURE );
Induces a block order by fully traversing an SBDTree.
Definition: BlockOrderer.hpp:48
void prefix(const unsigned long int index)
Prefix operation during SBD tree traversal.
Definition: BlockOrderer.hpp:62
void columnBounds(const unsigned long int index, unsigned long int &c_lo, unsigned long int &c_hi)
Returns the column bounds corresponding to a given node.
Definition: SBDTree.cpp:206
std::vector< std::vector< Triplet< T > > > induce(const std::vector< Triplet< T > > &input, std::vector< unsigned long int > &r_hierarchy, std::vector< unsigned long int > &c_hierarchy, std::vector< unsigned long int > &r_bounds, std::vector< unsigned long int > &c_bounds, std::vector< signed char > *datatype)
Induces this ordering on a set of nonzeroes.
Definition: BlockOrderer.hpp:263
virtual void post_readout(const unsigned long int index)=0
Postfix traversal code.
SBDTree * tree
The SBD tree to order the blocks of.
Definition: BlockOrderer.hpp:53
void post_height(const unsigned long int index)
Postfix code for height-determining traversal.
virtual void in_readout(const unsigned long int index)=0
Infix traversal code.
char isLeaf(const unsigned long int index)
Whether the given node is a leaf node.
Definition: SBDTree.cpp:214
ULI i() const
Definition: Triplet.hpp:70
void postfix(const unsigned long int index)
Postfix operation during SBD tree traversal.
Definition: BlockOrderer.hpp:92
unsigned long int cur_height
The current height at the traversal position.
Definition: BlockOrderer.hpp:166
bool left_horizontal(const unsigned long int index, const Triplet< T > triplet)
Helper function for determining place of a nonzero within a separator cross.
Definition: BlockOrderer.hpp:203
bool upper_vertical(const unsigned long int index, const Triplet< T > triplet)
Helper function for determining place of a nonzero within a separator cross.
Definition: BlockOrderer.hpp:221
unsigned long int left(const unsigned long int index)
Returns the left child of a given node.
Definition: SBDTree.cpp:180
std::vector< char > leftpass
Stores whether a node has been traversed from the left.
Definition: BlockOrderer.hpp:56
unsigned long int * height
Stores the height of a SBD node.
Definition: BlockOrderer.hpp:163
virtual ~BlockOrderer()
Base destructor.
Definition: BlockOrderer.hpp:256
void rowBounds(const unsigned long int index, unsigned long int &r_lo, unsigned long int &r_hi)
Returns the row bounds corresponding to a given node.
Definition: SBDTree.cpp:198
void in_height(const unsigned long int index)
Infix code for height-determining traversal.
bool right_horizontal(const unsigned long int index, const Triplet< T > triplet)
Helper function for determining place of a nonzero within a separator cross.
Definition: BlockOrderer.hpp:212
unsigned long int up(const unsigned long int index)
Returns the parent of a given node.
Definition: SBDTree.cpp:171
unsigned long int size()
Gets the number of nodes.
Definition: SBDTree.cpp:222
static const char READOUT
Mode flag for SBD tree readouts.
Definition: BlockOrderer.hpp:180
bool lower_vertical(const unsigned long int index, const Triplet< T > triplet)
Helper function for determining place of a nonzero within a separator cross.
Definition: BlockOrderer.hpp:230
virtual void pre_readout(const unsigned long int index)=0
Prefix traversal code.
void pre_height(const unsigned long int index)
Prefix code for height-determining traversal.
std::vector< std::vector< Triplet< T > > > * output
Output structure after SBD readout (series of blocks in the correct order).
Definition: BlockOrderer.hpp:197
unsigned long int right(const unsigned long int index)
Returns the right child of a given node.
Definition: SBDTree.cpp:189
unsigned long int getRoot()
Gets the root index.
Definition: SBDTree.cpp:226
static const char TRAVERSE_HEIGHT
Mode flag for height-determining traversal.
Definition: BlockOrderer.hpp:160
BlockOrderer()
Base constructor.
Definition: BlockOrderer.hpp:253
ULI j() const
Definition: Triplet.hpp:73
char traverse_mode
Sets the traversal mode.
Definition: BlockOrderer.hpp:155
std::vector< char > rightpass
Stores whether a node has been traversed from the right.
Definition: BlockOrderer.hpp:59
void infix(const unsigned long int index)
Infix operation during SBD tree traversal.
Definition: BlockOrderer.hpp:77
bool middle(const unsigned long int index, const Triplet< T > triplet)
Helper function for determining place of a nonzero within a separator cross.
Definition: BlockOrderer.hpp:239
std::vector< signed char > * datatype
The data type of each block.
Definition: BlockOrderer.hpp:200
Models a Separated Block Diagonal tree structure.
Definition: SBDTree.hpp:44
A single triplet value.
Definition: Triplet.hpp:52
void getSeparatorBB(const unsigned long int index, unsigned long int &r_lo, unsigned long int &r_hi, unsigned long int &c_lo, unsigned long int &c_hi)
Gets, from a separator node, the bounding box of the nonzeroes contained in the separator.
Definition: SBDTree.cpp:141
void traverse()
Traverses the SBD tree, makes call to prefix, infix, and postfix during traversal.
Definition: BlockOrderer.hpp:107
std::vector< Triplet< T > > * items
Nonzero storage at each node.
Definition: BlockOrderer.hpp:194