Skip to content

Commit

Permalink
Fix for Issue #59
Browse files Browse the repository at this point in the history
	modified:   src/main/java/edu/ucla/sspace/matrix/MatrixIO.java

- Added support for reading in NaN values for SVDLIBC's output
  • Loading branch information
David Jurgens committed Jan 27, 2015
1 parent 824367a commit 89cb347
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/edu/ucla/sspace/matrix/MatrixIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,14 @@ else if (cols == -1) {
int row = valuesSeen / cols;
int col = valuesSeen % cols;

double val = Double.parseDouble(vals[i]);
// NOTE: SVDLIBC doesn't seem to capitalize its NaN values,
// which causes Java's double parsing code to break. We
// don't really expect this case to happen but it seems to
// when passed the results of calling SVD on a degenerate
// matrix, so we check so that the code "just works".
double val = (vals[i].equals("nan"))
? Double.NaN
: Double.parseDouble(vals[i]);

if (transposeOnRead)
m.set(col, row, val);
Expand Down Expand Up @@ -1071,7 +1078,7 @@ private static Matrix readSparseSVDLIBCbinary(File matrix, Type matrixType,
((transposeOnRead) ? "transposed" : ""),
rows, cols, nz));
Matrix m = null;

// Special case for reading transposed data. This avoids the log(n)
// overhead from resorting the row data for the matrix, which can be
// significant in large matrices.
Expand Down

0 comments on commit 89cb347

Please sign in to comment.