Skip to content

Commit 1f90f50

Browse files
authored
In the public surface area, all occurrences of Argument keyword replaced with Options (#2563)
* inital commit. all tests pass locally * review comments * more renamings * review comments * update to latest master
1 parent 2223d3f commit 1f90f50

File tree

104 files changed

+719
-719
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+719
-719
lines changed

docs/samples/Microsoft.ML.Samples/Dynamic/Calibrator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static void Example()
2828
var mlContext = new MLContext();
2929

3030
// Create a text loader.
31-
var reader = mlContext.Data.CreateTextLoader(new TextLoader.Arguments()
31+
var reader = mlContext.Data.CreateTextLoader(new TextLoader.Options()
3232
{
3333
Separators = new[] { '\t' },
3434
HasHeader = true,

docs/samples/Microsoft.ML.Samples/Dynamic/ImageAnalytics/ConvertToGrayScale.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static void Example()
2323
// hotdog.jpg hotdog
2424
// tomato.jpg tomato
2525

26-
var data = mlContext.Data.CreateTextLoader(new TextLoader.Arguments()
26+
var data = mlContext.Data.CreateTextLoader(new TextLoader.Options()
2727
{
2828
Columns = new[]
2929
{

docs/samples/Microsoft.ML.Samples/Dynamic/ImageAnalytics/ExtractPixels.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static void Example()
2424
// hotdog.jpg hotdog
2525
// tomato.jpg tomato
2626

27-
var data = mlContext.Data.CreateTextLoader(new TextLoader.Arguments()
27+
var data = mlContext.Data.CreateTextLoader(new TextLoader.Options()
2828
{
2929
Columns = new[]
3030
{

docs/samples/Microsoft.ML.Samples/Dynamic/ImageAnalytics/LoadImages.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static void Example()
2323
// hotdog.jpg hotdog
2424
// tomato.jpg tomato
2525

26-
var data = mlContext.Data.CreateTextLoader(new TextLoader.Arguments()
26+
var data = mlContext.Data.CreateTextLoader(new TextLoader.Options()
2727
{
2828
Columns = new[]
2929
{

docs/samples/Microsoft.ML.Samples/Dynamic/ImageAnalytics/ResizeImages.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static void Example()
2323
// hotdog.jpg hotdog
2424
// tomato.jpg tomato
2525

26-
var data = mlContext.Data.CreateTextLoader(new TextLoader.Arguments()
26+
var data = mlContext.Data.CreateTextLoader(new TextLoader.Options()
2727
{
2828
Columns = new[]
2929
{

docs/samples/Microsoft.ML.Samples/Dynamic/LogisticRegression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static void Example()
3131
// 14. Column: native-country (text/categorical)
3232
// 15. Column: Column [Label]: IsOver50K (boolean)
3333

34-
var reader = ml.Data.CreateTextLoader(new TextLoader.Arguments
34+
var reader = ml.Data.CreateTextLoader(new TextLoader.Options
3535
{
3636
Separators = new[] { ',' },
3737
HasHeader = true,

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static void Example()
2424
// Define the trainer options.
2525
var options = new AveragedPerceptronTrainer.Options()
2626
{
27-
LossFunction = new SmoothedHingeLoss.Arguments(),
27+
LossFunction = new SmoothedHingeLoss.Options(),
2828
LearningRate = 0.1f,
2929
DoLazyUpdates = false,
3030
RecencyGain = 0.1f,

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Regression/OrdinaryLeastSquares.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void Example()
2222
// The data is tab separated with all numeric columns.
2323
// The first column being the label and rest are numeric features
2424
// Here only seven numeric columns are used as features
25-
var dataView = mlContext.Data.ReadFromTextFile(dataFile, new TextLoader.Arguments
25+
var dataView = mlContext.Data.ReadFromTextFile(dataFile, new TextLoader.Options
2626
{
2727
Separators = new[] { '\t' },
2828
HasHeader = true,

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Regression/OrdinaryLeastSquaresWithOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static void Example()
2323
// The data is tab separated with all numeric columns.
2424
// The first column being the label and rest are numeric features
2525
// Here only seven numeric columns are used as features
26-
var dataView = mlContext.Data.ReadFromTextFile(dataFile, new TextLoader.Arguments
26+
var dataView = mlContext.Data.ReadFromTextFile(dataFile, new TextLoader.Options
2727
{
2828
Separators = new[] { '\t' },
2929
HasHeader = true,

src/Microsoft.ML.Data/Commands/DataCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,11 @@ protected IDataLoader CreateRawLoader(
364364
var isBinary = string.Equals(ext, ".idv", StringComparison.OrdinalIgnoreCase);
365365
var isTranspose = string.Equals(ext, ".tdv", StringComparison.OrdinalIgnoreCase);
366366

367-
return isText ? TextLoader.Create(Host, new TextLoader.Arguments(), fileSource) :
367+
return isText ? TextLoader.Create(Host, new TextLoader.Options(), fileSource) :
368368
isBinary ? new BinaryLoader(Host, new BinaryLoader.Arguments(), fileSource) :
369369
isTranspose ? new TransposeLoader(Host, new TransposeLoader.Arguments(), fileSource) :
370370
defaultLoaderFactory != null ? defaultLoaderFactory(Host, fileSource) :
371-
TextLoader.Create(Host, new TextLoader.Arguments(), fileSource);
371+
TextLoader.Create(Host, new TextLoader.Options(), fileSource);
372372
}
373373
else
374374
{

src/Microsoft.ML.Data/DataLoadSave/Text/TextLoader.cs

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
using Microsoft.ML.Model;
1616
using Float = System.Single;
1717

18-
[assembly: LoadableClass(TextLoader.Summary, typeof(IDataLoader), typeof(TextLoader), typeof(TextLoader.Arguments), typeof(SignatureDataLoader),
18+
[assembly: LoadableClass(TextLoader.Summary, typeof(IDataLoader), typeof(TextLoader), typeof(TextLoader.Options), typeof(SignatureDataLoader),
1919
"Text Loader", "TextLoader", "Text", DocName = "loader/TextLoader.md")]
2020

2121
[assembly: LoadableClass(TextLoader.Summary, typeof(IDataLoader), typeof(TextLoader), null, typeof(SignatureLoadDataLoader),
@@ -379,7 +379,7 @@ public bool IsValid()
379379
}
380380
}
381381

382-
public sealed class Arguments : ArgumentsCore
382+
public sealed class Options : ArgumentsCore
383383
{
384384
[Argument(ArgumentType.AtMostOnce, HelpText = "Use separate parsing threads?", ShortName = "threads", Hide = true)]
385385
public bool UseThreads = true;
@@ -936,7 +936,7 @@ private static VersionInfo GetVersionInfo()
936936
/// bumping the version number.
937937
/// </summary>
938938
[Flags]
939-
private enum Options : uint
939+
private enum OptionFlags : uint
940940
{
941941
TrimWhitespace = 0x01,
942942
HasHeader = 0x02,
@@ -950,7 +950,7 @@ private enum Options : uint
950950
private const int SrcLim = int.MaxValue;
951951

952952
private readonly bool _useThreads;
953-
private readonly Options _flags;
953+
private readonly OptionFlags _flags;
954954
private readonly long _maxRows;
955955
// Input size is zero for unknown - determined by the data (including sparse rows).
956956
private readonly int _inputSize;
@@ -961,7 +961,7 @@ private enum Options : uint
961961

962962
private bool HasHeader
963963
{
964-
get { return (_flags & Options.HasHeader) != 0; }
964+
get { return (_flags & OptionFlags.HasHeader) != 0; }
965965
}
966966

967967
private readonly IHost _host;
@@ -980,38 +980,38 @@ public TextLoader(IHostEnvironment env, Column[] columns, bool hasHeader = false
980980
{
981981
}
982982

983-
private static Arguments MakeArgs(Column[] columns, bool hasHeader, char[] separatorChars)
983+
private static Options MakeArgs(Column[] columns, bool hasHeader, char[] separatorChars)
984984
{
985985
Contracts.AssertValue(separatorChars);
986-
var result = new Arguments { Columns = columns, HasHeader = hasHeader, Separators = separatorChars};
986+
var result = new Options { Columns = columns, HasHeader = hasHeader, Separators = separatorChars};
987987
return result;
988988
}
989989

990990
/// <summary>
991991
/// Loads a text file into an <see cref="IDataView"/>. Supports basic mapping from input columns to IDataView columns.
992992
/// </summary>
993993
/// <param name="env">The environment to use.</param>
994-
/// <param name="args">Defines the settings of the load operation.</param>
994+
/// <param name="options">Defines the settings of the load operation.</param>
995995
/// <param name="dataSample">Allows to expose items that can be used for reading.</param>
996-
public TextLoader(IHostEnvironment env, Arguments args = null, IMultiStreamSource dataSample = null)
996+
public TextLoader(IHostEnvironment env, Options options = null, IMultiStreamSource dataSample = null)
997997
{
998-
args = args ?? new Arguments();
998+
options = options ?? new Options();
999999

10001000
Contracts.CheckValue(env, nameof(env));
10011001
_host = env.Register(RegistrationName);
1002-
_host.CheckValue(args, nameof(args));
1002+
_host.CheckValue(options, nameof(options));
10031003
_host.CheckValueOrNull(dataSample);
10041004

10051005
if (dataSample == null)
10061006
dataSample = new MultiFileSource(null);
10071007

10081008
IMultiStreamSource headerFile = null;
1009-
if (!string.IsNullOrWhiteSpace(args.HeaderFile))
1010-
headerFile = new MultiFileSource(args.HeaderFile);
1009+
if (!string.IsNullOrWhiteSpace(options.HeaderFile))
1010+
headerFile = new MultiFileSource(options.HeaderFile);
10111011

1012-
var cols = args.Columns;
1012+
var cols = options.Columns;
10131013
bool error;
1014-
if (Utils.Size(cols) == 0 && !TryParseSchema(_host, headerFile ?? dataSample, ref args, out cols, out error))
1014+
if (Utils.Size(cols) == 0 && !TryParseSchema(_host, headerFile ?? dataSample, ref options, out cols, out error))
10151015
{
10161016
if (error)
10171017
throw _host.Except("TextLoader options embedded in the file are invalid");
@@ -1026,43 +1026,43 @@ public TextLoader(IHostEnvironment env, Arguments args = null, IMultiStreamSourc
10261026
}
10271027
_host.Assert(Utils.Size(cols) > 0);
10281028

1029-
_useThreads = args.UseThreads;
1029+
_useThreads = options.UseThreads;
10301030

1031-
if (args.TrimWhitespace)
1032-
_flags |= Options.TrimWhitespace;
1033-
if (headerFile == null && args.HasHeader)
1034-
_flags |= Options.HasHeader;
1035-
if (args.AllowQuoting)
1036-
_flags |= Options.AllowQuoting;
1037-
if (args.AllowSparse)
1038-
_flags |= Options.AllowSparse;
1031+
if (options.TrimWhitespace)
1032+
_flags |= OptionFlags.TrimWhitespace;
1033+
if (headerFile == null && options.HasHeader)
1034+
_flags |= OptionFlags.HasHeader;
1035+
if (options.AllowQuoting)
1036+
_flags |= OptionFlags.AllowQuoting;
1037+
if (options.AllowSparse)
1038+
_flags |= OptionFlags.AllowSparse;
10391039

10401040
// REVIEW: This should be persisted (if it should be maintained).
1041-
_maxRows = args.MaxRows ?? long.MaxValue;
1042-
_host.CheckUserArg(_maxRows >= 0, nameof(args.MaxRows));
1041+
_maxRows = options.MaxRows ?? long.MaxValue;
1042+
_host.CheckUserArg(_maxRows >= 0, nameof(options.MaxRows));
10431043

10441044
// Note that _maxDim == 0 means sparsity is illegal.
1045-
_inputSize = args.InputSize ?? 0;
1045+
_inputSize = options.InputSize ?? 0;
10461046
_host.Check(_inputSize >= 0, "inputSize");
10471047
if (_inputSize >= SrcLim)
10481048
_inputSize = SrcLim - 1;
10491049

1050-
_host.CheckNonEmpty(args.Separator, nameof(args.Separator), "Must specify a separator");
1050+
_host.CheckNonEmpty(options.Separator, nameof(options.Separator), "Must specify a separator");
10511051

10521052
//Default arg.Separator is tab and default args.Separators is also a '\t'.
10531053
//At a time only one default can be different and whichever is different that will
10541054
//be used.
1055-
if (args.Separators.Length > 1 || args.Separators[0] != '\t')
1055+
if (options.Separators.Length > 1 || options.Separators[0] != '\t')
10561056
{
10571057
var separators = new HashSet<char>();
1058-
foreach (char c in args.Separators)
1058+
foreach (char c in options.Separators)
10591059
separators.Add(NormalizeSeparator(c.ToString()));
10601060

10611061
_separators = separators.ToArray();
10621062
}
10631063
else
10641064
{
1065-
string sep = args.Separator.ToLowerInvariant();
1065+
string sep = options.Separator.ToLowerInvariant();
10661066
if (sep == ",")
10671067
_separators = new char[] { ',' };
10681068
else
@@ -1103,7 +1103,7 @@ private char NormalizeSeparator(string sep)
11031103
return ',';
11041104
case "colon":
11051105
case ":":
1106-
_host.CheckUserArg((_flags & Options.AllowSparse) == 0, nameof(Arguments.Separator),
1106+
_host.CheckUserArg((_flags & OptionFlags.AllowSparse) == 0, nameof(Options.Separator),
11071107
"When the separator is colon, turn off allowSparse");
11081108
return ':';
11091109
case "semicolon":
@@ -1115,7 +1115,7 @@ private char NormalizeSeparator(string sep)
11151115
default:
11161116
char ch = sep[0];
11171117
if (sep.Length != 1 || ch < ' ' || '0' <= ch && ch <= '9' || ch == '"')
1118-
throw _host.ExceptUserArg(nameof(Arguments.Separator), "Illegal separator: '{0}'", sep);
1118+
throw _host.ExceptUserArg(nameof(Options.Separator), "Illegal separator: '{0}'", sep);
11191119
return sep[0];
11201120
}
11211121
}
@@ -1134,7 +1134,7 @@ private sealed class LoaderHolder
11341134
// If so, update args and set cols to the combined set of columns.
11351135
// If not, set error to true if there was an error condition.
11361136
private static bool TryParseSchema(IHost host, IMultiStreamSource files,
1137-
ref Arguments args, out Column[] cols, out bool error)
1137+
ref Options options, out Column[] cols, out bool error)
11381138
{
11391139
host.AssertValue(host);
11401140
host.AssertValue(files);
@@ -1144,7 +1144,7 @@ private static bool TryParseSchema(IHost host, IMultiStreamSource files,
11441144

11451145
// Verify that the current schema-defining arguments are default.
11461146
// Get settings just for core arguments, not everything.
1147-
string tmp = CmdParser.GetSettings(host, args, new ArgumentsCore());
1147+
string tmp = CmdParser.GetSettings(host, options, new ArgumentsCore());
11481148

11491149
// Try to get the schema information from the file.
11501150
string str = Cursor.GetEmbeddedArgs(files);
@@ -1176,12 +1176,12 @@ private static bool TryParseSchema(IHost host, IMultiStreamSource files,
11761176

11771177
// Make sure the loader binds to us.
11781178
var info = host.ComponentCatalog.GetLoadableClassInfo<SignatureDataLoader>(loader.Name);
1179-
if (info.Type != typeof(IDataLoader) || info.ArgType != typeof(Arguments))
1179+
if (info.Type != typeof(IDataLoader) || info.ArgType != typeof(Options))
11801180
goto LDone;
11811181

1182-
var argsNew = new Arguments();
1182+
var argsNew = new Options();
11831183
// Copy the non-core arguments to the new args (we already know that all the core arguments are default).
1184-
var parsed = CmdParser.ParseArguments(host, CmdParser.GetSettings(host, args, new Arguments()), argsNew);
1184+
var parsed = CmdParser.ParseArguments(host, CmdParser.GetSettings(host, options, new Options()), argsNew);
11851185
ch.Assert(parsed);
11861186
// Copy the core arguments to the new args.
11871187
if (!CmdParser.ParseArguments(host, loader.GetSettingsString(), argsNew, typeof(ArgumentsCore), msg => ch.Error(msg)))
@@ -1192,7 +1192,7 @@ private static bool TryParseSchema(IHost host, IMultiStreamSource files,
11921192
goto LDone;
11931193

11941194
error = false;
1195-
args = argsNew;
1195+
options = argsNew;
11961196

11971197
LDone:
11981198
return !error;
@@ -1202,16 +1202,16 @@ private static bool TryParseSchema(IHost host, IMultiStreamSource files,
12021202
/// <summary>
12031203
/// Checks whether the source contains the valid TextLoader.Arguments depiction.
12041204
/// </summary>
1205-
public static bool FileContainsValidSchema(IHostEnvironment env, IMultiStreamSource files, out Arguments args)
1205+
public static bool FileContainsValidSchema(IHostEnvironment env, IMultiStreamSource files, out Options options)
12061206
{
12071207
Contracts.CheckValue(env, nameof(env));
12081208
var h = env.Register(RegistrationName);
12091209
h.CheckValue(files, nameof(files));
1210-
args = new Arguments();
1210+
options = new Options();
12111211
Column[] cols;
12121212
bool error;
1213-
bool found = TryParseSchema(h, files, ref args, out cols, out error);
1214-
return found && !error && args.IsValid();
1213+
bool found = TryParseSchema(h, files, ref options, out cols, out error);
1214+
return found && !error && options.IsValid();
12151215
}
12161216

12171217
private TextLoader(IHost host, ModelLoadContext ctx)
@@ -1236,8 +1236,8 @@ private TextLoader(IHost host, ModelLoadContext ctx)
12361236
host.CheckDecode(cbFloat == sizeof(Float));
12371237
_maxRows = ctx.Reader.ReadInt64();
12381238
host.CheckDecode(_maxRows > 0);
1239-
_flags = (Options)ctx.Reader.ReadUInt32();
1240-
host.CheckDecode((_flags & ~Options.All) == 0);
1239+
_flags = (OptionFlags)ctx.Reader.ReadUInt32();
1240+
host.CheckDecode((_flags & ~OptionFlags.All) == 0);
12411241
_inputSize = ctx.Reader.ReadInt32();
12421242
host.CheckDecode(0 <= _inputSize && _inputSize < SrcLim);
12431243

@@ -1253,7 +1253,7 @@ private TextLoader(IHost host, ModelLoadContext ctx)
12531253
}
12541254

12551255
if (_separators.Contains(':'))
1256-
host.CheckDecode((_flags & Options.AllowSparse) == 0);
1256+
host.CheckDecode((_flags & OptionFlags.AllowSparse) == 0);
12571257

12581258
_bindings = new Bindings(ctx, this);
12591259
_parser = new Parser(this);
@@ -1273,14 +1273,14 @@ internal static TextLoader Create(IHostEnvironment env, ModelLoadContext ctx)
12731273
// These are legacy constructors needed for ComponentCatalog.
12741274
internal static IDataLoader Create(IHostEnvironment env, ModelLoadContext ctx, IMultiStreamSource files)
12751275
=> (IDataLoader)Create(env, ctx).Read(files);
1276-
internal static IDataLoader Create(IHostEnvironment env, Arguments args, IMultiStreamSource files)
1277-
=> (IDataLoader)new TextLoader(env, args, files).Read(files);
1276+
internal static IDataLoader Create(IHostEnvironment env, Options options, IMultiStreamSource files)
1277+
=> (IDataLoader)new TextLoader(env, options, files).Read(files);
12781278

12791279
/// <summary>
12801280
/// Convenience method to create a <see cref="TextLoader"/> and use it to read a specified file.
12811281
/// </summary>
1282-
internal static IDataView ReadFile(IHostEnvironment env, Arguments args, IMultiStreamSource fileSource)
1283-
=> new TextLoader(env, args, fileSource).Read(fileSource);
1282+
internal static IDataView ReadFile(IHostEnvironment env, Options options, IMultiStreamSource fileSource)
1283+
=> new TextLoader(env, options, fileSource).Read(fileSource);
12841284

12851285
void ICanSaveModel.Save(ModelSaveContext ctx)
12861286
{
@@ -1298,7 +1298,7 @@ void ICanSaveModel.Save(ModelSaveContext ctx)
12981298
// bindings
12991299
ctx.Writer.Write(sizeof(Float));
13001300
ctx.Writer.Write(_maxRows);
1301-
_host.Assert((_flags & ~Options.All) == 0);
1301+
_host.Assert((_flags & ~OptionFlags.All) == 0);
13021302
ctx.Writer.Write((uint)_flags);
13031303
_host.Assert(0 <= _inputSize && _inputSize < SrcLim);
13041304
ctx.Writer.Write(_inputSize);
@@ -1367,7 +1367,7 @@ internal static TextLoader CreateTextReader<TInput>(IHostEnvironment host,
13671367
columns.Add(column);
13681368
}
13691369

1370-
Arguments args = new Arguments
1370+
Options options = new Options
13711371
{
13721372
HasHeader = hasHeader,
13731373
Separators = new[] { separator },
@@ -1377,7 +1377,7 @@ internal static TextLoader CreateTextReader<TInput>(IHostEnvironment host,
13771377
Columns = columns.ToArray()
13781378
};
13791379

1380-
return new TextLoader(host, args);
1380+
return new TextLoader(host, options);
13811381
}
13821382

13831383
private sealed class BoundLoader : IDataLoader

0 commit comments

Comments
 (0)