Skip to content

Commit 1f53146

Browse files
committed
faster number parsing
1 parent 37f7225 commit 1f53146

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/main/java/org/apache/sysds/runtime/frame/data/columns/DoubleArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ public static double parseDouble(String value) {
377377
return Double.POSITIVE_INFINITY;
378378
else if(len == 4 && value.compareToIgnoreCase("-Inf") == 0)
379379
return Double.NEGATIVE_INFINITY;
380-
throw new DMLRuntimeException(e);
380+
throw e;
381381
}
382382
}
383383

src/main/java/org/apache/sysds/runtime/frame/data/columns/StringArray.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,8 @@ private static double getAsDouble(String s) {
616616
else if(ls.equals("false") || ls.equals("f"))
617617
return 0;
618618
else
619-
throw new DMLRuntimeException("Unable to change to double: " + s, e);
619+
throw e; // for efficiency
620+
// throw new DMLRuntimeException("Unable to change to double: " + s, e);
620621
}
621622
}
622623

src/main/java/org/apache/sysds/utils/DoubleParser.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public interface DoubleParser {
184184
0x8e679c2f5e44ff8fL};
185185

186186
public static double parseFloatingPointLiteral(String str, int offset, int endIndex) {
187-
if(endIndex > 100)
187+
if(endIndex > 100)// long string
188188
return Double.parseDouble(str);
189189
// Skip leading whitespace
190190
int index = skipWhitespace(str, offset, endIndex);
@@ -197,9 +197,10 @@ public static double parseFloatingPointLiteral(String str, int offset, int endIn
197197
}
198198

199199
// Parse NaN or Infinity (this occurs rarely)
200-
if(ch >= 'I')
201-
return Double.parseDouble(str);
202-
else if(str.charAt(endIndex - 1) >= 'a')
200+
// : is the first character after numbers.
201+
// 0 is the first number.
202+
// we use the last position, since this is not allowed to be other values than a number.
203+
if(str.charAt(endIndex - 1) > '9' || str.charAt(endIndex - 1) < '0')
203204
return Double.parseDouble(str);
204205

205206
final double val = parseDecFloatLiteral(str, index, offset, endIndex);

0 commit comments

Comments
 (0)