summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjan.reininghaus <jan.reininghaus@8e3bb3c2-eed4-f18f-5264-0b6c94e6926d>2013-04-23 09:46:54 +0000
committerjan.reininghaus <jan.reininghaus@8e3bb3c2-eed4-f18f-5264-0b6c94e6926d>2013-04-23 09:46:54 +0000
commit3cf63b2f122f1fd9a967ee9dc7a21436f4a94077 (patch)
tree564b36ccc0f2a4bdf64f9843313d94da4b5bce95
parent6119cf9deec63c756a4d022655e46df319d42c92 (diff)
new vector<vector> interface for boundary_matrix
git-svn-id: https://phat.googlecode.com/svn/trunk@38 8e3bb3c2-eed4-f18f-5264-0b6c94e6926d
-rw-r--r--include/phat/boundary_matrix.h32
-rw-r--r--include/phat/helpers/dualize.h2
-rw-r--r--src/self_test.cpp17
3 files changed, 46 insertions, 5 deletions
diff --git a/include/phat/boundary_matrix.h b/include/phat/boundary_matrix.h
index 6700b3d..28b58fa 100644
--- a/include/phat/boundary_matrix.h
+++ b/include/phat/boundary_matrix.h
@@ -115,7 +115,7 @@ namespace phat {
for( index idx = 0; idx < number_of_columns; idx++ ) {
this->get_col( idx, temp_col );
other_boundary_matrix.get_col( idx, other_temp_col );
- if( temp_col != other_temp_col )
+ if( temp_col != other_temp_col || this->get_dim( idx ) != other_boundary_matrix.get_dim( idx ) )
return false;
}
return true;
@@ -146,12 +146,36 @@ namespace phat {
public:
// initializes boundary_matrix from (vector<vector>, vector) pair -- untested
- void init( const std::vector< std::vector< index > >& input_matrix, const std::vector< dimension >& input_dims ) {
+ template< typename index_type, typename dimemsion_type >
+ void load_vector_vector( const std::vector< std::vector< index_type > >& input_matrix, const std::vector< dimemsion_type >& input_dims ) {
const index nr_of_columns = (index)input_matrix.size();
this->set_num_cols( nr_of_columns );
+ column temp_col;
+ for( index cur_col = 0; cur_col < nr_of_columns; cur_col++ ) {
+ this->set_dim( cur_col, (dimension)input_dims[ cur_col ] );
+
+ index num_rows = input_matrix[ cur_col ].size();
+ temp_col.resize( num_rows );
+ for( index cur_row = 0; cur_row < num_rows; cur_row++ )
+ temp_col[ cur_row ] = (index)input_matrix[ cur_col ][ cur_row ];
+ this->set_col( cur_col, temp_col );
+ }
+ }
+
+ template< typename index_type, typename dimemsion_type >
+ void save_vector_vector( std::vector< std::vector< index_type > >& output_matrix, std::vector< dimemsion_type >& output_dims ) {
+ const index nr_of_columns = get_num_cols();
+ output_matrix.resize( nr_of_columns );
+ output_dims.resize( nr_of_columns );
+ column temp_col;
for( index cur_col = 0; cur_col < nr_of_columns; cur_col++ ) {
- this->set_dim( cur_col, input_dims[ cur_col ] );
- this->set_col( cur_col, input_matrix[ cur_col ] );
+ output_dims[ cur_col ] = (dimemsion_type)get_dim( cur_col );
+ get_col( cur_col, temp_col );
+ index num_rows = temp_col.size();
+ output_matrix[ cur_col ].clear();
+ output_matrix[ cur_col ].resize( num_rows );
+ for( index cur_row = 0; cur_row < num_rows; cur_row++ )
+ output_matrix[ cur_col ][ cur_row ] = (index_type)temp_col[ cur_row ];
}
}
diff --git a/include/phat/helpers/dualize.h b/include/phat/helpers/dualize.h
index 15f7c57..752103d 100644
--- a/include/phat/helpers/dualize.h
+++ b/include/phat/helpers/dualize.h
@@ -46,6 +46,6 @@ namespace phat {
for( index cur_col = 0; cur_col < nr_of_columns; cur_col++ )
std::reverse( dual_matrix[ cur_col ].begin(), dual_matrix[ cur_col ].end() );
- boundary_matrix.init( dual_matrix, dual_dims );
+ boundary_matrix.load_vector_vector( dual_matrix, dual_dims );
}
}
diff --git a/src/self_test.cpp b/src/self_test.cpp
index 858a475..9ce44bc 100644
--- a/src/self_test.cpp
+++ b/src/self_test.cpp
@@ -161,5 +161,22 @@ int main( int argc, char** argv )
else std::cout << "All results are identical (as they should be)" << std::endl;
}
+ std::cout << "Testing vector<vector> interface ..." << std::endl;
+ {
+ std::vector< std::vector< int > > vector_vector_matrix;
+ std::vector< int > vector_dims;
+ boundary_matrix.save_vector_vector( vector_vector_matrix, vector_dims );
+ phat::boundary_matrix< BitTree > vector_vector_boundary_matrix;
+ vector_vector_boundary_matrix.load_vector_vector( vector_vector_matrix, vector_dims );
+
+ if( vector_vector_boundary_matrix != boundary_matrix ) {
+ std::cerr << "Error: [load|save]_vector_vector bug" << std::endl;
+ error = true;
+ }
+
+ if( error ) return EXIT_FAILURE;
+ else std::cout << "Test passed!" << std::endl;
+ }
+
return EXIT_SUCCESS;
}