Skip to content

Commit 9d19d0e

Browse files
Ivanidzo4kajustinormont
authored andcommitted
small code cleanup (#271)
1 parent c259863 commit 9d19d0e

File tree

10 files changed

+41
-46
lines changed

10 files changed

+41
-46
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public sealed class EntryPointInfo
5151
public readonly Type[] OutputKinds;
5252
public readonly ObsoleteAttribute ObsoleteAttribute;
5353

54-
internal EntryPointInfo(IExceptionContext ectx, MethodInfo method,
54+
internal EntryPointInfo(IExceptionContext ectx, MethodInfo method,
5555
TlcModule.EntryPointAttribute attribute, ObsoleteAttribute obsoleteAttribute)
5656
{
5757
Contracts.AssertValueOrNull(ectx);
@@ -187,7 +187,7 @@ private ModuleCatalog(IExceptionContext ectx)
187187
if (attr == null)
188188
continue;
189189

190-
var info = new EntryPointInfo(ectx, methodInfo, attr,
190+
var info = new EntryPointInfo(ectx, methodInfo, attr,
191191
methodInfo.GetCustomAttributes(typeof(ObsoleteAttribute), false).FirstOrDefault() as ObsoleteAttribute);
192192

193193
entryPoints.Add(info);
@@ -315,7 +315,7 @@ public bool TryFindComponent(Type interfaceType, Type argumentType, out Componen
315315
Contracts.CheckParam(interfaceType.IsInterface, nameof(interfaceType), "Must be interface");
316316
Contracts.CheckValue(argumentType, nameof(argumentType));
317317

318-
component = _components.FirstOrDefault(x => x.InterfaceType == interfaceType && x.ArgumentType == argumentType);
318+
component = _components.FirstOrDefault(x => x.InterfaceType == interfaceType && x.ArgumentType == argumentType);
319319
return component != null;
320320
}
321321

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,8 @@ public static Output Score(IHostEnvironment env, Input input)
7272
host.CheckValue(input, nameof(input));
7373
EntryPointUtils.CheckInputArgs(host, input);
7474

75-
76-
IPredictor predictor;
7775
var inputData = input.Data;
78-
RoleMappedData data;
79-
input.PredictorModel.PrepareData(host, inputData, out data, out predictor);
76+
input.PredictorModel.PrepareData(host, inputData, out RoleMappedData data, out IPredictor predictor);
8077

8178
IDataView scoredPipe;
8279
using (var ch = host.Start("Creating scoring pipeline"))

src/Microsoft.ML.PipelineInference/AutoInference.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ private void ProcessPipeline(Sweeper.Algorithms.SweeperProbabilityUtils utils, S
353353
testMetricVal += 1e-10;
354354

355355
// Save performance score
356-
candidate.PerformanceSummary =
356+
candidate.PerformanceSummary =
357357
new RunSummary(testMetricVal, randomizedNumberOfRows, stopwatch.ElapsedMilliseconds, trainMetricVal);
358358
_sortedSampledElements.Add(candidate.PerformanceSummary.MetricValue, candidate);
359359
_history.Add(candidate);

src/Microsoft.ML.PipelineInference/AutoMlUtils.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Microsoft.ML.Runtime.PipelineInference
1515
{
1616
public static class AutoMlUtils
1717
{
18-
public static double ExtractValueFromIDV(IHostEnvironment env, IDataView result, string columnName)
18+
public static double ExtractValueFromIdv(IHostEnvironment env, IDataView result, string columnName)
1919
{
2020
Contracts.CheckValue(env, nameof(env));
2121
env.CheckValue(result, nameof(result));
@@ -40,8 +40,8 @@ public static double ExtractValueFromIDV(IHostEnvironment env, IDataView result,
4040

4141
public static AutoInference.RunSummary ExtractRunSummary(IHostEnvironment env, IDataView result, string metricColumnName, IDataView trainResult = null)
4242
{
43-
double testingMetricValue = ExtractValueFromIDV(env, result, metricColumnName);
44-
double trainingMetricValue = trainResult != null ? ExtractValueFromIDV(env, trainResult, metricColumnName) : double.MinValue;
43+
double testingMetricValue = ExtractValueFromIdv(env, result, metricColumnName);
44+
double trainingMetricValue = trainResult != null ? ExtractValueFromIdv(env, trainResult, metricColumnName) : double.MinValue;
4545
return new AutoInference.RunSummary(testingMetricValue, 0, 0, trainingMetricValue);
4646
}
4747

src/Microsoft.ML.PipelineInference/PipelinePattern.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ public void RunTrainTestExperiment(IDataView trainData, IDataView testData,
213213

214214
var dataOut = experiment.GetOutput(trainTestOutput.OverallMetrics);
215215
var dataOutTraining = experiment.GetOutput(trainTestOutput.TrainingOverallMetrics);
216-
testMetricValue = AutoMlUtils.ExtractValueFromIDV(_env, dataOut, metric.Name);
217-
trainMetricValue = AutoMlUtils.ExtractValueFromIDV(_env, dataOutTraining, metric.Name);
216+
testMetricValue = AutoMlUtils.ExtractValueFromIdv(_env, dataOut, metric.Name);
217+
trainMetricValue = AutoMlUtils.ExtractValueFromIdv(_env, dataOutTraining, metric.Name);
218218
}
219219

220220
public static PipelineResultRow[] ExtractResults(IHostEnvironment env, IDataView data,

src/Microsoft.ML/Runtime/EntryPoints/CrossValidationBinaryMacro.cs

-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ public static ArrayITransformModelOutput MakeArray(IHostEnvironment env, ArrayIT
256256
return result;
257257
}
258258

259-
260259
public sealed class ArrayIDataViewInput
261260
{
262261
[Argument(ArgumentType.Required, HelpText = "The data sets", SortOrder = 1)]

src/Microsoft.ML/Runtime/EntryPoints/CrossValidationMacro.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public sealed class SubGraphOutput
3131
{
3232
[Argument(ArgumentType.AtMostOnce, HelpText = "The predictor model", SortOrder = 1)]
3333
public Var<IPredictorModel> PredictorModel;
34-
34+
3535
[Argument(ArgumentType.AtMostOnce, HelpText = "The transform model", SortOrder = 2)]
3636
public Var<ITransformModel> TransformModel;
3737
}
@@ -104,7 +104,6 @@ public sealed class Output
104104
public IDataView ConfusionMatrix;
105105
}
106106

107-
108107
public sealed class CombineMetricsInput
109108
{
110109
[Argument(ArgumentType.Multiple, HelpText = "Overall metrics datasets", SortOrder = 1)]
@@ -219,7 +218,7 @@ public static CommonOutputs.MacroOutput<Output> CrossValidate(
219218
}
220219
else
221220
args.Outputs.TransformModel = null;
222-
221+
223222
// Set train/test trainer kind to match.
224223
args.Kind = input.Kind;
225224

src/Microsoft.ML/Runtime/EntryPoints/ImportTextData.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static Output TextLoader(IHostEnvironment env, LoaderInput input)
6464
var host = env.Register("ImportTextData");
6565
env.CheckValue(input, nameof(input));
6666
EntryPointUtils.CheckInputArgs(host, input);
67-
var loader = host.CreateLoader(input.Arguments, new FileHandleSource(input.InputFile));
67+
var loader = host.CreateLoader(input.Arguments, new FileHandleSource(input.InputFile));
6868
return new Output { Data = loader };
6969
}
7070
}

src/Microsoft.ML/Runtime/EntryPoints/TrainTestMacro.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public sealed class SubGraphOutput
2626
{
2727
[Argument(ArgumentType.AtMostOnce, HelpText = "The predictor model", SortOrder = 1)]
2828
public Var<IPredictorModel> PredictorModel;
29-
29+
3030
[Argument(ArgumentType.AtMostOnce, HelpText = "Transform model", SortOrder = 2)]
3131
public Var<ITransformModel> TransformModel;
3232
}
@@ -130,7 +130,7 @@ public static CommonOutputs.MacroOutput<Output> TrainTest(
130130
if (!subGraphRunContext.TryGetVariable(varName, out dataVariable))
131131
throw env.Except($"Invalid variable name '{varName}'.");
132132

133-
string outputVarName = input.Outputs.PredictorModel == null ? node.GetOutputVariableName(nameof(Output.TransformModel)) :
133+
string outputVarName = input.Outputs.PredictorModel == null ? node.GetOutputVariableName(nameof(Output.TransformModel)) :
134134
node.GetOutputVariableName(nameof(Output.PredictorModel));
135135

136136
foreach (var subGraphNode in subGraphNodes)
@@ -249,7 +249,7 @@ public static CommonOutputs.MacroOutput<Output> TrainTest(
249249
var evalInputOutputTraining = MacroUtils.GetEvaluatorInputOutput(input.Kind, settings);
250250
var evalNodeTraining = evalInputOutputTraining.Item1;
251251
var evalOutputTraining = evalInputOutputTraining.Item2;
252-
evalNodeTraining.Data.VarName = input.Outputs.PredictorModel == null ? datasetTransformNodeTrainingOutput.OutputData.VarName :
252+
evalNodeTraining.Data.VarName = input.Outputs.PredictorModel == null ? datasetTransformNodeTrainingOutput.OutputData.VarName :
253253
scoreNodeTrainingOutput.ScoredData.VarName;
254254

255255
if (node.OutputMap.TryGetValue(nameof(Output.TrainingWarnings), out outVariableName))

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

+25-25
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ public static string GetJsonFromField(string fieldName, Type fieldType)
408408
private readonly string _regenerate;
409409
private readonly HashSet<string> _excludedSet;
410410
private const string RegistrationName = "CSharpApiGenerator";
411-
public Dictionary<string, string> _typesSymbolTable = new Dictionary<string, string>();
411+
public Dictionary<string, string> TypesSymbolTable = new Dictionary<string, string>();
412412

413413
public CSharpApiGenerator(IHostEnvironment env, Arguments args, string regenerate)
414414
{
@@ -612,7 +612,7 @@ private void GenerateEnums(IndentingTextWriter writer, Type inputType, string cu
612612
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Optional<>))
613613
type = type.GetGenericArguments()[0];
614614

615-
if (_typesSymbolTable.ContainsKey(type.FullName))
615+
if (TypesSymbolTable.ContainsKey(type.FullName))
616616
continue;
617617

618618
if (!type.IsEnum)
@@ -625,13 +625,13 @@ private void GenerateEnums(IndentingTextWriter writer, Type inputType, string cu
625625

626626
var enumType = Enum.GetUnderlyingType(type);
627627

628-
_typesSymbolTable[type.FullName] = GetSymbolFromType(_typesSymbolTable, type, currentNamespace);
628+
TypesSymbolTable[type.FullName] = GetSymbolFromType(TypesSymbolTable, type, currentNamespace);
629629
if (enumType == typeof(int))
630-
writer.WriteLine($"public enum {_typesSymbolTable[type.FullName].Substring(_typesSymbolTable[type.FullName].LastIndexOf('.') + 1)}");
630+
writer.WriteLine($"public enum {TypesSymbolTable[type.FullName].Substring(TypesSymbolTable[type.FullName].LastIndexOf('.') + 1)}");
631631
else
632632
{
633633
Contracts.Assert(enumType == typeof(byte));
634-
writer.WriteLine($"public enum {_typesSymbolTable[type.FullName].Substring(_typesSymbolTable[type.FullName].LastIndexOf('.') + 1)} : byte");
634+
writer.WriteLine($"public enum {TypesSymbolTable[type.FullName].Substring(TypesSymbolTable[type.FullName].LastIndexOf('.') + 1)} : byte");
635635
}
636636

637637
writer.Write("{");
@@ -707,19 +707,19 @@ private void GenerateStructs(IndentingTextWriter writer,
707707
if (typeEnum != TlcModule.DataKind.Unknown)
708708
continue;
709709

710-
if (_typesSymbolTable.ContainsKey(type.FullName))
710+
if (TypesSymbolTable.ContainsKey(type.FullName))
711711
continue;
712712

713-
_typesSymbolTable[type.FullName] = GetSymbolFromType(_typesSymbolTable, type, currentNamespace);
713+
TypesSymbolTable[type.FullName] = GetSymbolFromType(TypesSymbolTable, type, currentNamespace);
714714
string classBase = "";
715715
if (type.IsSubclassOf(typeof(OneToOneColumn)))
716-
classBase = $" : OneToOneColumn<{_typesSymbolTable[type.FullName].Substring(_typesSymbolTable[type.FullName].LastIndexOf('.') + 1)}>, IOneToOneColumn";
716+
classBase = $" : OneToOneColumn<{TypesSymbolTable[type.FullName].Substring(TypesSymbolTable[type.FullName].LastIndexOf('.') + 1)}>, IOneToOneColumn";
717717
else if (type.IsSubclassOf(typeof(ManyToOneColumn)))
718-
classBase = $" : ManyToOneColumn<{_typesSymbolTable[type.FullName].Substring(_typesSymbolTable[type.FullName].LastIndexOf('.') + 1)}>, IManyToOneColumn";
719-
writer.WriteLine($"public sealed partial class {_typesSymbolTable[type.FullName].Substring(_typesSymbolTable[type.FullName].LastIndexOf('.') + 1)}{classBase}");
718+
classBase = $" : ManyToOneColumn<{TypesSymbolTable[type.FullName].Substring(TypesSymbolTable[type.FullName].LastIndexOf('.') + 1)}>, IManyToOneColumn";
719+
writer.WriteLine($"public sealed partial class {TypesSymbolTable[type.FullName].Substring(TypesSymbolTable[type.FullName].LastIndexOf('.') + 1)}{classBase}");
720720
writer.WriteLine("{");
721721
writer.Indent();
722-
GenerateInputFields(writer, type, catalog, _typesSymbolTable);
722+
GenerateInputFields(writer, type, catalog, TypesSymbolTable);
723723
writer.Outdent();
724724
writer.WriteLine("}");
725725
writer.WriteLine();
@@ -858,12 +858,12 @@ private void GenerateColumnAddMethods(IndentingTextWriter writer,
858858
writer.Indent();
859859
if (isArray)
860860
{
861-
writer.WriteLine($"var list = {fieldName} == null ? new List<{_typesSymbolTable[type.FullName]}>() : new List<{_typesSymbolTable[type.FullName]}>({fieldName});");
862-
writer.WriteLine($"list.Add(OneToOneColumn<{_typesSymbolTable[type.FullName]}>.Create(source));");
861+
writer.WriteLine($"var list = {fieldName} == null ? new List<{TypesSymbolTable[type.FullName]}>() : new List<{TypesSymbolTable[type.FullName]}>({fieldName});");
862+
writer.WriteLine($"list.Add(OneToOneColumn<{TypesSymbolTable[type.FullName]}>.Create(source));");
863863
writer.WriteLine($"{fieldName} = list.ToArray();");
864864
}
865865
else
866-
writer.WriteLine($"{fieldName} = OneToOneColumn<{_typesSymbolTable[type.FullName]}>.Create(source);");
866+
writer.WriteLine($"{fieldName} = OneToOneColumn<{TypesSymbolTable[type.FullName]}>.Create(source);");
867867
writer.Outdent();
868868
writer.WriteLine("}");
869869
writer.WriteLine();
@@ -872,12 +872,12 @@ private void GenerateColumnAddMethods(IndentingTextWriter writer,
872872
writer.Indent();
873873
if (isArray)
874874
{
875-
writer.WriteLine($"var list = {fieldName} == null ? new List<{_typesSymbolTable[type.FullName]}>() : new List<{_typesSymbolTable[type.FullName]}>({fieldName});");
876-
writer.WriteLine($"list.Add(OneToOneColumn<{_typesSymbolTable[type.FullName]}>.Create(name, source));");
875+
writer.WriteLine($"var list = {fieldName} == null ? new List<{TypesSymbolTable[type.FullName]}>() : new List<{TypesSymbolTable[type.FullName]}>({fieldName});");
876+
writer.WriteLine($"list.Add(OneToOneColumn<{TypesSymbolTable[type.FullName]}>.Create(name, source));");
877877
writer.WriteLine($"{fieldName} = list.ToArray();");
878878
}
879879
else
880-
writer.WriteLine($"{fieldName} = OneToOneColumn<{_typesSymbolTable[type.FullName]}>.Create(name, source);");
880+
writer.WriteLine($"{fieldName} = OneToOneColumn<{TypesSymbolTable[type.FullName]}>.Create(name, source);");
881881
writer.Outdent();
882882
writer.WriteLine("}");
883883
writer.WriteLine();
@@ -905,12 +905,12 @@ private void GenerateColumnAddMethods(IndentingTextWriter writer,
905905
writer.Indent();
906906
if (isArray)
907907
{
908-
writer.WriteLine($"var list = {fieldName} == null ? new List<{_typesSymbolTable[type.FullName]}>() : new List<{_typesSymbolTable[type.FullName]}>({fieldName});");
909-
writer.WriteLine($"list.Add(ManyToOneColumn<{_typesSymbolTable[type.FullName]}>.Create(name, source));");
908+
writer.WriteLine($"var list = {fieldName} == null ? new List<{TypesSymbolTable[type.FullName]}>() : new List<{TypesSymbolTable[type.FullName]}>({fieldName});");
909+
writer.WriteLine($"list.Add(ManyToOneColumn<{TypesSymbolTable[type.FullName]}>.Create(name, source));");
910910
writer.WriteLine($"{fieldName} = list.ToArray();");
911911
}
912912
else
913-
writer.WriteLine($"{fieldName} = ManyToOneColumn<{_typesSymbolTable[type.FullName]}>.Create(name, source);");
913+
writer.WriteLine($"{fieldName} = ManyToOneColumn<{TypesSymbolTable[type.FullName]}>.Create(name, source);");
914914
writer.Outdent();
915915
writer.WriteLine("}");
916916
writer.WriteLine();
@@ -942,10 +942,10 @@ private void GenerateInput(IndentingTextWriter writer,
942942
foreach (var line in entryPointInfo.Description.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
943943
writer.WriteLine($"/// {line}");
944944
writer.WriteLine("/// </summary>");
945-
946-
if(entryPointInfo.ObsoleteAttribute != null)
945+
946+
if (entryPointInfo.ObsoleteAttribute != null)
947947
writer.WriteLine($"[Obsolete(\"{entryPointInfo.ObsoleteAttribute.Message}\")]");
948-
948+
949949
writer.WriteLine($"public sealed partial class {classAndMethod.Item2}{classBase}");
950950
writer.WriteLine("{");
951951
writer.Indent();
@@ -955,7 +955,7 @@ private void GenerateInput(IndentingTextWriter writer,
955955

956956
GenerateColumnAddMethods(writer, entryPointInfo.InputType, catalog, classAndMethod.Item2, out Type transformType);
957957
writer.WriteLine();
958-
GenerateInputFields(writer, entryPointInfo.InputType, catalog, _typesSymbolTable);
958+
GenerateInputFields(writer, entryPointInfo.InputType, catalog, TypesSymbolTable);
959959
writer.WriteLine();
960960

961961
GenerateOutput(writer, entryPointInfo, out HashSet<string> outputVariableNames);
@@ -1191,7 +1191,7 @@ private void GenerateComponent(IndentingTextWriter writer, ModuleCatalog.Compone
11911191
writer.WriteLine($"public sealed class {GeneratorUtils.GetComponentName(component)} : {component.Kind}");
11921192
writer.WriteLine("{");
11931193
writer.Indent();
1194-
GenerateInputFields(writer, component.ArgumentType, catalog, _typesSymbolTable, "Microsoft.ML.");
1194+
GenerateInputFields(writer, component.ArgumentType, catalog, TypesSymbolTable, "Microsoft.ML.");
11951195
writer.WriteLine($"internal override string ComponentName => \"{component.Name}\";");
11961196
writer.Outdent();
11971197
writer.WriteLine("}");

0 commit comments

Comments
 (0)