Skip to content

Commit fabdabf

Browse files
authored
Update to Preview5 of .NET Core 3.0 (#3532)
* Update to Preview4 of .NET Core 3.0 * Update to the latest 3.0 Preview5 build * Fix up for AVX naming change * Fix up first set of tests to account for formatting change on netcoreapp3.0. * Update to latest Preview 5 * Fix tests by adding a new option for comparing numbers - parsing as float instead of double. The TestConvertWorkout test had both floats and doubles in the baseline, so re-wrote the validation to validate in memory, instead of using a basline. * Update to .NET Core 3.0.100-preview5-011568
1 parent 3712486 commit fabdabf

File tree

12 files changed

+235
-108
lines changed

12 files changed

+235
-108
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.100-preview-010184
1+
3.0.100-preview5-011568

src/Microsoft.ML.CpuMath/AvxIntrinsics.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private static Vector256<float> GetNewDst256(in Vector256<float> xDst1, in Vecto
137137
Vector256<float> signMask = Vector256.Create(-0.0f); // 0x8000 0000
138138
Vector256<float> xSign = Avx.And(xDst1, signMask); // result = 0x8000 0000 if xDst1 is negative or 0x0000 0000 otherwise
139139
Vector256<float> xDst1Abs = Avx.Xor(xDst1, xSign);
140-
Vector256<float> xCond = Avx.Compare(xDst1Abs, xThreshold, FloatComparisonMode.GreaterThanOrderedNonSignaling); // result = 0xFFFF FFFF if true
140+
Vector256<float> xCond = Avx.Compare(xDst1Abs, xThreshold, FloatComparisonMode.OrderedGreaterThanNonSignaling); // result = 0xFFFF FFFF if true
141141
Vector256<float> x2 = Avx.Xor(xSign, xThreshold); // -xThreshold if xDst1 is negative and +xThreshold otherwise
142142
return Avx.And(Avx.Subtract(xDst1, x2), xCond);
143143
}

test/BaselineOutput/Common/Convert/Types.tsv

-30
This file was deleted.

test/Microsoft.ML.Predictor.Tests/TestPredictors.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public void FastForestRegressionTest()
399399
TestLearners.QuantileRegressionScorer,
400400
};
401401
var regressionDatasets = GetDatasetsForRegressorTest();
402-
RunAllTests(regressionPredictors, regressionDatasets);
402+
RunAllTests(regressionPredictors, regressionDatasets, parseOption: NumberParseOption.UseSingle);
403403
});
404404
Done();
405405
}
@@ -531,7 +531,7 @@ public void RegressorLightGBMTest()
531531
{
532532
var regPredictors = new[] { TestLearners.LightGBMReg };
533533
var regDatasets = new[] { TestDatasets.generatedRegressionDataset };
534-
RunAllTests(regPredictors, regDatasets);
534+
RunAllTests(regPredictors, regDatasets, parseOption: NumberParseOption.UseSingle);
535535
Done();
536536
}
537537

@@ -545,7 +545,7 @@ public void RegressorLightGBMMAETest()
545545
{
546546
var regPredictors = new[] { TestLearners.LightGBMRegMae };
547547
var regDatasets = new[] { TestDatasets.generatedRegressionDataset };
548-
RunAllTests(regPredictors, regDatasets, extraTag: "MAE");
548+
RunAllTests(regPredictors, regDatasets, extraTag: "MAE", parseOption: NumberParseOption.UseSingle);
549549
Done();
550550
}
551551

@@ -559,7 +559,7 @@ public void RegressorLightGBMRMSETest()
559559
{
560560
var regPredictors = new[] { TestLearners.LightGBMRegRmse };
561561
var regDatasets = new[] { TestDatasets.generatedRegressionDataset };
562-
RunAllTests(regPredictors, regDatasets, extraTag: "RMSE");
562+
RunAllTests(regPredictors, regDatasets, extraTag: "RMSE", parseOption: NumberParseOption.UseSingle);
563563
Done();
564564
}
565565

test/Microsoft.ML.TestFramework/BaseTestBaseline.cs

