Skip to content
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

Make Create constructors private and handle that in ComponentCatalog. #922

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
50 changes: 25 additions & 25 deletions src/Microsoft.ML.Core/ComponentModel/ComponentCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,29 +336,29 @@ private static bool ShouldSkipPath(string path)
string name = Path.GetFileName(path).ToLowerInvariant();
switch (name)
{
case "cqo.dll":
case "fasttreenative.dll":
case "libiomp5md.dll":
case "libvw.dll":
case "matrixinterf.dll":
case "Microsoft.ML.neuralnetworks.gpucuda.dll":
case "MklImports.dll":
case "microsoft.research.controls.decisiontrees.dll":
case "Microsoft.ML.neuralnetworks.sse.dll":
case "neuraltreeevaluator.dll":
case "optimizationbuilderdotnet.dll":
case "parallelcommunicator.dll":
case "Microsoft.ML.Runtime.RunTests.dll":
case "scopecompiler.dll":
case "tbb.dll":
case "Internallearnscope.dll":
case "unmanagedlib.dll":
case "vcclient.dll":
case "libxgboost.dll":
case "zedgraph.dll":
case "__scopecodegen__.dll":
case "cosmosClientApi.dll":
return true;
case "cqo.dll":
case "fasttreenative.dll":
case "libiomp5md.dll":
case "libvw.dll":
case "matrixinterf.dll":
case "Microsoft.ML.neuralnetworks.gpucuda.dll":
case "MklImports.dll":
case "microsoft.research.controls.decisiontrees.dll":
case "Microsoft.ML.neuralnetworks.sse.dll":
case "neuraltreeevaluator.dll":
case "optimizationbuilderdotnet.dll":
case "parallelcommunicator.dll":
case "Microsoft.ML.Runtime.RunTests.dll":
case "scopecompiler.dll":
case "tbb.dll":
case "Internallearnscope.dll":
case "unmanagedlib.dll":
case "vcclient.dll":
case "libxgboost.dll":
case "zedgraph.dll":
case "__scopecodegen__.dll":
case "cosmosClientApi.dll":
return true;
}

foreach (var s in FilePrefixesToAvoid)
Expand Down Expand Up @@ -567,14 +567,14 @@ private static MethodInfo FindInstanceGetter(Type instType, Type loaderType)

private static MethodInfo FindCreateMethod(Type instType, Type loaderType, Type[] parmTypes)
{
var meth = loaderType.GetMethod("Create", parmTypes ?? Type.EmptyTypes);
var meth = loaderType.GetMethod("Create", BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy, null, parmTypes ?? Type.EmptyTypes, null);
if (meth == null)
return null;
if (meth.DeclaringType != loaderType)
return null;
if (meth.ReturnType != instType)
return null;
if (!meth.IsPublic || !meth.IsStatic)
if (!meth.IsStatic)
return null;
return meth;
}
Expand Down
9 changes: 6 additions & 3 deletions src/Microsoft.ML.Data/Transforms/CopyColumnsTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ public sealed class Arguments : TransformInputBase
public Column[] Column;
}

public static IDataView Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
// Factory method for SignatureLoadDataTransform.
private static IDataView Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
{
Contracts.CheckValue(env, nameof(env));
env.CheckValue(ctx, nameof(ctx));
Expand All @@ -139,7 +140,8 @@ public static IDataView Create(IHostEnvironment env, ModelLoadContext ctx, IData
return transformer.Transform(input);
}

public static CopyColumnsTransform Create(IHostEnvironment env, ModelLoadContext ctx)
// Factory method for SignatureLoadModel.
private static CopyColumnsTransform Create(IHostEnvironment env, ModelLoadContext ctx)
{
Contracts.CheckValue(env, nameof(env));
env.CheckValue(ctx, nameof(ctx));
Expand Down Expand Up @@ -225,7 +227,8 @@ private static VersionInfo GetVersionInfo()
loaderSignature: LoaderSignature);
}

