Skip to content

Commit 8553b85

Browse files
committed
Merged from Master
2 parents e3d7845 + fc7286c commit 8553b85

File tree

12 files changed

+63
-88
lines changed

12 files changed

+63
-88
lines changed

Microsoft.ML.sln

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.Console", "src
108108
EndProject
109109
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.Sweeper.Tests", "test\Microsoft.ML.Sweeper.Tests\Microsoft.ML.Sweeper.Tests.csproj", "{3DEB504D-7A07-48CE-91A2-8047461CB3D4}"
110110
EndProject
111+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{487213C9-E8A9-4F94-85D7-28A05DBBFE3A}"
112+
EndProject
113+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "netstandard2.0", "netstandard2.0", "{9252A8EB-ABFB-440C-AB4D-1D562753CE0F}"
114+
ProjectSection(SolutionItems) = preProject
115+
pkg\Microsoft.ML\build\netstandard2.0\Microsoft.ML.props = pkg\Microsoft.ML\build\netstandard2.0\Microsoft.ML.props
116+
pkg\Microsoft.ML\build\netstandard2.0\Microsoft.ML.targets = pkg\Microsoft.ML\build\netstandard2.0\Microsoft.ML.targets
117+
EndProjectSection
118+
EndProject
111119
Global
112120
GlobalSection(SolutionConfigurationPlatforms) = preSolution
113121
Debug|Any CPU = Debug|Any CPU
@@ -250,6 +258,8 @@ Global
250258
{64F40A0D-D4C2-4AA7-8470-E9CC437827E4} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
251259
{362A98CF-FBF7-4EBB-A11B-990BBF845B15} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
252260
{3DEB504D-7A07-48CE-91A2-8047461CB3D4} = {AED9C836-31E3-4F3F-8ABC-929555D3F3C4}
261+
{487213C9-E8A9-4F94-85D7-28A05DBBFE3A} = {DEC8F776-49F7-4D87-836C-FE4DC057D08C}
262+
{9252A8EB-ABFB-440C-AB4D-1D562753CE0F} = {487213C9-E8A9-4F94-85D7-28A05DBBFE3A}
253263
EndGlobalSection
254264
GlobalSection(ExtensibilityGlobals) = postSolution
255265
SolutionGuid = {41165AF1-35BB-4832-A189-73060F82B01D}

pkg/Microsoft.ML/build/Microsoft.ML.props renamed to pkg/Microsoft.ML/build/netstandard2.0/Microsoft.ML.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<ItemGroup Condition="Exists('packages.config') OR
88
Exists('$(MSBuildProjectName).packages.config') OR
99
Exists('packages.$(MSBuildProjectName).config')">
10-
<Content Include="$(MSBuildThisFileDirectory)\..\runtimes\win-x64\native\*.dll"
10+
<Content Include="$(MSBuildThisFileDirectory)\..\..\runtimes\win-x64\native\*.dll"
1111
Condition="'$(PlatformTarget)' == 'x64'">
1212
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1313
<Visible>false</Visible>

src/Microsoft.ML.Core/Utilities/HybridMemoryStream.cs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,24 @@ public sealed class HybridMemoryStream : Stream
1919
{
2020
private MemoryStream _memStream;
2121
private Stream _overflowStream;
22-
private string _overflowPath;
2322
private readonly int _overflowBoundary;
2423
private const int _defaultMaxLen = 1 << 30;
2524

2625
private bool _disposed;
2726

28-
private Stream MyStream { get { return _memStream ?? _overflowStream; } }
27+
private Stream MyStream => _memStream ?? _overflowStream;
2928

30-
private bool IsMemory { get { return _memStream != null; } }
29+
private bool IsMemory => _memStream != null;
3130

32-
public override long Position
33-
{
34-
get { return MyStream.Position; }
35-
set { Seek(value, SeekOrigin.Begin); }
31+
public override long Position {
32+
get => MyStream.Position;
33+
set => Seek(value, SeekOrigin.Begin);
3634
}
3735

38-
public override long Length { get { return MyStream.Length; } }
39-
public override bool CanWrite { get { return MyStream.CanWrite; } }
40-
public override bool CanSeek { get { return MyStream.CanSeek; } }
41-
public override bool CanRead { get { return MyStream.CanRead; } }
36+
public override long Length => MyStream.Length;
37+
public override bool CanWrite => MyStream.CanWrite;
38+
public override bool CanSeek => MyStream.CanSeek;
39+
public override bool CanRead => MyStream.CanRead;
4240

4341
/// <summary>
4442
/// Constructs an initially empty read-write stream. Once the number of
@@ -123,27 +121,24 @@ protected override void Dispose(bool disposing)
123121
var overflow = _overflowStream;
124122
_overflowStream = null;
125123
overflow.Dispose();
126-
Contracts.AssertValue(_overflowPath);
127-
File.Delete(_overflowPath);
128-
_overflowPath = null;
129124
}
130125
_disposed = true;
131126
AssertInvariants();
127+
base.Dispose(disposing);
132128
}
133129
}
134130