+51-19
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ protected BaseTestBaseline(ITestOutputHelper output) : base(output)
6060
private static readonly string BinRegUnixExp = @"\/[^\\\t ]+\/bin\/" + Mode;
6161
private static readonly string Bin64RegUnixExp = @"\/[^\\\t ]+\/bin\/x64\/" + Mode;
6262
// The Regex matches both positive and negative decimal point numbers present in a string.
63-
// The numbers could be a part of a word. They can also be in Exponential form eg. 3E-9
64-
private static readonly Regex MatchNumbers = new Regex(@"-?\b[0-9]+\.?[0-9]*(E-[0-9]*)?\b", RegexOptions.IgnoreCase | RegexOptions.Compiled);
63+
// The numbers could be a part of a word. They can also be in Exponential form eg. 3E-9 or 4E+07
64+
private static readonly Regex MatchNumbers = new Regex(@"-?\b[0-9]+\.?[0-9]*(E[-+][0-9]*)?\b", RegexOptions.IgnoreCase | RegexOptions.Compiled);
6565

6666
/// <summary>
6767
/// When the progress log is appended to the end of output (in test runs), this line precedes the progress log.
@@ -330,21 +330,24 @@ public void Dispose()
330330
/// <summary>
331331
/// Compare the contents of an output file with its baseline.
332332
/// </summary>
333-
protected bool CheckEquality(string dir, string name, string nameBase = null, int digitsOfPrecision = DigitsOfPrecision)
333+
protected bool CheckEquality(string dir, string name, string nameBase = null,
334+
int digitsOfPrecision = DigitsOfPrecision, NumberParseOption parseOption = NumberParseOption.Default)
334335
{
335-
return CheckEqualityCore(dir, name, nameBase ?? name, false, digitsOfPrecision);
336+
return CheckEqualityCore(dir, name, nameBase ?? name, false, digitsOfPrecision, parseOption);
336337
}
337338

338339
/// <summary>
339340
/// Check whether two files are same ignoring volatile differences (path, dates, times, etc).
340341
/// Returns true if the check passes.
341342
/// </summary>
342-
protected bool CheckEqualityNormalized(string dir, string name, string nameBase = null, int digitsOfPrecision = DigitsOfPrecision)
343+
protected bool CheckEqualityNormalized(string dir, string name, string nameBase = null,
344+
int digitsOfPrecision = DigitsOfPrecision, NumberParseOption parseOption = NumberParseOption.Default)
343345
{
344-
return CheckEqualityCore(dir, name, nameBase ?? name, true, digitsOfPrecision);
346+
return CheckEqualityCore(dir, name, nameBase ?? name, true, digitsOfPrecision, parseOption);
345347
}
346348

