Skip to content

Commit b604b07

Browse files
ganikIvanidzo4ka
authored andcommitted
Mark EntryPoints classes and APIs as internal (#2674)
1 parent ec418e4 commit b604b07

File tree

22 files changed

+120
-134
lines changed

22 files changed

+120
-134
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,8 @@ public static bool IsNumericKind(DataKind kind)
650650
/// <summary>
651651
/// The untyped base class for 'maybe'.
652652
/// </summary>
653-
public abstract class Optional
653+
[BestFriend]
654+
internal abstract class Optional
654655
{
655656
/// <summary>
656657
/// Whether the value was set 'explicitly', or 'implicitly'.
@@ -674,7 +675,8 @@ private protected Optional(bool isExplicit)
674675
/// the weight column to be 'Weight', we need to actually enforce the presence of the column.
675676
/// </summary>
676677
/// <typeparam name="T">The type of the value</typeparam>
677-
public sealed class Optional<T> : Optional
678+
[BestFriend]
679+
internal sealed class Optional<T> : Optional
678680
{
679681
public readonly T Value;
680682

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace Microsoft.ML.EntryPoints
1111
/// <summary>
1212
/// Base type for standard predictor model port type.
1313
/// </summary>
14-
public abstract class PredictorModel
14+
[BestFriend]
15+
internal abstract class PredictorModel
1516
{
1617
[BestFriend]
1718
private protected PredictorModel()

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace Microsoft.ML.EntryPoints
1111
/// <summary>
1212
/// Interface for standard transform model port type.
1313
/// </summary>
14-
public abstract class TransformModel
14+
[BestFriend]
15+
internal abstract class TransformModel
1516
{
1617
[BestFriend]
1718
private protected TransformModel()

src/Microsoft.ML.Data/EntryPoints/EntryPointNode.cs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace Microsoft.ML.EntryPoints
1818
{
19-
public class VarSerializer : JsonConverter
19+
internal class VarSerializer : JsonConverter
2020
{
2121
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
2222
{
@@ -53,7 +53,8 @@ internal interface IVarSerializationHelper
5353
/// in an entry point graph.
5454
/// </summary>
5555
[JsonConverter(typeof(VarSerializer))]
56-
public sealed class Var<T> : IVarSerializationHelper
56+
[BestFriend]
57+
internal sealed class Var<T> : IVarSerializationHelper
5758
{
5859
public string VarName { get; set; }
5960
bool IVarSerializationHelper.IsValue { get; }
@@ -90,7 +91,8 @@ public static bool CheckType(Type type)
9091
/// in an entry point graph.
9192
/// </summary>
9293
[JsonConverter(typeof(VarSerializer))]
93-
public sealed class ArrayVar<T> : IVarSerializationHelper
94+
[BestFriend]
95+
internal sealed class ArrayVar<T> : IVarSerializationHelper
9496
{
9597
public string VarName { get; set; }
9698
private readonly bool _isValue;
@@ -127,7 +129,7 @@ public Var<T> this[int i]
127129
/// in an entry point graph.
128130
/// </summary>
129131
[JsonConverter(typeof(VarSerializer))]
130-
public sealed class DictionaryVar<T> : IVarSerializationHelper
132+
internal sealed class DictionaryVar<T> : IVarSerializationHelper
131133
{
132134
public string VarName { get; set; }
133135
bool IVarSerializationHelper.IsValue { get; }
@@ -153,7 +155,8 @@ public Var<T> this[string key]
153155
/// <summary>
154156
/// A descriptor of one 'variable' of the graph (input or output that is referenced as a $variable in the graph definition).
155157
/// </summary>
156-
public sealed class EntryPointVariable
158+
[BestFriend]
159+
internal sealed class EntryPointVariable
157160
{
158161
private readonly IExceptionContext _ectx;
159162
public readonly string Name;
@@ -257,7 +260,8 @@ public EntryPointVariable Clone(string newName)
257260
/// This is populated by individual nodes when they parse their respective JSON definitions, and then the values are updated
258261
/// during the node execution.
259262
/// </summary>
260-
public sealed class RunContext
263+
[BestFriend]
264+
internal sealed class RunContext
261265
{
262266
private readonly Dictionary<string, EntryPointVariable> _vars;
263267
private readonly IExceptionContext _ectx;
@@ -404,7 +408,8 @@ public EntryPointVariable CreateTempOutputVar<T>(string varPrefix)
404408
/// <summary>
405409
/// A representation of one graph node.
406410
/// </summary>
407-
public sealed class EntryPointNode
411+
[BestFriend]
412+
internal sealed class EntryPointNode
408413
{
409414
// The unique node ID, generated at compilation.
410415
public readonly string Id;
@@ -983,7 +988,8 @@ public Tuple<Var<T>, VariableBinding> AddNewVariable<T>(string uniqueName, T val
983988
}
984989
}
985990

986-
public sealed class EntryPointGraph
991+
[BestFriend]
992+
internal sealed class EntryPointGraph
987993
{
988994
private const string RegistrationName = "EntryPointGraph";
989995
private readonly IHost _host;
@@ -1049,7 +1055,8 @@ public void AddNode(EntryPointNode node)
10491055
/// or a array-indexed or dictionary-keyed value from the variable, assuming it is
10501056
/// of an Array or Dictionary type.
10511057
/// </summary>
1052-
public abstract class VariableBinding
1058+
[BestFriend]
1059+
internal abstract class VariableBinding
10531060
{
10541061
public string VariableName { get; private set; }
10551062

@@ -1124,7 +1131,8 @@ public void Rename(string newName)
11241131
public override string ToString() => VariableName;
11251132
}
11261133

1127-
public sealed class SimpleVariableBinding
1134+
[BestFriend]
1135+
internal sealed class SimpleVariableBinding
11281136
: VariableBinding
11291137
{
11301138
public SimpleVariableBinding(string name)
@@ -1143,7 +1151,7 @@ public override string ToJson()
11431151
}
11441152
}
11451153

1146-
public sealed class DictionaryKeyVariableBinding
1154+
internal sealed class DictionaryKeyVariableBinding
11471155
: VariableBinding
11481156
{
11491157
public readonly string Key;
@@ -1168,7 +1176,8 @@ public override string ToJson()
11681176
}
11691177
}
11701178

1171-
public sealed class ArrayIndexVariableBinding
1179+
[BestFriend]
1180+
internal sealed class ArrayIndexVariableBinding
11721181
: VariableBinding
11731182
{
11741183
public readonly int Index;
@@ -1199,7 +1208,8 @@ public override string ToJson()
11991208
/// of a yet-to-be-constructed array or dictionary EntryPoint input parameter
12001209
/// (for example, "myVar": ["$var1", "$var2"] would yield two <see cref="ArrayIndexParameterBinding"/>: (myVar, 0), (myVar, 1))
12011210
/// </summary>
1202-
public abstract class ParameterBinding
1211+
[BestFriend]
1212+
internal abstract class ParameterBinding
12031213
{
12041214
public readonly string ParameterName;
12051215

@@ -1212,7 +1222,8 @@ protected ParameterBinding(string name)
12121222
public override string ToString() => ParameterName;
12131223
}
12141224

1215-
public sealed class SimpleParameterBinding
1225+
[BestFriend]
1226+
internal sealed class SimpleParameterBinding
12161227
: ParameterBinding
12171228
{
12181229
public SimpleParameterBinding(string name)
@@ -1233,7 +1244,7 @@ public override int GetHashCode()
12331244
}
12341245
}
12351246

1236-
public sealed class DictionaryKeyParameterBinding
1247+
internal sealed class DictionaryKeyParameterBinding
12371248
: ParameterBinding
12381249
{
12391250
public readonly string Key;
@@ -1261,7 +1272,8 @@ public override int GetHashCode()
12611272
}
12621273
}
12631274

1264-
public sealed class ArrayIndexParameterBinding
1275+
[BestFriend]
1276+
internal sealed class ArrayIndexParameterBinding
12651277
: ParameterBinding
12661278
{
12671279
public readonly int Index;

src/Microsoft.ML.Data/EntryPoints/InputBase.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public abstract class LearnerInputBaseWithWeight : LearnerInputBaseWithLabel
9898
/// Column to use for example weight.
9999
/// </summary>
100100
[Argument(ArgumentType.AtMostOnce, HelpText = "Column to use for example weight", ShortName = "weight", SortOrder = 4, Visibility = ArgumentAttribute.VisibilityType.EntryPointsOnly)]
101-
public Optional<string> WeightColumn = Optional<string>.Implicit(DefaultColumnNames.Weight);
101+
public string WeightColumn = null;
102102
}
103103

104104
/// <summary>
@@ -111,7 +111,7 @@ public abstract class UnsupervisedLearnerInputBaseWithWeight : LearnerInputBase
111111
/// Column to use for example weight.
112112
/// </summary>
113113
[Argument(ArgumentType.AtMostOnce, HelpText = "Column to use for example weight", ShortName = "weight", SortOrder = 4, Visibility = ArgumentAttribute.VisibilityType.EntryPointsOnly)]
114-
public Optional<string> WeightColumn = Optional<string>.Implicit(DefaultColumnNames.Weight);
114+
public string WeightColumn = null;
115115
}
116116

117117
/// <summary>
@@ -133,8 +133,8 @@ public abstract class LearnerInputBaseWithGroupId : LearnerInputBaseWithWeight
133133
/// <summary>
134134
/// Column to use for example groupId.
135135
/// </summary>
136-
[Argument(ArgumentType.AtMostOnce, HelpText = "Column to use for example groupId", ShortName = "groupId", SortOrder = 5, Visibility = ArgumentAttribute.VisibilityType.EntryPointsOnly)]
137-
public Optional<string> GroupIdColumn = Optional<string>.Implicit(DefaultColumnNames.GroupId);
136+
[Argument(ArgumentType.AtMostOnce, Name = "GroupIdColumn", HelpText = "Column to use for example groupId", ShortName = "groupId", SortOrder = 5, Visibility = ArgumentAttribute.VisibilityType.EntryPointsOnly)]
137+
public string GroupIdColumn = null;
138138
}
139139

140140
[BestFriend]
@@ -275,23 +275,23 @@ public interface ITrainerInputWithLabel : ITrainerInput
275275
/// </summary>
276276
public interface IUnsupervisedTrainerWithWeight : ITrainerInput
277277
{
278-
Optional<string> WeightColumn { get; }
278+
string WeightColumn { get; }
279279
}
280280

281281
/// <summary>
282282
/// Interface that all API trainer input classes will implement.
283283
/// </summary>
284284
public interface ITrainerInputWithWeight : ITrainerInputWithLabel
285285
{
286-
Optional<string> WeightColumn { get; }
286+
string WeightColumn { get; }
287287
}
288288

289289
/// <summary>
290290
/// Interface that all API trainer input classes will implement.
291291
/// </summary>
292292
public interface ITrainerInputWithGroupId : ITrainerInputWithWeight
293293
{
294-
Optional<string> GroupIdColumn { get; }
294+
string GroupIdColumn { get; }
295295
}
296296

297297
/// <summary>

src/Microsoft.ML.Data/EntryPoints/InputBuilder.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Microsoft.ML.EntryPoints.JsonUtils
1818
/// required values. The values can be set from their JSON representation (during the graph parsing stage), as well as directly
1919
/// (in the process of graph execution).
2020
/// </summary>
21-
public sealed class InputBuilder
21+
internal sealed class InputBuilder
2222
{
2323
private readonly struct Attributes
2424
{
@@ -646,7 +646,7 @@ public object GetInstance()
646646
/// This class wraps around the output object type, does not create an instance, and provides utility methods for field type checking
647647
/// and extracting values.
648648
/// </summary>
649-
public sealed class OutputHelper
649+
internal sealed class OutputHelper
650650
{
651651
private readonly IExceptionContext _ectx;
652652
private readonly Type _type;
@@ -736,7 +736,8 @@ public JObject GetJsonObject(Dictionary<string, string> outputMap)
736736
/// <summary>
737737
/// These are the common field names used in the JSON objects for defining the manifest.
738738
/// </summary>
739-
public static class FieldNames
739+
[BestFriend]
740+
internal static class FieldNames
740741
{
741742
public const string Nodes = "Nodes";
742743
public const string Kind = "Kind";

src/Microsoft.ML.Data/Training/TrainerUtils.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -389,17 +389,6 @@ public static SchemaShape.Column MakeR4ScalarWeightColumn(string weightColumn)
389389
return new SchemaShape.Column(weightColumn, SchemaShape.Column.VectorKind.Scalar, NumberDataViewType.Single, false);
390390
}
391391

392-
/// <summary>
393-
/// The <see cref="SchemaShape.Column"/> for the weight column.
394-
/// </summary>
395-
/// <param name="weightColumn">name of the weight column</param>
396-
public static SchemaShape.Column MakeR4ScalarWeightColumn(Optional<string> weightColumn)
397-
{
398-
if (weightColumn == null || weightColumn.Value == null || !weightColumn.IsExplicit)
399-
return default;
400-
return new SchemaShape.Column(weightColumn, SchemaShape.Column.VectorKind.Scalar, NumberDataViewType.Single, false);
401-
}
402-
403392
/// <summary>
404393
/// This is a shim class to translate the more contemporaneous <see cref="ITrainerEstimator{TTransformer, TPredictor}"/>
405394
/// style transformers into the older now disfavored <see cref="ITrainer{TPredictor}"/> idiom, for components that still

src/Microsoft.ML.FastTree/FastTree.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,8 @@ private protected FastTreeTrainerBase(IHostEnvironment env,
124124

125125
FastTreeTrainerOptions.LabelColumn = label.Name;
126126
FastTreeTrainerOptions.FeatureColumn = featureColumn;
127-
128-
if (weightColumn != null)
129-
FastTreeTrainerOptions.WeightColumn = Optional<string>.Explicit(weightColumn);
130-
131-
if (groupIdColumn != null)
132-
FastTreeTrainerOptions.GroupIdColumn = Optional<string>.Explicit(groupIdColumn);
127+
FastTreeTrainerOptions.WeightColumn = weightColumn;
128+
FastTreeTrainerOptions.GroupIdColumn = groupIdColumn;
133129

134130
// The discretization step renders this trainer non-parametric, and therefore it does not need normalization.
135131
// Also since it builds its own internal discretized columnar structures, it cannot benefit from caching.

src/Microsoft.ML.HalLearners/HalLearnersCatalog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static OlsLinearRegressionTrainer OrdinaryLeastSquares(this RegressionCat
3939
{
4040
LabelColumn = labelColumnName,
4141
FeatureColumn = featureColumnName,
42-
WeightColumn = weightColumn != null ? Optional<string>.Explicit(weightColumn) : Optional<string>.Implicit(DefaultColumnNames.Weight)
42+
WeightColumn = weightColumn
4343
};
4444

4545
return new OlsLinearRegressionTrainer(env, options);

src/Microsoft.ML.KMeansClustering/KMeansCatalog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static KMeansPlusPlusTrainer KMeans(this ClusteringCatalog.ClusteringTrai
3838
var options = new KMeansPlusPlusTrainer.Options
3939
{
4040
FeatureColumn = featureColumn,
41-
WeightColumn = weights != null ? Optional<string>.Explicit(weights) : Optional<string>.Implicit(DefaultColumnNames.Weight),
41+
WeightColumn = weights,
4242
ClustersCount = clustersCount
4343
};
4444
return new KMeansPlusPlusTrainer(env, options);

0 commit comments

Comments
 (0)