135131
public override void Close()
136132
{
137133
AssertInvariants();
138-
if (MyStream != null)
139-
MyStream.Close();
134+
// The base Stream class Close will call Dispose(bool).
135+
base.Close();
140136
}
141137

142138
public override void Flush()
143139
{
144140
AssertInvariants();
145-
if (MyStream != null)
146-
MyStream.Flush();
141+
MyStream?.Flush();
147142
AssertInvariants();
148143
}
149144

@@ -164,9 +159,9 @@ private void EnsureOverflow()
164159
// been closed.
165160
Contracts.Check(_memStream.CanRead, "attempt to perform operation on closed stream");
166161

167-
Contracts.Assert(_overflowPath == null);
168-
_overflowPath = Path.GetTempFileName();
169-
_overflowStream = new FileStream(_overflowPath, FileMode.Open, FileAccess.ReadWrite);
162+
string overflowPath = Path.GetTempFileName();
163+
_overflowStream = new FileStream(overflowPath, FileMode.Open, FileAccess.ReadWrite,
164+
FileShare.None, bufferSize: 4096, FileOptions.DeleteOnClose);
170165

171166
// The documentation is not clear on this point, but the source code for
172167
// memory stream makes clear that this buffer is exposable for a memory

src/Microsoft.ML.Core/Utilities/TextReaderStream.cs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Microsoft.ML.Runtime.Internal.Utilities
1414
/// compensates by inserting <c>\n</c> line feed characters at the end of every
1515
/// input line, including the last one.
1616
/// </summary>
17-
public class TextReaderStream : Stream
17+
public sealed class TextReaderStream : Stream
1818
{
1919
private readonly TextReader _baseReader;
2020
private readonly Encoding _encoding;
@@ -38,19 +38,11 @@ public class TextReaderStream : Stream
3838
public override bool CanWrite => false;
3939

4040
public override long Length
41-
{
42-
get
43-
{
44-
throw Contracts.ExceptNotSupp("Stream cannot determine length.");
45-
}
46-
}
41+
=> throw Contracts.ExceptNotSupp("Stream cannot determine length.");
4742

4843
public override long Position
4944
{
50-
get
51-
{
52-
return _position;
53-
}
45+
get => _position;
5446
set
5547
{
5648
if (value != Position)
@@ -96,6 +88,7 @@ public override void Close()
9688
protected override void Dispose(bool disposing)
9789
{
9890
_baseReader.Dispose();
91+
base.Dispose(disposing);
9992
}
10093

10194
public override void Flush()
@@ -182,18 +175,12 @@ public override int ReadByte()
182175
}
183176

184177
public override long Seek(long offset, SeekOrigin origin)
185-
{
186-
throw Contracts.ExceptNotSupp("Stream cannot seek.");
187-
}
178+
=> throw Contracts.ExceptNotSupp("Stream cannot seek.");
188179

189180
public override void Write(byte[] buffer, int offset, int count)
190-
{
191-
throw Contracts.ExceptNotSupp("Stream is not writable.");
192-
}
181+
=> throw Contracts.ExceptNotSupp("Stream is not writable.");
193182

194183
public override void SetLength(long value)
195-
{
196-
throw Contracts.ExceptNotSupp("Stream is not writable.");
197-
}
184+
=> throw Contracts.ExceptNotSupp("Stream is not writable.");
198185
}
199186
}

src/Microsoft.ML.Transforms/NAReplaceTransform.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public enum ReplacementKind
4343
Mean,
4444
Minimum,
4545
Maximum,
46+
SpecifiedValue,
4647

4748
[HideEnumValue]
4849
Def = DefaultValue,
@@ -53,8 +54,6 @@ public enum ReplacementKind
5354
[HideEnumValue]
5455
Max = Maximum,
5556

56-
[HideEnumValue]
57-
SpecifiedValue,
5857
[HideEnumValue]
5958
Val = SpecifiedValue,
6059
[HideEnumValue]

