Skip to content

Address PR feedback from #2579 #2611

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

Merged
merged 1 commit into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/Microsoft.ML.Data/Data/Conversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1585,17 +1585,6 @@ 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();
return true;
}

return false;
}
public void Convert(in TX span, ref U4 value)
{
value = ParseU4(in span);
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.ML.Data/DataLoadSave/Text/TextLoaderParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,8 +1016,8 @@ public int GatherFields(ReadOnlyMemory<char> lineSpan, ReadOnlySpan<char> span,
}
var spanT = Fields.Spans[Fields.Count - 1];

int csrc = 0;
if (!Conversions.Instance.TryConvert(in spanT, ref csrc) || csrc <= 0)
int csrc;
if (!Conversions.Instance.TryParse(in spanT, out csrc) || csrc <= 0)
Copy link
Member

@stephentoub stephentoub Feb 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that TryParse is going to be slightly more expensive, but it's unlikely to be measurable, especially given everything else going on here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slightly more expensive

Because of the extra write to the out parameter? Or because of the under/overflow check? Or something else?

Copy link
Member

@stephentoub stephentoub Feb 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra indirect write in the case of success, two extra indirect writes in the case of failure, the overflow check, the cast from the nullable rather than GetValueOrDefault, larger code that's even less likely to be inlined (though it's probably already not getting inlined). In general this code is not particularly clean.

{
_stats.LogBadFmt(ref scan, "Bad dimensionality or ambiguous sparse item. Use sparse=- for non-sparse file, and/or quote the value.");
break;
Expand Down