public static CopyColumnsRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema schema)
// Factory method for SignatureLoadRowMapper.
private static CopyColumnsRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema schema)
{
Contracts.CheckValue(env, nameof(env));
env.CheckValue(ctx, nameof(ctx));
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.ML.Data/Transforms/KeyToValueTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataV
/// <summary>
/// Factory method for SignatureLoadModel.
/// </summary>
public static KeyToValueTransform Create(IHostEnvironment env, ModelLoadContext ctx)
private static KeyToValueTransform Create(IHostEnvironment env, ModelLoadContext ctx)
{
Contracts.CheckValue(env, nameof(env));
var host = env.Register(nameof(KeyToValueTransform));
Expand All @@ -129,13 +129,13 @@ private KeyToValueTransform(IHost host, ModelLoadContext ctx)
/// <summary>
/// Factory method for SignatureLoadDataTransform.
/// </summary>
public static IDataTransform Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
private static IDataTransform Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
=> Create(env, ctx).MakeDataTransform(input);

/// <summary>
/// Factory method for SignatureLoadRowMapper.
/// </summary>
public static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
=> Create(env, ctx).MakeRowMapper(inputSchema);

public override void Save(ModelSaveContext ctx)
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.ML.Data/Transforms/KeyToVectorTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public override void Save(ModelSaveContext ctx)
}

// Factory method for SignatureLoadModel.
public static KeyToVectorTransform Create(IHostEnvironment env, ModelLoadContext ctx)
private static KeyToVectorTransform Create(IHostEnvironment env, ModelLoadContext ctx)
{
Contracts.CheckValue(env, nameof(env));
var host = env.Register(RegistrationName);
Expand Down Expand Up @@ -204,7 +204,7 @@ public static IDataTransform Create(IHostEnvironment env, IDataView input, param
new KeyToVectorTransform(env, columns).MakeDataTransform(input);

// Factory method for SignatureDataTransform.
public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataView input)
private static IDataTransform Create(IHostEnvironment env, Arguments args, IDataView input)
{
Contracts.CheckValue(env, nameof(env));
env.CheckValue(args, nameof(args));
Expand All @@ -227,11 +227,11 @@ public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataV
}

// Factory method for SignatureLoadDataTransform.
public static IDataTransform Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
private static IDataTransform Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
=> Create(env, ctx).MakeDataTransform(input);

// Factory method for SignatureLoadRowMapper.
public static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
=> Create(env, ctx).MakeRowMapper(inputSchema);

protected override IRowMapper MakeRowMapper(ISchema schema) => new Mapper(this, schema);
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Data/Transforms/Normalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public static NormalizerTransformer Create(IHostEnvironment env, ModelLoadContex
}

// Factory method for SignatureLoadRowMapper.
public static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
=> Create(env, ctx).MakeRowMapper(inputSchema);

public override void Save(ModelSaveContext ctx)
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.ML.Data/Transforms/TermTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataV
}

// Factory method for SignatureLoadModel.
public static TermTransform Create(IHostEnvironment env, ModelLoadContext ctx)
private static TermTransform Create(IHostEnvironment env, ModelLoadContext ctx)
{
Contracts.CheckValue(env, nameof(env));
var host = env.Register(RegistrationName);
Expand Down Expand Up @@ -385,11 +385,11 @@ private TermTransform(IHost host, ModelLoadContext ctx)
}

// Factory method for SignatureLoadDataTransform.
public static IDataTransform Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
private static IDataTransform Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
=> Create(env, ctx).MakeDataTransform(input);

// Factory method for SignatureLoadRowMapper.
public static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
=> Create(env, ctx).MakeRowMapper(inputSchema);

/// <summary>
Expand Down
7 changes: 4 additions & 3 deletions src/Microsoft.ML.ImageAnalytics/ImageGrayscaleTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataV
.MakeDataTransform(input);
}

public static ImageGrayscaleTransform Create(IHostEnvironment env, ModelLoadContext ctx)
// Factory method for SignatureLoadModel.
private static ImageGrayscaleTransform Create(IHostEnvironment env, ModelLoadContext ctx)
{
Contracts.CheckValue(env, nameof(env));
var host = env.Register(RegistrationName);
Expand All @@ -113,11 +114,11 @@ private ImageGrayscaleTransform(IHost host, ModelLoadContext ctx)
}

// Factory method for SignatureLoadDataTransform.
public static IDataTransform Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
private static IDataTransform Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
=> Create(env, ctx).MakeDataTransform(input);

// Factory method for SignatureLoadRowMapper.
public static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
=> Create(env, ctx).MakeRowMapper(inputSchema);

public override void Save(ModelSaveContext ctx)
Expand Down
7 changes: 4 additions & 3 deletions src/Microsoft.ML.ImageAnalytics/ImageLoaderTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataV
.MakeDataTransform(data);
}

public static ImageLoaderTransform Create(IHostEnvironment env, ModelLoadContext ctx)
// Factory method for SignatureLoadModel.
private static ImageLoaderTransform Create(IHostEnvironment env, ModelLoadContext ctx)
{
Contracts.CheckValue(env, nameof(env));
env.CheckValue(ctx, nameof(ctx));
Expand All @@ -104,11 +105,11 @@ private ImageLoaderTransform(IHost host, ModelLoadContext ctx)
}

// Factory method for SignatureLoadDataTransform.
public static IDataTransform Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
private static IDataTransform Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
=> Create(env, ctx).MakeDataTransform(input);

// Factory method for SignatureLoadRowMapper.
public static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
=> Create(env, ctx).MakeRowMapper(inputSchema);

