-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Remove exception due to supportsSparse:true in ReadFromTextLoader #2579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1585,6 +1585,17 @@ public void Convert(in TX span, ref I4 value) | |
{ | ||
value = ParseI4(in span); | ||
} | ||
public bool TryConvert(in TX span, ref I4 value) | ||
{ | ||
TryParseSigned(I4.MaxValue, in span, out long? res); | ||
if (res.HasValue) | ||
{ | ||
value = (I4)res.GetValueOrDefault(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Why not just GetValue() since you have already checked it has value? Alternatively we can remove this if condition and do the below: value = (I4)res.GetValueOrDefault(); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Exactly because we already checked it has a value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation. My understanding of these routines was the exact opposite of what they really do. Looks good! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm. We may have some code to rewrite a number of places... opened #2612 to track this. |
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
public void Convert(in TX span, ref U4 value) | ||
{ | ||
value = ParseU4(in span); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the existing
TryParse
method?machinelearning/src/Microsoft.ML.Data/Data/Conversion.cs
Lines 1184 to 1201 in 369a9b6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to remain consistent with the existing code, which assigned a value, then passed it by ref, and then checked whether it remained what it was assigned. In practice it wouldn't matter because it would end up with the default value in either case, but it would incur additional writes in the failure case, and I didn't know whether it would matter. When I don't know a code base particularly well and what ramifications my changes might have, I try to maintain the existing code as much as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess my concern is the consistency in the internal
Conversion
class.TryParse
andTryConvert
. Which one should new callers choose?TryConvert
for Int32, but no other types?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you feel strongly about this and want to change the call site to use TryParse, go for it. As I noted, my goal was to muck minimally with the call site logic.