347-
protected bool CheckEqualityCore(string dir, string name, string nameBase, bool normalize, int digitsOfPrecision = DigitsOfPrecision)
349+
protected bool CheckEqualityCore(string dir, string name, string nameBase, bool normalize,
350+
int digitsOfPrecision = DigitsOfPrecision, NumberParseOption parseOption = NumberParseOption.Default)
348351
{
349352
Contracts.Assert(IsActive);
350353
Contracts.AssertValue(dir); // Can be empty.
@@ -371,7 +374,7 @@ protected bool CheckEqualityCore(string dir, string name, string nameBase, bool
371374
if (!CheckBaseFile(basePath))
372375
return false;
373376

374-
bool res = CheckEqualityFromPathsCore(relPath, basePath, outPath, digitsOfPrecision: digitsOfPrecision);
377+
bool res = CheckEqualityFromPathsCore(relPath, basePath, outPath, digitsOfPrecision: digitsOfPrecision, parseOption: parseOption);
375378

376379
// No need to keep the raw (unnormalized) output file.
377380
if (normalize && res)
@@ -448,7 +451,8 @@ protected bool CheckOutputIsSuffix(string basePath, string outPath, int skip = 0
448451
}
449452
}
450453

451-
protected bool CheckEqualityFromPathsCore(string relPath, string basePath, string outPath, int skip = 0, int digitsOfPrecision = DigitsOfPrecision)
454+
protected bool CheckEqualityFromPathsCore(string relPath, string basePath, string outPath, int skip = 0,
455+
int digitsOfPrecision = DigitsOfPrecision, NumberParseOption parseOption = NumberParseOption.Default)
452456
{
453457
Contracts.Assert(skip >= 0);
454458

@@ -495,7 +499,7 @@ protected bool CheckEqualityFromPathsCore(string relPath, string basePath, strin
495499
}
496500

497501
count++;
498-
var inRange = GetNumbersFromFile(ref line1, ref line2, digitsOfPrecision);
502+
var inRange = GetNumbersFromFile(ref line1, ref line2, digitsOfPrecision, parseOption);
499503

500504
if (!inRange || line1 != line2)
501505
{
@@ -509,15 +513,15 @@ protected bool CheckEqualityFromPathsCore(string relPath, string basePath, strin
509513
}
510514
}
511515

512-
private bool GetNumbersFromFile(ref string firstString, ref string secondString, int digitsOfPrecision)
516+
private bool GetNumbersFromFile(ref string firstString, ref string secondString,
517+
int digitsOfPrecision, NumberParseOption parseOption)
513518
{
514-
515519
MatchCollection firstCollection = MatchNumbers.Matches(firstString);
516520
MatchCollection secondCollection = MatchNumbers.Matches(secondString);
517521

518522
if (firstCollection.Count == secondCollection.Count)
519523
{
520-
if (!MatchNumberWithTolerance(firstCollection, secondCollection, digitsOfPrecision))
524+
if (!MatchNumberWithTolerance(firstCollection, secondCollection, digitsOfPrecision, parseOption))
521525
{
522526
return false;
523527
}
@@ -528,18 +532,39 @@ private bool GetNumbersFromFile(ref string firstString, ref string secondString,
528532
return true;
529533
}
530534

531-
private bool MatchNumberWithTolerance(MatchCollection firstCollection, MatchCollection secondCollection, int digitsOfPrecision)
535+
private bool MatchNumberWithTolerance(MatchCollection firstCollection, MatchCollection secondCollection,
536+
int digitsOfPrecision, NumberParseOption parseOption)
532537
{
533-
for (int i = 0; i < firstCollection.Count; i++)
538+
if (parseOption == NumberParseOption.UseSingle)
534539
{
535-
double f1 = double.Parse(firstCollection[i].ToString());
536-
double f2 = double.Parse(secondCollection[i].ToString());
540+
for (int i = 0; i < firstCollection.Count; i++)
541+
{
542+
float f1 = float.Parse(firstCollection[i].ToString());
543+
float f2 = float.Parse(secondCollection[i].ToString());
537544

538-
if (!CompareNumbersWithTolerance(f1, f2, i, digitsOfPrecision))
545+
if (!CompareNumbersWithTolerance(f1, f2, i, digitsOfPrecision))
546+
{
547+
return false;
548+
}
549+
}
550+
}
551+
else if (parseOption == NumberParseOption.UseDouble)
552+
{
553+
for (int i = 0; i < firstCollection.Count; i++)
539554
{
540-
return false;
555+
double f1 = double.Parse(firstCollection[i].ToString());
556+
double f2 = double.Parse(secondCollection[i].ToString());
557+
558+
if (!CompareNumbersWithTolerance(f1, f2, i, digitsOfPrecision))
559+
{
560+
return false;
561+
}
541562
}
542563
}
564+
else
565+
{
566+
throw new ArgumentException($"Invalid {nameof(NumberParseOption)}", nameof(parseOption));
567+
}
543568

544569
return true;
545570
}
@@ -811,6 +836,13 @@ protected int MainForTest(string args)
811836
{
812837
return Maml.MainCore(ML, args, false);
813838
}
839+
840+
public enum NumberParseOption
841+
{
842+
Default = UseDouble,
843+
UseSingle = 1,
844+
UseDouble = 2,
845+
}
814846
}
815847

816848
public partial class TestBaselineNormalize : BaseTestBaseline

test/Microsoft.ML.TestFramework/BaseTestPredictorsMaml.cs

+21-16
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public TestImpl(RunContextBase ctx) :
9191
/// <summary>
9292
/// Run the predictor with given args and check if it adds up
9393
/// </summary>
94-
protected void Run(RunContext ctx, int digitsOfPrecision = DigitsOfPrecision)
94+
protected void Run(RunContext ctx, int digitsOfPrecision = DigitsOfPrecision, NumberParseOption parseOption = NumberParseOption.Default)
9595
{
9696
Contracts.Assert(IsActive);
9797
List<string> args = new List<string>();
@@ -164,8 +164,8 @@ protected void Run(RunContext ctx, int digitsOfPrecision = DigitsOfPrecision)
164164
return;
165165
}
166166
var consOutPath = ctx.StdoutPath();
167-
TestCore(ctx, ctx.Command.ToString(), runcmd, digitsOfPrecision: digitsOfPrecision);
168-
bool matched = consOutPath.CheckEqualityNormalized(digitsOfPrecision);
167+
TestCore(ctx, ctx.Command.ToString(), runcmd, digitsOfPrecision: digitsOfPrecision, parseOption: parseOption);
168+
bool matched = consOutPath.CheckEqualityNormalized(digitsOfPrecision, parseOption: parseOption);
169169

170170
if (modelPath != null && (ctx.Summary || ctx.SaveAsIni))
171171
{
@@ -191,7 +191,7 @@ protected void Run(RunContext ctx, int digitsOfPrecision = DigitsOfPrecision)
191191
}
192192

193193
MainForTest(_env, LogWriter, str);
194-
files.ForEach(file => CheckEqualityNormalized(dir, file, digitsOfPrecision: digitsOfPrecision));
194+
files.ForEach(file => CheckEqualityNormalized(dir, file, digitsOfPrecision: digitsOfPrecision, parseOption: parseOption));
195195
}
196196

197197
if (ctx.Command == Cmd.Train || ctx.Command == Cmd.Test || ctx.ExpectedToFail)
@@ -209,12 +209,12 @@ protected void Run(RunContext ctx, int digitsOfPrecision = DigitsOfPrecision)
209209

210210
// Run result processor on the console output.
211211
RunResultProcessorTest(new string[] { consOutPath.Path }, rpOutPath, rpArgs);
212-
CheckEqualityNormalized(dir, rpName, digitsOfPrecision:digitsOfPrecision);
212+
CheckEqualityNormalized(dir, rpName, digitsOfPrecision:digitsOfPrecision, parseOption: parseOption);
213213
}
214214

215215
// Check the prediction output against its baseline.
216216
Contracts.Assert(predOutPath != null);
217-
predOutPath.CheckEquality(digitsOfPrecision: digitsOfPrecision);
217+
predOutPath.CheckEquality(digitsOfPrecision: digitsOfPrecision, parseOption: parseOption);
218218

219219
if (ctx.Command == Cmd.TrainTest)
220220
{
@@ -257,7 +257,7 @@ protected void Run(RunContext ctx, int digitsOfPrecision = DigitsOfPrecision)
257257
// Redirect output to the individual log and run the test.
258258
var ctx2 = ctx.TestCtx();
259259
OutputPath consOutPath2 = ctx2.StdoutPath();
260-
TestCore(ctx2, "Test", runcmd, digitsOfPrecision:digitsOfPrecision);
260+
TestCore(ctx2, "Test", runcmd, digitsOfPrecision, parseOption);
261261

262262
if (CheckTestOutputMatchesTrainTest(consOutPath.Path, consOutPath2.Path, 1))
263263
File.Delete(consOutPath2.Path);
@@ -339,25 +339,27 @@ public string GetLoaderTransformSettings(TestDataset dataset)
339339
/// </summary>
340340
protected void RunAllTests(
341341
IList<PredictorAndArgs> predictors, IList<TestDataset> datasets,
342-
string[] extraSettings = null, string extraTag = "", bool summary = false, int digitsOfPrecision = DigitsOfPrecision)
342+
string[] extraSettings = null, string extraTag = "", bool summary = false,
343+
int digitsOfPrecision = DigitsOfPrecision, NumberParseOption parseOption = NumberParseOption.Default)
343344
{
344345
Contracts.Assert(IsActive);
345346
foreach (TestDataset dataset in datasets)
346347
{
347348
foreach (PredictorAndArgs predictor in predictors)
348-
RunOneAllTests(predictor, dataset, extraSettings, extraTag, summary, digitsOfPrecision);
349+
RunOneAllTests(predictor, dataset, extraSettings, extraTag, summary, digitsOfPrecision, parseOption);
349350
}
350351
}
351352

352353
/// <summary>
353354
/// Run TrainTest, CV, and TrainSaveTest for a single predictor on a single dataset.
354355
/// </summary>
355356
protected void RunOneAllTests(PredictorAndArgs predictor, TestDataset dataset,
356-
string[] extraSettings = null, string extraTag = "", bool summary = false, int digitsOfPrecision = DigitsOfPrecision)
357+
string[] extraSettings = null, string extraTag = "", bool summary = false,
358+
int digitsOfPrecision = DigitsOfPrecision, NumberParseOption parseOption = NumberParseOption.Default)
357359
{
358360
Contracts.Assert(IsActive);
359-
Run_TrainTest(predictor, dataset, extraSettings, extraTag, summary: summary, digitsOfPrecision: digitsOfPrecision);
360-
Run_CV(predictor, dataset, extraSettings, extraTag, useTest: true, digitsOfPrecision: digitsOfPrecision);
361+
Run_TrainTest(predictor, dataset, extraSettings, extraTag, summary: summary, digitsOfPrecision: digitsOfPrecision, parseOption: parseOption);
362+
Run_CV(predictor, dataset, extraSettings, extraTag, useTest: true, digitsOfPrecision: digitsOfPrecision, parseOption: parseOption);
361363
}
362364

