@@ -56,12 +56,16 @@ namespace mt_kahypar::io {
5656 bool & has_vertex_weights) {
5757 if (!is_line_ending (mapped_file, pos)) {
5858 // read the (up to) three 0/1 format digits
59- uint32_t format_num = read_number<uint32_t >(mapped_file, pos, current_line, length, " format specifier" );
60- // TODO
61- ASSERT (format_num < 100 , " Vertex sizes in input file are not supported." );
62- ASSERT (format_num / 10 == 0 || format_num / 10 == 1 );
59+ uint32_t format_num = read_number<uint32_t >(mapped_file, pos, current_line, length, " weight type" );
60+ if (format_num >= 100 ) {
61+ parsing_exception (current_line, " header has invalid weight type: " + STR (format_num) +
62+ " (should be one of 00/01/10/11; note that vertex sizes are not supported)" );
63+ }
64+ bool format_is_valid = (format_num / 10 == 0 || format_num / 10 == 1 ) && (format_num % 10 == 0 || format_num % 10 == 1 );
65+ if (!format_is_valid) {
66+ parsing_exception (current_line, " header has invalid weight type: " + STR (format_num) + " (should be one of 00/01/10/11)" );
67+ }
6368 has_vertex_weights = (format_num / 10 == 1 );
64- ASSERT (format_num % 10 == 0 || format_num % 10 == 1 );
6569 has_edge_weights = (format_num % 10 == 1 );
6670 }
6771 }
@@ -108,6 +112,7 @@ namespace mt_kahypar::io {
108112 size_t & current_line,
109113 const size_t length,
110114 const HyperedgeID num_hyperedges,
115+ const HypernodeID num_hypernodes,
111116 const bool has_hyperedge_weights,
112117 HyperedgeVector& hyperedges,
113118 vec<HyperedgeWeight>& hyperedges_weight,
@@ -159,7 +164,12 @@ namespace mt_kahypar::io {
159164 Hyperedge hyperedge;
160165 while ( !is_line_ending (mapped_file, current_pos) ) {
161166 HypernodeID pin = read_number<HypernodeID>(mapped_file, current_pos, current_line, current_end, " vertex ID" );
162- ASSERT (pin > 0 , V (current_hyperedge_id));
167+ if (pin == 0 ) {
168+ parsing_exception (current_line, " 0 is not a valid vertex ID; the hMETIS file format requires that IDs start at 1" );
169+ }
170+ if (pin > num_hypernodes) {
171+ parsing_exception (current_line, " invalid vertex ID: " + STR (pin) + " (larger than number of vertices)" );
172+ }
163173 hyperedge.push_back (pin - 1 );
164174 }
165175 do_line_ending (mapped_file, current_pos, current_line);
@@ -216,7 +226,9 @@ namespace mt_kahypar::io {
216226 if ( has_hypernode_weights ) {
217227 hypernodes_weight.resize (num_hypernodes);
218228 for ( HypernodeID hn = 0 ; hn < num_hypernodes; ++hn ) {
219- ASSERT (pos > 0 && pos < length);
229+ if (pos >= length) {
230+ parsing_exception (" found only " + STR (hn) + " hypernode weights, but there are " + STR (num_hypernodes) + " hypernodes" );
231+ }
220232 ASSERT (mapped_file[pos - 1 ] == ' \n ' );
221233 hypernodes_weight[hn] = read_number<HypernodeWeight>(mapped_file, pos, current_line, length, " vertex weight" );
222234 do_line_ending (mapped_file, pos, current_line);
@@ -249,7 +261,7 @@ namespace mt_kahypar::io {
249261 // Read Hyperedges
250262 HighResClockTimepoint hyperedges_start = std::chrono::high_resolution_clock::now ();
251263 HyperedgeReadResult res =
252- readHyperedges (handle.mapped_file , pos, current_line, handle.length , num_hyperedges,
264+ readHyperedges (handle.mapped_file , pos, current_line, handle.length , num_hyperedges, num_hypernodes,
253265 has_hyperedge_weights, hyperedges, hyperedges_weight, remove_single_pin_hes);
254266 num_hyperedges -= res.num_removed_single_pin_hyperedges ;
255267 num_removed_single_pin_hyperedges = res.num_removed_single_pin_hyperedges ;
@@ -384,7 +396,12 @@ namespace mt_kahypar::io {
384396
385397 while ( !is_line_ending (mapped_file, current_pos) ) {
386398 const HypernodeID target = read_number<HypernodeID>(mapped_file, current_pos, current_line, current_end, " node ID" );
387- ASSERT (target > 0 && (target - 1 ) < num_vertices, V (target));
399+ if (target == 0 ) {
400+ parsing_exception (current_line, " 0 is not a valid node ID; the METIS file format requires that IDs start at 1" );
401+ }
402+ if (target > num_vertices) {
403+ parsing_exception (current_line, " invalid node ID: " + STR (target) + " (larger than number of nodes)" );
404+ }
388405
389406 // process forward edges, ignore backward edges
390407 if ( current_vertex_id < (target - 1 ) ) {
@@ -407,7 +424,11 @@ namespace mt_kahypar::io {
407424 LOG << V (second_pass_time);
408425
409426 // finally, we copy the local edge lists to the global list
410- copy_to_global_list (local_edges, edges);
427+ size_t actual_num_edges = copy_to_global_list (local_edges, edges);
428+ if (actual_num_edges != num_edges) {
429+ parsing_exception (" number of edges in header (=" + STR (num_edges) +
430+ " ) does not match actual number of (forward) edges in file (=" + STR (actual_num_edges) + " )" );
431+ }
411432 if ( has_edge_weights ) {
412433 copy_to_global_list (local_edges_weight, edges_weight);
413434 ASSERT (edges.size () == edges_weight.size ());
0 commit comments