Skip to content

Commit 9e980a3

Browse files
authored
Merge branch 'dotnet:main' into improvement3
2 parents 7d3e3df + 39235a7 commit 9e980a3

File tree

19 files changed

+1771
-1735
lines changed

19 files changed

+1771
-1735
lines changed

build/libomp.rb

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class Libomp < Formula
1515
end
1616

1717
depends_on "cmake" => :build
18-
depends_on macos: :yosemite
1918

2019
def install
2120
system "cmake", ".", *std_cmake_args

src/Microsoft.Data.Analysis/DataFrame.IO.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -439,14 +439,13 @@ private static DataFrame ReadCsvLinesIntoDataFrame(WrappedStreamReaderOrStringRe
439439

440440
if (addIndexColumn)
441441
{
442-
PrimitiveDataFrameColumn<int> indexColumn = new PrimitiveDataFrameColumn<int>("IndexColumn", columns[0].Length);
443-
for (int i = 0; i < columns[0].Length; i++)
442+
Int64DataFrameColumn indexColumn = new Int64DataFrameColumn("IndexColumn", columns[0].Length);
443+
for (long i = 0; i < columns[0].Length; i++)
444444
{
445445
indexColumn[i] = i;
446446
}
447-
columns.Insert(0, indexColumn);
447+
ret.Columns.Insert(0, indexColumn);
448448
}
449-
450449
}
451450

452451
return ret;

src/Microsoft.ML.AutoML/CodeGen/search-space-schema.json

+24-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@
4646
"BertArchitecture.Roberta"
4747
]
4848
},
49+
"dataKind": {
50+
"type": "string",
51+
"enum": [
52+
"DataKind.Int16",
53+
"DataKind.SByte",
54+
"DataKind.Byte",
55+
"DataKind.UInt16",
56+
"DataKind.Int32",
57+
"DataKind.UInt32",
58+
"DataKind.Int64",
59+
"DataKind.UInt64",
60+
"DataKind.Single",
61+
"DataKind.Double",
62+
"DataKind.String",
63+
"DataKind.Boolean",
64+
"DataKind.TimeSpan",
65+
"DataKind.DateTime",
66+
"DataKind.DateTimeOffset"
67+
]
68+
},
4969
"bertArchitectureArray": {
5070
"type": "array",
5171
"items": {
@@ -217,7 +237,8 @@
217237
"TrainingAnswerColumnName",
218238
"AnswerIndexStartColumnName",
219239
"predictedAnswerColumnName",
220-
"TopKAnswers"
240+
"TopKAnswers",
241+
"TargetType"
221242
]
222243
},
223244
"option_type": {
@@ -235,7 +256,8 @@
235256
"anchor",
236257
"dnnModelFactory",
237258
"bertArchitecture",
238-
"imageClassificationArchType"
259+
"imageClassificationArchType",
260+
"dataKind"
239261
]
240262
}
241263
},

src/Microsoft.ML.AutoML/CodeGen/type_converter_search_space.json

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
{
1010
"name": "InputColumnNames",
1111
"type": "strings"
12+
},
13+
{
14+
"name": "TargetType",
15+
"type": "dataKind",
16+
"default": "DataKind.Single"
1217
}
1318
]
1419
}

src/Microsoft.ML.AutoML/SweepableEstimator/Estimators/TypeConvert.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal partial class ConvertType
99
public override IEstimator<ITransformer> BuildFromOption(MLContext context, ConvertTypeOption param)
1010
{
1111
var inputOutputPairs = AutoMlUtils.CreateInputOutputColumnPairsFromStrings(param.InputColumnNames, param.OutputColumnNames);
12-
return context.Transforms.Conversion.ConvertType(inputOutputPairs);
12+
return context.Transforms.Conversion.ConvertType(inputOutputPairs, param.TargetType);
1313
}
1414
}
1515
}

src/Microsoft.ML.Core/EntryPoints/EntryPointModuleAttribute.cs