src/Microsoft.ML/CSharpApi.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11058,14 +11058,10 @@ namespace Transforms
1105811058
{
1105911059
public enum NAHandleTransformReplacementKind
1106011060
{
11061-
Default = 0,
11062-
Def = 0,
1106311061
DefaultValue = 0,
1106411062
Mean = 1,
1106511063
Minimum = 2,
11066-
Min = 2,
11067-
Maximum = 3,
11068-
Max = 3
11064+
Maximum = 3
1106911065
}
1107011066

1107111067

@@ -11153,7 +11149,7 @@ public void AddColumn(string outputColumn, string inputColumn)
1115311149
/// <summary>
1115411150
/// The replacement method to utilize
1115511151
/// </summary>
11156-
public NAHandleTransformReplacementKind ReplaceWith { get; set; } = NAHandleTransformReplacementKind.Def;
11152+
public NAHandleTransformReplacementKind ReplaceWith { get; set; } = NAHandleTransformReplacementKind.DefaultValue;
1115711153

1115811154
/// <summary>
1115911155
/// Whether to impute values by slot
@@ -11527,17 +11523,11 @@ namespace Transforms
1152711523
{
1152811524
public enum NAReplaceTransformReplacementKind
1152911525
{
11530-
Default = 0,
1153111526
DefaultValue = 0,
11532-
Def = 0,
1153311527
Mean = 1,
11534-
Min = 2,
1153511528
Minimum = 2,
11536-
Max = 3,
1153711529
Maximum = 3,
11538-
SpecifiedValue = 4,
11539-
Val = 4,
11540-
Value = 4
11530+
SpecifiedValue = 4
1154111531
}
1154211532

1154311533

@@ -11625,7 +11615,7 @@ public void AddColumn(string outputColumn, string inputColumn)
1162511615
/// <summary>
1162611616
/// The replacement method to utilize
1162711617
/// </summary>
11628-
public NAReplaceTransformReplacementKind ReplacementKind { get; set; } = NAReplaceTransformReplacementKind.Def;
11618+
public NAReplaceTransformReplacementKind ReplacementKind { get; set; } = NAReplaceTransformReplacementKind.DefaultValue;
1162911619

1163011620
/// <summary>
1163111621
/// Whether to impute values by slot

src/Microsoft.ML/Runtime/EntryPoints/JsonUtils/JsonManifestUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ private static JToken BuildTypeToken(IExceptionContext ectx, FieldInfo fieldInfo
344344
case TlcModule.DataKind.Enum:
345345
jo = new JObject();
346346
jo[FieldNames.Kind] = typeEnum.ToString();
347-
var values = Enum.GetNames(type);
347+
var values = Enum.GetNames(type).Where(n => type.GetField(n).GetCustomAttribute<HideEnumValueAttribute>() == null);
348348
jo[FieldNames.Values] = new JArray(values);
349349
return jo;
350350
case TlcModule.DataKind.Array:

src/Microsoft.ML/Runtime/Internal/Tools/CSharpApiGenerator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Generic;
77
using System.IO;
88
using System.Linq;
9+
using System.Reflection;
910
using Microsoft.ML.Runtime;
1011
using Microsoft.ML.Runtime.CommandLine;
1112
using Microsoft.ML.Runtime.Data;
@@ -156,6 +157,8 @@ private void GenerateEnums(IndentingTextWriter writer, Type inputType, string cu
156157
for (int i = 0; i < names.Length; i++)
157158
{
158159
var name = names[i];
160+
if (type.GetField(name).GetCustomAttribute<HideEnumValueAttribute>() != null)
161+
continue;
159162
var value = values.GetValue(i);
160163
writer.WriteLine(prefix);
161164
if (enumType == typeof(int))

src/Microsoft.ML/Runtime/Internal/Tools/CSharpGeneratorUtils.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.CodeDom;
77
using System.Collections.Generic;
88
using System.Linq;
9+
using System.Reflection;
910
using Microsoft.CSharp;
1011
using Microsoft.ML.Runtime.CommandLine;
1112
using Microsoft.ML.Runtime.EntryPoints;
@@ -279,10 +280,22 @@ public static string GetValue(ModuleCatalog catalog, Type fieldType, object fiel
279280
case TlcModule.DataKind.Bool:
280281
return (bool)fieldValue ? "true" : "false";
281282
case TlcModule.DataKind.Enum:
283+
string enumAsString = fieldValue.ToString();
284+
if (fieldType.GetField(enumAsString).GetCustomAttribute<HideEnumValueAttribute>() != null)
285+
{
286+
// The default value for the enum has the hiding attribute on it. We will search for
287+
// alternate names. Regrettably I see no way beyond a manual scan.
288+
289+
string unhiddenName = Enum.GetNames(fieldType).Zip(Enum.GetValues(fieldType).Cast<object>(), (name, val) => (name, val))
290+
.Where(pair => pair.val.Equals(fieldValue))
291+
.Where(pair => fieldType.GetField(pair.name).GetCustomAttribute<HideEnumValueAttribute>() == null)
292+
.Select(pair => pair.name).FirstOrDefault();
293+
enumAsString = unhiddenName ?? throw Contracts.Except($"Could not find unhidden alternative for '{fieldValue}' in type '{fieldType}'");
294+
}
282295
if (generatedClasses.IsGenerated(fieldType.FullName))
283-
return generatedClasses.GetApiName(fieldType, rootNameSpace) + "." + fieldValue;
296+
return generatedClasses.GetApiName(fieldType, rootNameSpace) + "." + enumAsString;
284297
else
285-
return generatedClasses.GetApiName(fieldType, "Runtime") + "." + fieldValue;
298+
return generatedClasses.GetApiName(fieldType, "Runtime") + "." + enumAsString;
286299
case TlcModule.DataKind.Char:
287300
return $"'{GetCharAsString((char)fieldValue)}'";
288301
case TlcModule.DataKind.Component:

0 commit comments

Comments
 (0)