summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-05-15 08:28:34 +0000
committerpdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-05-15 08:28:34 +0000
commit16a63d90930a72f20388a803694fc757a3482683 (patch)
treeb8a841120b33ba049d02e7f436f1b453c8207f5f /src
parent0e2ee9211f44f717e9a7b658e824ed1cf0ba7f6c (diff)
Possible solution of a problem of inf on mac
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/gudhi_stat@2418 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 854d171274535e6a7edf2133c0bca116b098eaa5
Diffstat (limited to 'src')
-rw-r--r--src/Gudhi_stat/include/gudhi/read_persistence_from_file.h27
-rw-r--r--src/Gudhi_stat/test/persistence_lanscapes_test.cpp2
2 files changed, 22 insertions, 7 deletions
diff --git a/src/Gudhi_stat/include/gudhi/read_persistence_from_file.h b/src/Gudhi_stat/include/gudhi/read_persistence_from_file.h
index f869f8e2..b82a55b3 100644
--- a/src/Gudhi_stat/include/gudhi/read_persistence_from_file.h
+++ b/src/Gudhi_stat/include/gudhi/read_persistence_from_file.h
@@ -125,6 +125,7 @@ std::vector< std::vector< double > > read_numbers_from_file_line_by_line( const
* If there are three numerical entries per line, then the function assume that they are: dimension and birth/death coordinates.
* If there are four numerical entries per line, then the function assume that they are: thc characteristic of a filed over which
* persistence was computed, dimension and birth/death coordinates.
+ * The 'inf' string can appear only as a last element of a line.
* The procedure returns vector of persistence pairs.
**/
std::vector<std::pair<double,double> > read_persistence_intervals_in_one_dimension_from_file(std::string const& filename, int dimension=-1 , double what_to_substitute_for_infinite_bar = -1 )
@@ -155,18 +156,27 @@ std::vector<std::pair<double,double> > read_persistence_intervals_in_one_dimensi
{
//If we do not know how many entries per line we have, we check it in below.
if ( number_of_entries_per_line == -1 )
- {
+ {
+ number_of_entries_per_line = 0;
+ std::string line_copy = line;
+ if ( line.find("inf") != std::string::npos )
+ {
+ size_t np = line_copy.find("inf");
+ //replace symbols 'inf' in line_copy with whilespaces:
+ line_copy[np] = ' ';
+ line_copy[np+1] = ' ';
+ line_copy[np+2] = ' ';
+ number_of_entries_per_line = 1;
+ }
//check how many entries we have in the line.
- std::stringstream ss( line );
+ std::stringstream ss( line_copy );
double number;
std::vector<double> this_line;
while ( ss >> number )
{
this_line.push_back( number );
}
- number_of_entries_per_line = (int)this_line.size();
- //if thie line contains 'inf' string, then we need to increment number_of_entries_per_line
- if ( line.find("inf") != std::string::npos )++number_of_entries_per_line;
+ number_of_entries_per_line += (int)this_line.size();
if ( dbg )
{
std::cerr << "number_of_entries_per_line : " << number_of_entries_per_line << ". This number was obtained by analyzing this line : " << line << std::endl;
@@ -184,6 +194,11 @@ std::vector<std::pair<double,double> > read_persistence_intervals_in_one_dimensi
{
std::cerr << "This line: " << line << " contains infinite interval. \n";
}
+ //first we substitute inf by whitespaces:
+ size_t np = line.find("inf");
+ line[np] = ' ';
+ line[np+1] = ' ';
+ line[np+2] = ' ';
if ( what_to_substitute_for_infinite_bar != -1 )
{
double beginn, field, dim;
@@ -223,7 +238,7 @@ std::vector<std::pair<double,double> > read_persistence_intervals_in_one_dimensi
}
continue;
}
- //Then, we read the content of the line:
+ //Then, we read the content of the line. We know that it do not contain 'inf' substring.
std::stringstream lineSS(line);
double beginn, endd, field, dim;
if ( number_of_entries_per_line == 4 )lineSS >> field;
diff --git a/src/Gudhi_stat/test/persistence_lanscapes_test.cpp b/src/Gudhi_stat/test/persistence_lanscapes_test.cpp
index 253b06d7..5985cec3 100644
--- a/src/Gudhi_stat/test/persistence_lanscapes_test.cpp
+++ b/src/Gudhi_stat/test/persistence_lanscapes_test.cpp
@@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(check_construction_of_landscape)
BOOST_AUTO_TEST_CASE(check_construction_of_landscape_form_gudhi_style_file)
{
- Persistence_landscape p( "data/persistence_file_with_four_entries_per_line" , 1 );
+ Persistence_landscape p( "data/persistence_file_with_four_entries_per_line" , 1 );
//p.print_to_file("persistence_file_with_four_entries_per_line_landscape");
Persistence_landscape q;
q.load_landscape_from_file( "data/persistence_file_with_four_entries_per_line_landscape" );