Skip to content

Expression estimator/transformer #4548

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 9 commits into from
Dec 26, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix unit tests
  • Loading branch information
yaeldMS committed Dec 23, 2019
commit e8f34918edffeed1c0a3e8cd3f025121a3609863
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using Microsoft.ML;
Expand All @@ -23,6 +24,7 @@
using Microsoft.ML.Transforms;
using Microsoft.ML.RunTests;
using Microsoft.ML.Tests;
using Microsoft.ML.TestFramework.Attributes;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -57,12 +59,15 @@ public void ExprParse()
Run("ExprParse");
}

[Fact, TestCategory("Expr Language")]
#if !NETFRAMEWORK
// Bug in sin(x) in .Net Framework: sin(1e+30) returns 1e+30.
[X64Fact("sin(1e+30) gives different value on x86."), TestCategory("Expr Language")]
public void ExprBind()
{
// Code coverage test for the binder.
Run("ExprBind");
}
#endif

[Fact, TestCategory("Expr Language")]
public void ExprBindEx()
Expand Down Expand Up @@ -90,16 +95,6 @@ private string InResName(string name)
return ResourcePrefix + name + "Input.txt";
}

private string InFileName(string name)
{
return name + "Input.txt";
}

private string OutFileName(string name)
{
return name + "Output.txt";
}

private string GetResText(string resName)
{
var stream = typeof(ExprLanguageTests).Assembly.GetManifestResourceStream(resName);
Expand All @@ -114,7 +109,7 @@ private string GetResText(string resName)

private void Run(string name)
{
string outDir = Path.Combine("..", "Common", "ExprParser");
string outDir = "ExprParser";

string text = GetResText(InResName(name));
string inName = name + "Input.txt";
Expand Down Expand Up @@ -217,13 +212,13 @@ private void Run(string name)
TestFuncs1.Writer = null;
}

LDone:
LDone:
wrt.WriteLine("===== End {0} =====", scriptName);
}
}
}

CheckEquality(outDir, outName);
CheckEquality(outDir, outName, digitsOfPrecision: 6);

Done();
}
Expand Down Expand Up @@ -261,7 +256,11 @@ private void Evaluate(IndentedTextWriter wrt, Delegate del, DataViewType typeRes
ReadOnlyMemory<char> chars = text.AsMemory().Slice(ichMin, ichLim - ichMin);
for (bool more = true; more;)
{
more = ReadOnlyMemoryUtils.SplitOne(chars, '\x0D', out var line, out chars);
ReadOnlyMemory<char> line;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
more = ReadOnlyMemoryUtils.SplitOne(chars, '\x0D', out line, out chars);
else
more = ReadOnlyMemoryUtils.SplitOne(chars, '\x0A', out line, out chars);
line = ReadOnlyMemoryUtils.TrimWhiteSpace(line);
if (line.IsEmpty)
continue;
Expand Down Expand Up @@ -295,7 +294,7 @@ private Func<ReadOnlyMemory<char>, bool> GetGetter(int i, DataViewType dst, obje
{
bool v;
bool tmp = Conversions.Instance.TryParse(in src, out v);
args[i] = (object)v;
args[i] = v;
return tmp;
};
case InternalDataKind.I4:
Expand All @@ -304,7 +303,7 @@ private Func<ReadOnlyMemory<char>, bool> GetGetter(int i, DataViewType dst, obje
{
int v;
bool tmp = Conversions.Instance.TryParse(in src, out v);
args[i] = (object)v;
args[i] = v;
return tmp;
};
case InternalDataKind.I8:
Expand All @@ -313,32 +312,32 @@ private Func<ReadOnlyMemory<char>, bool> GetGetter(int i, DataViewType dst, obje
{
long v;
bool tmp = Conversions.Instance.TryParse(in src, out v);
args[i] = (object)v;
args[i] = v;
return tmp;
};
case InternalDataKind.R4:
return
src =>
{
Single v;
float v;
bool tmp = Conversions.Instance.TryParse(in src, out v);
args[i] = (object)v;
args[i] = v;
return tmp;
};
case InternalDataKind.R8:
return
src =>
{
Double v;
double v;
bool tmp = Conversions.Instance.TryParse(in src, out v);
args[i] = (object)v;
args[i] = v;
return tmp;
};
case InternalDataKind.TX:
return
src =>
{
args[i] = (object)src;
args[i] = src;
return true;
};
}
Expand Down