363365
/// <summary>
@@ -385,10 +387,12 @@ protected RunContext Run_Train(PredictorAndArgs predictor, TestDataset dataset,
385387
/// Run a train-test unit test
386388
/// </summary>
387389
protected void Run_TrainTest(PredictorAndArgs predictor, TestDataset dataset,
388-
string[] extraSettings = null, string extraTag = "", bool expectFailure = false, bool summary = false, bool saveAsIni = false, int digitsOfPrecision = DigitsOfPrecision)
390+
string[] extraSettings = null, string extraTag = "", bool expectFailure = false, bool summary = false,
391+
bool saveAsIni = false, int digitsOfPrecision = DigitsOfPrecision,
392+
NumberParseOption parseOption = NumberParseOption.Default)
389393
{
390394
RunContext ctx = new RunContext(this, Cmd.TrainTest, predictor, dataset, extraSettings, extraTag, expectFailure: expectFailure, summary: summary, saveAsIni: saveAsIni);
391-
Run(ctx, digitsOfPrecision);
395+
Run(ctx, digitsOfPrecision, parseOption);
392396
}
393397

394398
// REVIEW: Remove TrainSaveTest and supporting code.
@@ -423,7 +427,8 @@ protected void Run_Test(PredictorAndArgs predictor, TestDataset dataset, string
423427
/// <paramref name="useTest"/> is set.
424428
/// </summary>
425429
protected void Run_CV(PredictorAndArgs predictor, TestDataset dataset,
426-
string[] extraSettings = null, string extraTag = "", bool useTest = false, int digitsOfPrecision = DigitsOfPrecision)
430+
string[] extraSettings = null, string extraTag = "", bool useTest = false,
431+
int digitsOfPrecision = DigitsOfPrecision, NumberParseOption parseOption = NumberParseOption.Default)
427432
{
428433
if (useTest)
429434
{
@@ -433,7 +438,7 @@ protected void Run_CV(PredictorAndArgs predictor, TestDataset dataset,
433438
dataset.trainFilename = dataset.testFilename;
434439
}
435440
RunContext cvCtx = new RunContext(this, Cmd.CV, predictor, dataset, extraSettings, extraTag);
436-
Run(cvCtx, digitsOfPrecision);
441+
Run(cvCtx, digitsOfPrecision, parseOption);
437442
}
438443

439444
/// <summary>

0 commit comments

Comments
 (0)