Changeset 439


Ignore:
Timestamp:
Dec 15, 2005, 1:46:38 PM (17 years ago)
Author:
Markus Ringnér
Message:

Fixed istream parsing when separator is last on line: a trailing NaN is generated

Location:
trunk/lib/gslapi
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/gslapi/matrix.cc

    r434 r439  
    5656      std::string element;
    5757      std::stringstream ss(line);
     58     
    5859      bool ok=true;
    5960      while(ok) {
     
    7778        }
    7879      }           
     80      if(sep!='\0' && line[line.size()-1]==sep) // add NaN for final separator
     81          v.push_back(std::numeric_limits<double>::quiet_NaN());
    7982      if (!nof_columns)
    8083        nof_columns=v.size();
     
    8285        std::ostringstream s;
    8386        s << "matrix::matrix(std::istream&, char) data file error: "
    84           << "line" << nof_rows+1 << " has " << v.size()
     87          << "line" << nof_rows << " has " << v.size()
    8588          << " columns; expected " << nof_columns << " columns.";
    8689        throw utility::IO_error(s.str());
  • trunk/lib/gslapi/vector.cc

    r434 r439  
    104104        }
    105105      }
     106      if(sep!='\0' && line[line.size()-1]==sep) // add NaN for final separator
     107          v.push_back(std::numeric_limits<double>::quiet_NaN());
    106108      if (!nof_columns)
    107109        nof_columns=v.size();
     
    109111        std::ostringstream s;
    110112        s << "vector::vector(std::istream&) data file error:\n"
    111           << "    File has inconsistent number of rows (" << nof_rows+1
     113          << "    File has inconsistent number of rows (" << nof_rows
    112114          << ") and columns (" << nof_columns
    113115          << ").\n    Expected a row or a column vector.";
     
    117119        std::ostringstream s;
    118120        s << "vector::vector(std::istream&) data file error:\n"
    119           << "    Line " << (nof_rows+1) << " has " << v.size()
     121          << "    Line " << nof_rows << " has " << v.size()
    120122          << " columns; expected " << nof_columns << " column.";
    121123        throw utility::IO_error(s.str());
  • trunk/lib/gslapi/vector.h

    r434 r439  
    317317    /// Sort the elements in the vector.
    318318    ///
     319    /// Bug in gsl: if vector contains NaN an infinite loop is entered.
    319320    ///
    320321    // Markus to Jari, doxygen group as Exchanging elements ????
    321     inline void sort(void) { return gsl_sort_vector(v_);}
     322    inline void sort(void) { gsl_sort_vector(v_);}
    322323
    323324
Note: See TracChangeset for help on using the changeset viewer.