Skip to content

In the public surface area, all occurrences of Argument keyword replaced with Options #2563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/samples/Microsoft.ML.Samples/Dynamic/Calibrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void Example()
var mlContext = new MLContext();

// Create a text loader.
var reader = mlContext.Data.CreateTextLoader(new TextLoader.Arguments()
var reader = mlContext.Data.CreateTextLoader(new TextLoader.Options()
{
Separators = new[] { '\t' },
HasHeader = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void Example()
// hotdog.jpg hotdog
// tomato.jpg tomato

var data = mlContext.Data.CreateTextLoader(new TextLoader.Arguments()
var data = mlContext.Data.CreateTextLoader(new TextLoader.Options()
{
Columns = new[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void Example()
// hotdog.jpg hotdog
// tomato.jpg tomato

var data = mlContext.Data.CreateTextLoader(new TextLoader.Arguments()
var data = mlContext.Data.CreateTextLoader(new TextLoader.Options()
{
Columns = new[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void Example()
// hotdog.jpg hotdog
// tomato.jpg tomato

var data = mlContext.Data.CreateTextLoader(new TextLoader.Arguments()
var data = mlContext.Data.CreateTextLoader(new TextLoader.Options()
{
Columns = new[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void Example()
// hotdog.jpg hotdog
// tomato.jpg tomato

var data = mlContext.Data.CreateTextLoader(new TextLoader.Arguments()
var data = mlContext.Data.CreateTextLoader(new TextLoader.Options()
{
Columns = new[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void Example()
// 14. Column: native-country (text/categorical)
// 15. Column: Column [Label]: IsOver50K (boolean)

var reader = ml.Data.CreateTextLoader(new TextLoader.Arguments
var reader = ml.Data.CreateTextLoader(new TextLoader.Options
{
Separators = new[] { ',' },
HasHeader = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void Example()
// Define the trainer options.
var options = new AveragedPerceptronTrainer.Options()
{
LossFunction = new SmoothedHingeLoss.Arguments(),
LossFunction = new SmoothedHingeLoss.Options(),
LearningRate = 0.1f,
DoLazyUpdates = false,
RecencyGain = 0.1f,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void Example()
// The data is tab separated with all numeric columns.
// The first column being the label and rest are numeric features
// Here only seven numeric columns are used as features
var dataView = mlContext.Data.ReadFromTextFile(dataFile, new TextLoader.Arguments
var dataView = mlContext.Data.ReadFromTextFile(dataFile, new TextLoader.Options
{
Separators = new[] { '\t' },
HasHeader = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void Example()
// The data is tab separated with all numeric columns.
// The first column being the label and rest are numeric features
// Here only seven numeric columns are used as features
var dataView = mlContext.Data.ReadFromTextFile(dataFile, new TextLoader.Arguments
var dataView = mlContext.Data.ReadFromTextFile(dataFile, new TextLoader.Options
{
Separators = new[] { '\t' },
HasHeader = true,
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.ML.Data/Commands/DataCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,11 @@ protected IDataLoader CreateRawLoader(
var isBinary = string.Equals(ext, ".idv", StringComparison.OrdinalIgnoreCase);
var isTranspose = string.Equals(ext, ".tdv", StringComparison.OrdinalIgnoreCase);

return isText ? TextLoader.Create(Host, new TextLoader.Arguments(), fileSource) :
return isText ? TextLoader.Create(Host, new TextLoader.Options(), fileSource) :
isBinary ? new BinaryLoader(Host, new BinaryLoader.Arguments(), fileSource) :
isTranspose ? new TransposeLoader(Host, new TransposeLoader.Arguments(), fileSource) :
defaultLoaderFactory != null ? defaultLoaderFactory(Host, fileSource) :
TextLoader.Create(Host, new TextLoader.Arguments(), fileSource);
TextLoader.Create(Host, new TextLoader.Options(), fileSource);
}
else
{
Expand Down
106 changes: 53 additions & 53 deletions src/Microsoft.ML.Data/DataLoadSave/Text/TextLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using Microsoft.ML.Model;
using Float = System.Single;

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

[assembly: LoadableClass(TextLoader.Summary, typeof(IDataLoader), typeof(TextLoader), null, typeof(SignatureLoadDataLoader),
Expand Down Expand Up @@ -379,7 +379,7 @@ public bool IsValid()
}
}

public sealed class Arguments : ArgumentsCore
public sealed class Options : ArgumentsCore
{
[Argument(ArgumentType.AtMostOnce, HelpText = "Use separate parsing threads?", ShortName = "threads", Hide = true)]
public bool UseThreads = true;
Expand Down Expand Up @@ -936,7 +936,7 @@ private static VersionInfo GetVersionInfo()
/// bumping the version number.
/// </summary>
[Flags]
private enum Options : uint
private enum OptionFlags : uint
{
TrimWhitespace = 0x01,
HasHeader = 0x02,
Expand All @@ -950,7 +950,7 @@ private enum Options : uint
private const int SrcLim = int.MaxValue;

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

private bool HasHeader
{
get { return (_flags & Options.HasHeader) != 0; }
get { return (_flags & OptionFlags.HasHeader) != 0; }
}

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

private static Arguments MakeArgs(Column[] columns, bool hasHeader, char[] separatorChars)
private static Options MakeArgs(Column[] columns, bool hasHeader, char[] separatorChars)
{
Contracts.AssertValue(separatorChars);
var result = new Arguments { Columns = columns, HasHeader = hasHeader, Separators = separatorChars};
var result = new Options { Columns = columns, HasHeader = hasHeader, Separators = separatorChars};
return result;
}

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

Contracts.CheckValue(env, nameof(env));
_host = env.Register(RegistrationName);
_host.CheckValue(args, nameof(args));
_host.CheckValue(options, nameof(options));
_host.CheckValueOrNull(dataSample);

if (dataSample == null)
dataSample = new MultiFileSource(null);

IMultiStreamSource headerFile = null;
if (!string.IsNullOrWhiteSpace(args.HeaderFile))
headerFile = new MultiFileSource(args.HeaderFile);
if (!string.IsNullOrWhiteSpace(options.HeaderFile))
headerFile = new MultiFileSource(options.HeaderFile);

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

_useThreads = args.UseThreads;
_useThreads = options.UseThreads;

if (args.TrimWhitespace)
_flags |= Options.TrimWhitespace;
if (headerFile == null && args.HasHeader)
_flags |= Options.HasHeader;
if (args.AllowQuoting)
_flags |= Options.AllowQuoting;
if (args.AllowSparse)
_flags |= Options.AllowSparse;
if (options.TrimWhitespace)
_flags |= OptionFlags.TrimWhitespace;
if (headerFile == null && options.HasHeader)
_flags |= OptionFlags.HasHeader;
if (options.AllowQuoting)
_flags |= OptionFlags.AllowQuoting;
if (options.AllowSparse)
_flags |= OptionFlags.AllowSparse;

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

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

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

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

_separators = separators.ToArray();
}
else
{
string sep = args.Separator.ToLowerInvariant();
string sep = options.Separator.ToLowerInvariant();
if (sep == ",")
_separators = new char[] { ',' };
else
Expand Down Expand Up @@ -1103,7 +1103,7 @@ private char NormalizeSeparator(string sep)
return ',';
case "colon":
case ":":
_host.CheckUserArg((_flags & Options.AllowSparse) == 0, nameof(Arguments.Separator),
_host.CheckUserArg((_flags & OptionFlags.AllowSparse) == 0, nameof(Options.Separator),
"When the separator is colon, turn off allowSparse");
return ':';
case "semicolon":
Expand All @@ -1115,7 +1115,7 @@ private char NormalizeSeparator(string sep)
default:
char ch = sep[0];
if (sep.Length != 1 || ch < ' ' || '0' <= ch && ch <= '9' || ch == '"')
throw _host.ExceptUserArg(nameof(Arguments.Separator), "Illegal separator: '{0}'", sep);
throw _host.ExceptUserArg(nameof(Options.Separator), "Illegal separator: '{0}'", sep);
return sep[0];
}
}
Expand All @@ -1134,7 +1134,7 @@ private sealed class LoaderHolder
// If so, update args and set cols to the combined set of columns.
// If not, set error to true if there was an error condition.
private static bool TryParseSchema(IHost host, IMultiStreamSource files,
ref Arguments args, out Column[] cols, out bool error)
ref Options options, out Column[] cols, out bool error)
{
host.AssertValue(host);
host.AssertValue(files);
Expand All @@ -1144,7 +1144,7 @@ private static bool TryParseSchema(IHost host, IMultiStreamSource files,

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

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

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

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

error = false;
args = argsNew;
options = argsNew;

LDone:
return !error;
Expand All @@ -1202,16 +1202,16 @@ private static bool TryParseSchema(IHost host, IMultiStreamSource files,
/// <summary>
/// Checks whether the source contains the valid TextLoader.Arguments depiction.
/// </summary>
public static bool FileContainsValidSchema(IHostEnvironment env, IMultiStreamSource files, out Arguments args)
public static bool FileContainsValidSchema(IHostEnvironment env, IMultiStreamSource files, out Options options)
{
Contracts.CheckValue(env, nameof(env));
var h = env.Register(RegistrationName);
h.CheckValue(files, nameof(files));
args = new Arguments();
options = new Options();
Column[] cols;
bool error;
bool found = TryParseSchema(h, files, ref args, out cols, out error);
return found && !error && args.IsValid();
bool found = TryParseSchema(h, files, ref options, out cols, out error);
return found && !error && options.IsValid();
}

private TextLoader(IHost host, ModelLoadContext ctx)
Expand All @@ -1236,8 +1236,8 @@ private TextLoader(IHost host, ModelLoadContext ctx)
host.CheckDecode(cbFloat == sizeof(Float));
_maxRows = ctx.Reader.ReadInt64();
host.CheckDecode(_maxRows > 0);
_flags = (Options)ctx.Reader.ReadUInt32();
host.CheckDecode((_flags & ~Options.All) == 0);
_flags = (OptionFlags)ctx.Reader.ReadUInt32();
host.CheckDecode((_flags & ~OptionFlags.All) == 0);
_inputSize = ctx.Reader.ReadInt32();
host.CheckDecode(0 <= _inputSize && _inputSize < SrcLim);

Expand All @@ -1253,7 +1253,7 @@ private TextLoader(IHost host, ModelLoadContext ctx)
}

if (_separators.Contains(':'))
host.CheckDecode((_flags & Options.AllowSparse) == 0);
host.CheckDecode((_flags & OptionFlags.AllowSparse) == 0);

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

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

void ICanSaveModel.Save(ModelSaveContext ctx)
{
Expand All @@ -1298,7 +1298,7 @@ void ICanSaveModel.Save(ModelSaveContext ctx)
// bindings
ctx.Writer.Write(sizeof(Float));
ctx.Writer.Write(_maxRows);
_host.Assert((_flags & ~Options.All) == 0);
_host.Assert((_flags & ~OptionFlags.All) == 0);
ctx.Writer.Write((uint)_flags);
_host.Assert(0 <= _inputSize && _inputSize < SrcLim);
ctx.Writer.Write(_inputSize);
Expand Down Expand Up @@ -1367,7 +1367,7 @@ internal static TextLoader CreateTextReader<TInput>(IHostEnvironment host,
columns.Add(column);
}

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

return new TextLoader(host, args);
return new TextLoader(host, options);
}

private sealed class BoundLoader : IDataLoader
Expand Down
Loading