+17-18
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,22 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6-
namespace Microsoft.ML.EntryPoints
7-
{
8-
/// <summary>
9-
/// This is a signature for classes that are 'holders' of entry points and components.
10-
/// </summary>
11-
[BestFriend]
12-
internal delegate void SignatureEntryPointModule();
6+
namespace Microsoft.ML.EntryPoints;
7+
8+
/// <summary>
9+
/// This is a signature for classes that are 'holders' of entry points and components.
10+
/// </summary>
11+
[BestFriend]
12+
internal delegate void SignatureEntryPointModule();
1313

14-
/// <summary>
15-
/// A simplified assembly attribute for marking EntryPoint modules.
16-
/// </summary>
17-
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
18-
[BestFriend]
19-
internal sealed class EntryPointModuleAttribute : LoadableClassAttributeBase
20-
{
21-
public EntryPointModuleAttribute(Type loaderType)
22-
: base(null, typeof(void), loaderType, null, new[] { typeof(SignatureEntryPointModule) }, loaderType.FullName)
23-
{ }
24-
}
14+
/// <summary>
15+
/// A simplified assembly attribute for marking EntryPoint modules.
16+
/// </summary>
17+
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
18+
[BestFriend]
19+
internal sealed class EntryPointModuleAttribute : LoadableClassAttributeBase
20+
{
21+
public EntryPointModuleAttribute(Type loaderType)
22+
: base(null, typeof(void), loaderType, null, new[] { typeof(SignatureEntryPointModule) }, loaderType.FullName)
23+
{ }
2524
}

src/Microsoft.ML.Core/EntryPoints/EntryPointUtils.cs

+106-107
Original file line numberDiff line numberDiff line change
@@ -9,127 +9,126 @@
99
using Microsoft.ML.Internal.Utilities;
1010
using Microsoft.ML.Runtime;
1111

12-
namespace Microsoft.ML.EntryPoints
12+
namespace Microsoft.ML.EntryPoints;
13+
14+
[BestFriend]
15+
internal static class EntryPointUtils
1316
{
14-
[BestFriend]
15-
internal static class EntryPointUtils
17+
private static readonly FuncStaticMethodInfo1<TlcModule.RangeAttribute, object, bool> _isValueWithinRangeMethodInfo
18+
= new FuncStaticMethodInfo1<TlcModule.RangeAttribute, object, bool>(IsValueWithinRange<int>);
19+
20+
private static bool IsValueWithinRange<T>(TlcModule.RangeAttribute range, object obj)
1621
{
17-
private static readonly FuncStaticMethodInfo1<TlcModule.RangeAttribute, object, bool> _isValueWithinRangeMethodInfo
18-
= new FuncStaticMethodInfo1<TlcModule.RangeAttribute, object, bool>(IsValueWithinRange<int>);
22+
T val;
23+
if (obj is Optional<T> asOptional)
24+
val = asOptional.Value;
25+
else
26+
val = (T)obj;
1927

20-
private static bool IsValueWithinRange<T>(TlcModule.RangeAttribute range, object obj)
21-
{
22-
T val;
23-
if (obj is Optional<T> asOptional)
24-
val = asOptional.Value;
25-
else
26-
val = (T)obj;
27-
28-
return
29-
(range.Min == null || ((IComparable)range.Min).CompareTo(val) <= 0) &&
30-
(range.Inf == null || ((IComparable)range.Inf).CompareTo(val) < 0) &&
31-
(range.Max == null || ((IComparable)range.Max).CompareTo(val) >= 0) &&
32-
(range.Sup == null || ((IComparable)range.Sup).CompareTo(val) > 0);
33-
}
28+
return
29+
(range.Min == null || ((IComparable)range.Min).CompareTo(val) <= 0) &&
30+
(range.Inf == null || ((IComparable)range.Inf).CompareTo(val) < 0) &&
31+
(range.Max == null || ((IComparable)range.Max).CompareTo(val) >= 0) &&
32+
(range.Sup == null || ((IComparable)range.Sup).CompareTo(val) > 0);
33+
}
3434

35-
public static bool IsValueWithinRange(this TlcModule.RangeAttribute range, object val)
36-
{
37-
Contracts.AssertValue(range);
38-
Contracts.AssertValue(val);
39-
// Avoid trying to cast double as float. If range
40-
// was specified using floats, but value being checked
41-
// is double, change range to be of type double
42-
if (range.Type == typeof(float) && val is double)
43-
range.CastToDouble();
44-
return Utils.MarshalInvoke(_isValueWithinRangeMethodInfo, range.Type, range, val);
45-
}
35+
public static bool IsValueWithinRange(this TlcModule.RangeAttribute range, object val)
36+
{
37+
Contracts.AssertValue(range);
38+
Contracts.AssertValue(val);
39+
// Avoid trying to cast double as float. If range
40+
// was specified using floats, but value being checked
41+
// is double, change range to be of type double
42+
if (range.Type == typeof(float) && val is double)
43+
range.CastToDouble();
44+
return Utils.MarshalInvoke(_isValueWithinRangeMethodInfo, range.Type, range, val);
45+
}
4646

47-
/// <summary>
48-
/// Performs checks on an EntryPoint input class equivalent to the checks that are done
49-
/// when parsing a JSON EntryPoint graph.
50-
///
51-
/// Call this method from EntryPoint methods to ensure that range and required checks are performed
52-
/// in a consistent manner when EntryPoints are created directly from code.
53-
/// </summary>
54-
public static void CheckInputArgs(IExceptionContext ectx, object args)
47+
/// <summary>
48+
/// Performs checks on an EntryPoint input class equivalent to the checks that are done
49+
/// when parsing a JSON EntryPoint graph.
50+
///
51+
/// Call this method from EntryPoint methods to ensure that range and required checks are performed
52+
/// in a consistent manner when EntryPoints are created directly from code.
53+
/// </summary>
54+
public static void CheckInputArgs(IExceptionContext ectx, object args)
55+
{
56+
foreach (var fieldInfo in args.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
5557
{
56-
foreach (var fieldInfo in args.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
57-
{
58-
var attr = fieldInfo.GetCustomAttributes(typeof(ArgumentAttribute), false).FirstOrDefault()
59-
as ArgumentAttribute;
60-
if (attr == null || attr.Visibility == ArgumentAttribute.VisibilityType.CmdLineOnly)
61-
continue;
62-
63-
var fieldVal = fieldInfo.GetValue(args);
64-
var fieldType = fieldInfo.FieldType;
65-
66-
// Optionals are either left in their Implicit constructed state or
67-
// a new Explicit optional is constructed. They should never be set
68-
// to null.
69-
if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Optional<>) && fieldVal == null)
70-
throw ectx.Except("Field '{0}' is Optional<> and set to null instead of an explicit value.", fieldInfo.Name);
71-
72-
if (attr.IsRequired)
73-
{
74-
bool equalToDefault;
75-
if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Optional<>))
76-
equalToDefault = !((Optional)fieldVal).IsExplicit;
77-
else
78-
equalToDefault = fieldType.IsValueType ? Activator.CreateInstance(fieldType).Equals(fieldVal) : fieldVal == null;
79-
80-
if (equalToDefault)
81-
throw ectx.Except("Field '{0}' is required but is not set.", fieldInfo.Name);
82-
}
83-
84-
var rangeAttr = fieldInfo.GetCustomAttributes(typeof(TlcModule.RangeAttribute), false).FirstOrDefault()
85-
as TlcModule.RangeAttribute;
86-
if (rangeAttr != null && fieldVal != null && !rangeAttr.IsValueWithinRange(fieldVal))
87-
throw ectx.Except("Field '{0}' is set to a value that falls outside the range bounds.", fieldInfo.Name);
88-
}
89-
}
58+
var attr = fieldInfo.GetCustomAttributes(typeof(ArgumentAttribute), false).FirstOrDefault()
59+
as ArgumentAttribute;
60+
if (attr == null || attr.Visibility == ArgumentAttribute.VisibilityType.CmdLineOnly)
61+
continue;
9062

91-
public static IHost CheckArgsAndCreateHost(IHostEnvironment env, string hostName, object input)
92-
{
93-
Contracts.CheckValue(env, nameof(env));
94-
var host = env.Register(hostName);
95-
host.CheckValue(input, nameof(input));
96-
CheckInputArgs(host, input);
97-
return host;
98-
}
63+
var fieldVal = fieldInfo.GetValue(args);
64+
var fieldType = fieldInfo.FieldType;
9965

100-
/// <summary>
101-
/// Searches for the given column name in the schema. This method applies a
102-
/// common policy that throws an exception if the column is not found
103-
/// and the column name was explicitly specified. If the column is not found
104-
/// and the column name was not explicitly specified, it returns null.
105-
/// </summary>
106-
public static string FindColumnOrNull(IExceptionContext ectx, DataViewSchema schema, Optional<string> value)
107-
{
108-
Contracts.CheckValueOrNull(ectx);
109-
ectx.CheckValue(schema, nameof(schema));
110-
ectx.CheckValue(value, nameof(value));
66+
// Optionals are either left in their Implicit constructed state or
67+
// a new Explicit optional is constructed. They should never be set
68+
// to null.
69+
if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Optional<>) && fieldVal == null)
70+
throw ectx.Except("Field '{0}' is Optional<> and set to null instead of an explicit value.", fieldInfo.Name);
11171