protected override void CheckInputColumn(ISchema inputSchema, int col, int srcCol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataV
return new RowToRowMapperTransform(env, input, transformer.MakeRowMapper(input.Schema));
}

public static ImagePixelExtractorTransform Create(IHostEnvironment env, ModelLoadContext ctx)
// Factory method for SignatureLoadModel.
private static ImagePixelExtractorTransform Create(IHostEnvironment env, ModelLoadContext ctx)
{
Contracts.CheckValue(env, nameof(env));
var host = env.Register(RegistrationName);
Expand All @@ -369,11 +370,11 @@ private ImagePixelExtractorTransform(IHost host, ModelLoadContext ctx)
}

// Factory method for SignatureLoadDataTransform.
public static IDataTransform Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
private static IDataTransform Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
=> Create(env, ctx).MakeDataTransform(input);

// Factory method for SignatureLoadRowMapper.
public static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
=> Create(env, ctx).MakeRowMapper(inputSchema);

public override void Save(ModelSaveContext ctx)
Expand Down
9 changes: 5 additions & 4 deletions src/Microsoft.ML.ImageAnalytics/ImageResizerTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataV
return new ImageResizerTransform(env, cols).MakeDataTransform(input);
}

public static ImageResizerTransform Create(IHostEnvironment env, ModelLoadContext ctx)
// Factory method for SignatureLoadModel.
private static ImageResizerTransform Create(IHostEnvironment env, ModelLoadContext ctx)
{
Contracts.CheckValue(env, nameof(env));
var host = env.Register(RegistrationName);
Expand Down Expand Up @@ -245,11 +246,11 @@ private ImageResizerTransform(IHost host, ModelLoadContext ctx)
}

// Factory method for SignatureLoadDataTransform.
public static IDataTransform Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
private static IDataTransform Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
=> Create(env, ctx).MakeDataTransform(input);

// Factory method for SignatureLoadRowMapper.
public static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
=> Create(env, ctx).MakeRowMapper(inputSchema);

public override void Save(ModelSaveContext ctx)
Expand Down Expand Up @@ -295,7 +296,7 @@ private sealed class Mapper : MapperBase
private readonly ImageResizerTransform _parent;

public Mapper(ImageResizerTransform parent, ISchema inputSchema)
:base(parent.Host.Register(nameof(Mapper)), parent, inputSchema)
: base(parent.Host.Register(nameof(Mapper)), parent, inputSchema)
{
_parent = parent;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.ML.TensorFlow/TensorflowTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static IDataTransform Create(IHostEnvironment env, IDataView input, strin
}

// Factory method for SignatureLoadModel.
public static TensorFlowTransform Create(IHostEnvironment env, ModelLoadContext ctx)
private static TensorFlowTransform Create(IHostEnvironment env, ModelLoadContext ctx)
{
Contracts.CheckValue(env, nameof(env));
env.CheckValue(ctx, nameof(ctx));
Expand Down Expand Up @@ -142,7 +142,7 @@ public static TensorFlowTransform Create(IHostEnvironment env, ModelLoadContext
}

// Factory method for SignatureDataTransform.
public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataView input)
private static IDataTransform Create(IHostEnvironment env, Arguments args, IDataView input)
{
Contracts.CheckValue(env, nameof(env));
env.CheckValue(args, nameof(args));
Expand All @@ -153,11 +153,11 @@ public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataV
}

// Factory method for SignatureLoadDataTransform.
public static IDataTransform Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
private static IDataTransform Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
=> Create(env, ctx).MakeDataTransform(input);

// Factory method for SignatureLoadRowMapper.
public static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
=> Create(env, ctx).MakeRowMapper(inputSchema);

private TFSession LoadTFSession(byte[] modelBytes)
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.ML.Transforms/KeyToBinaryVectorTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public override void Save(ModelSaveContext ctx)
}

// Factory method for SignatureLoadModel.
public static KeyToBinaryVectorTransform Create(IHostEnvironment env, ModelLoadContext ctx)
private static KeyToBinaryVectorTransform Create(IHostEnvironment env, ModelLoadContext ctx)
{
Contracts.CheckValue(env, nameof(env));
var host = env.Register(RegistrationName);
Expand Down Expand Up @@ -150,11 +150,11 @@ public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataV
}

// Factory method for SignatureLoadDataTransform.
public static IDataTransform Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
private static IDataTransform Create(IHostEnvironment env, ModelLoadContext ctx, IDataView input)
=> Create(env, ctx).MakeDataTransform(input);

// Factory method for SignatureLoadRowMapper.
public static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, ISchema inputSchema)
=> Create(env, ctx).MakeRowMapper(inputSchema);

protected override IRowMapper MakeRowMapper(ISchema schema) => new Mapper(this, schema);
Expand Down