112-
if (value == "")
113-
return null;
114-
if (schema.GetColumnOrNull(value) == null)
72+
if (attr.IsRequired)
11573
{
116-
if (value.IsExplicit)
117-
throw ectx.Except("Column '{0}' not found", value);
118-
return null;
74+
bool equalToDefault;
75+
if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Optional<>))
76+
equalToDefault = !((Optional)fieldVal).IsExplicit;
77+
else
78+
equalToDefault = fieldType.IsValueType ? Activator.CreateInstance(fieldType).Equals(fieldVal) : fieldVal == null;
79+
80+
if (equalToDefault)
81+
throw ectx.Except("Field '{0}' is required but is not set.", fieldInfo.Name);
11982
}
120-
return value;
83+
84+
var rangeAttr = fieldInfo.GetCustomAttributes(typeof(TlcModule.RangeAttribute), false).FirstOrDefault()
85+
as TlcModule.RangeAttribute;
86+
if (rangeAttr != null && fieldVal != null && !rangeAttr.IsValueWithinRange(fieldVal))
87+
throw ectx.Except("Field '{0}' is set to a value that falls outside the range bounds.", fieldInfo.Name);
12188
}
89+
}
12290

123-
/// <summary>
124-
/// Converts EntryPoint Optional{T} types into nullable types, with the
125-
/// implicit value being converted to the null value.
126-
/// </summary>
127-
public static T? AsNullable<T>(this Optional<T> opt) where T : struct
91+
public static IHost CheckArgsAndCreateHost(IHostEnvironment env, string hostName, object input)
92+
{
93+
Contracts.CheckValue(env, nameof(env));
94+
var host = env.Register(hostName);
95+
host.CheckValue(input, nameof(input));
96+
CheckInputArgs(host, input);
97+
return host;
98+
}
99+
100+
/// <summary>
101+
/// Searches for the given column name in the schema. This method applies a
102+
/// common policy that throws an exception if the column is not found
103+
/// and the column name was explicitly specified. If the column is not found
104+
/// and the column name was not explicitly specified, it returns null.
105+
/// </summary>
106+
public static string FindColumnOrNull(IExceptionContext ectx, DataViewSchema schema, Optional<string> value)
107+
{
108+
Contracts.CheckValueOrNull(ectx);
109+
ectx.CheckValue(schema, nameof(schema));
110+
ectx.CheckValue(value, nameof(value));
111+
112+
if (value == "")
113+
return null;
114+
if (schema.GetColumnOrNull(value) == null)
128115
{
129-
if (opt.IsExplicit)
130-
return opt.Value;
131-
else
132-
return null;
116+
if (value.IsExplicit)
117+
throw ectx.Except("Column '{0}' not found", value);
118+
return null;
133119
}
120+
return value;
121+
}
122+
123+
/// <summary>
124+
/// Converts EntryPoint Optional{T} types into nullable types, with the
125+
/// implicit value being converted to the null value.
126+
/// </summary>
127+
public static T? AsNullable<T>(this Optional<T> opt) where T : struct
128+
{
129+
if (opt.IsExplicit)
130+
return opt.Value;
131+
else
132+
return null;
134133
}
135134
}

0 commit comments

Comments
 (0)