Skip to content

Remove some ISchema #1861

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 3 commits into from
Dec 11, 2018
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
4 changes: 2 additions & 2 deletions src/Microsoft.ML.Core/Data/IEstimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.ML.Core.Data
{
/// <summary>
/// A set of 'requirements' to the incoming schema, as well as a set of 'promises' of the outgoing schema.
/// This is more relaxed than the proper <see cref="ISchema"/>, since it's only a subset of the columns,
/// This is more relaxed than the proper <see cref="Schema"/>, since it's only a subset of the columns,
/// and also since it doesn't specify exact <see cref="ColumnType"/>'s for vectors and keys.
/// </summary>
public sealed class SchemaShape : IReadOnlyList<SchemaShape.Column>
Expand Down Expand Up @@ -287,7 +287,7 @@ public interface ITransformer
/// <summary>
/// The estimator (in Spark terminology) is an 'untrained transformer'. It needs to 'fit' on the data to manufacture
/// a transformer.
/// It also provides the 'schema propagation' like transformers do, but over <see cref="SchemaShape"/> instead of <see cref="ISchema"/>.
/// It also provides the 'schema propagation' like transformers do, but over <see cref="SchemaShape"/> instead of <see cref="Schema"/>.
/// </summary>
public interface IEstimator<out TTransformer>
where TTransformer : ITransformer
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Core/Data/ISchemaBindableMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public interface IRowToRowMapper

/// <summary>
/// Given a predicate specifying which columns are needed, return a predicate indicating which input columns are
/// needed. The domain of the function is defined over the indices of the columns of <see cref="ISchema.ColumnCount"/>
/// needed. The domain of the function is defined over the indices of the columns of <see cref="Schema.ColumnCount"/>
/// for <see cref="InputSchema"/>.
/// </summary>
Func<int, bool> GetDependencies(Func<int, bool> predicate);
Expand Down
16 changes: 8 additions & 8 deletions src/Microsoft.ML.Core/Data/RoleMappedSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.ML.Runtime.Data
/// <summary>
/// This contains information about a column in an <see cref="IDataView"/>. It is essentially a convenience cache
/// containing the name, column index, and column type for the column. The intended usage is that users of <see cref="RoleMappedSchema"/>
/// will have a convenient method of getting the index and type without having to separately query it through the <see cref="ISchema"/>,
/// will have a convenient method of getting the index and type without having to separately query it through the <see cref="Schema"/>,
/// since practically the first thing a consumer of a <see cref="RoleMappedSchema"/> will want to do once they get a mappping is get
/// the type and index of the corresponding column.
/// </summary>
Expand All @@ -32,7 +32,7 @@ private ColumnInfo(string name, int index, ColumnType type)
/// Create a ColumnInfo for the column with the given name in the given schema. Throws if the name
/// doesn't map to a column.
/// </summary>
public static ColumnInfo CreateFromName(ISchema schema, string name, string descName)
public static ColumnInfo CreateFromName(Schema schema, string name, string descName)
{
if (!TryCreateFromName(schema, name, out var colInfo))
throw Contracts.ExceptParam(nameof(name), $"{descName} column '{name}' not found");
Expand All @@ -44,7 +44,7 @@ public static ColumnInfo CreateFromName(ISchema schema, string name, string desc
/// Tries to create a ColumnInfo for the column with the given name in the given schema. Returns
/// false if the name doesn't map to a column.
/// </summary>
public static bool TryCreateFromName(ISchema schema, string name, out ColumnInfo colInfo)
public static bool TryCreateFromName(Schema schema, string name, out ColumnInfo colInfo)
{
Contracts.CheckValue(schema, nameof(schema));
Contracts.CheckNonEmpty(name, nameof(name));
Expand All @@ -62,7 +62,7 @@ public static bool TryCreateFromName(ISchema schema, string name, out ColumnInfo
/// of the column might actually map to a different column, so this should be used with care
/// and rarely.
/// </summary>
public static ColumnInfo CreateFromIndex(ISchema schema, int index)
public static ColumnInfo CreateFromIndex(Schema schema, int index)
{
Contracts.CheckValue(schema, nameof(schema));
Contracts.CheckParam(0 <= index && index < schema.ColumnCount, nameof(index));
Expand All @@ -72,7 +72,7 @@ public static ColumnInfo CreateFromIndex(ISchema schema, int index)
}

/// <summary>
/// Encapsulates an <see cref="ISchema"/> plus column role mapping information. The purpose of role mappings is to
/// Encapsulates an <see cref="Schema"/> plus column role mapping information. The purpose of role mappings is to
/// provide information on what the intended usage is for. That is: while a given data view may have a column named
/// "Features", by itself that is insufficient: the trainer must be fed a role mapping that says that the role
/// mapping for features is filled by that "Features" column. This allows things like columns not named "Features"
Expand All @@ -88,7 +88,7 @@ public static ColumnInfo CreateFromIndex(ISchema schema, int index)
/// in this schema.
/// </summary>
/// <remarks>
/// Note that instances of this class are, like instances of <see cref="ISchema"/>, immutable.
/// Note that instances of this class are, like instances of <see cref="Schema"/>, immutable.
///
/// It is often the case that one wishes to bundle the actual data with the role mappings, not just the schema. For
/// that case, please use the <see cref="RoleMappedData"/> class.
Expand Down Expand Up @@ -184,7 +184,7 @@ public static KeyValuePair<ColumnRole, string> CreatePair(ColumnRole role, strin
=> new KeyValuePair<ColumnRole, string>(role, name);

/// <summary>
/// The source <see cref="ISchema"/>.
/// The source <see cref="Schema"/>.
/// </summary>
public Schema Schema { get; }

Expand Down Expand Up @@ -274,7 +274,7 @@ private static void Add(Dictionary<string, List<ColumnInfo>> map, ColumnRole rol
list.Add(info);
}

private static Dictionary<string, List<ColumnInfo>> MapFromNames(ISchema schema, IEnumerable<KeyValuePair<ColumnRole, string>> roles, bool opt = false)
private static Dictionary<string, List<ColumnInfo>> MapFromNames(Schema schema, IEnumerable<KeyValuePair<ColumnRole, string>> roles, bool opt = false)
{
Contracts.AssertValue(schema);
Contracts.AssertValue(roles);
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Core/Data/Schema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public ColumnType GetMetadataTypeOrNull(string kind, int col)
var meta = this[col].Metadata;
if (meta == null)
return null;
if (((ISchema)meta.Schema).TryGetColumnIndex(kind, out int metaCol))
if (meta.Schema.TryGetColumnIndex(kind, out int metaCol))
return meta.Schema[metaCol].Type;
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.ML.Data/Commands/EvaluateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataV
using (var ch = env.Register("EvaluateTransform").Start("Create Transform"))
{
ch.Trace("Binding columns");
ISchema schema = input.Schema;
var schema = input.Schema;
string label = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Arguments.LabelColumn),
args.LabelColumn, DefaultColumnNames.Label);
string group = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Arguments.GroupColumn),
Expand Down Expand Up @@ -218,7 +218,7 @@ private void RunCore(IChannel ch)
(env, source) => new IO.BinaryLoader(env, new IO.BinaryLoader.Arguments(), source));

ch.Trace("Binding columns");
ISchema schema = view.Schema;
var schema = view.Schema;
string label = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Arguments.LabelColumn),
Args.LabelColumn, DefaultColumnNames.Label);
string group = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Arguments.GroupColumn),
Expand Down
17 changes: 9 additions & 8 deletions src/Microsoft.ML.Data/Commands/ShowSchemaCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Linq;
using System.Reflection;
using System.Text;
using Microsoft.ML.Data;
using Microsoft.ML.Runtime;
using Microsoft.ML.Runtime.Command;
using Microsoft.ML.Runtime.CommandLine;
Expand Down Expand Up @@ -113,7 +114,7 @@ private static IEnumerable<IDataView> GetViewChainReversed(IDataView data)
}
}

private static void PrintSchema(TextWriter writer, Arguments args, ISchema schema, ITransposeSchema tschema)
private static void PrintSchema(TextWriter writer, Arguments args, Schema schema, ITransposeSchema tschema)
{
Contracts.AssertValue(writer);
Contracts.AssertValue(args);
Expand Down Expand Up @@ -179,7 +180,7 @@ private static void PrintSchema(TextWriter writer, Arguments args, ISchema schem
}
}

private static void ShowMetadata(IndentedTextWriter itw, ISchema schema, int col, bool showVals)
private static void ShowMetadata(IndentedTextWriter itw, Schema schema, int col, bool showVals)
{
Contracts.AssertValue(itw);
Contracts.AssertValue(schema);
Expand All @@ -205,7 +206,7 @@ private static void ShowMetadata(IndentedTextWriter itw, ISchema schema, int col
}
}

private static void ShowMetadataValue(IndentedTextWriter itw, ISchema schema, int col, string kind, ColumnType type)
private static void ShowMetadataValue(IndentedTextWriter itw, Schema schema, int col, string kind, ColumnType type)
{
Contracts.AssertValue(itw);
Contracts.AssertValue(schema);
Expand All @@ -220,12 +221,12 @@ private static void ShowMetadataValue(IndentedTextWriter itw, ISchema schema, in
return;
}

Action<IndentedTextWriter, ISchema, int, string, ColumnType> del = ShowMetadataValue<int>;
Action<IndentedTextWriter, Schema, int, string, ColumnType> del = ShowMetadataValue<int>;
var meth = del.GetMethodInfo().GetGenericMethodDefinition().MakeGenericMethod(type.RawType);
meth.Invoke(null, new object[] { itw, schema, col, kind, type });
}

private static void ShowMetadataValue<T>(IndentedTextWriter itw, ISchema schema, int col, string kind, ColumnType type)
private static void ShowMetadataValue<T>(IndentedTextWriter itw, Schema schema, int col, string kind, ColumnType type)
{
Contracts.AssertValue(itw);
Contracts.AssertValue(schema);
Expand All @@ -245,7 +246,7 @@ private static void ShowMetadataValue<T>(IndentedTextWriter itw, ISchema schema,
itw.Write(": '{0}'", sb);
}

private static void ShowMetadataValueVec(IndentedTextWriter itw, ISchema schema, int col, string kind, ColumnType type)
private static void ShowMetadataValueVec(IndentedTextWriter itw, Schema schema, int col, string kind, ColumnType type)
{
Contracts.AssertValue(itw);
Contracts.AssertValue(schema);
Expand All @@ -260,12 +261,12 @@ private static void ShowMetadataValueVec(IndentedTextWriter itw, ISchema schema,
return;
}

Action<IndentedTextWriter, ISchema, int, string, ColumnType> del = ShowMetadataValueVec<int>;
Action<IndentedTextWriter, Schema, int, string, ColumnType> del = ShowMetadataValueVec<int>;
var meth = del.GetMethodInfo().GetGenericMethodDefinition().MakeGenericMethod(type.ItemType.RawType);
meth.Invoke(null, new object[] { itw, schema, col, kind, type });
}

private static void ShowMetadataValueVec<T>(IndentedTextWriter itw, ISchema schema, int col, string kind, ColumnType type)
private static void ShowMetadataValueVec<T>(IndentedTextWriter itw, Schema schema, int col, string kind, ColumnType type)
{
Contracts.AssertValue(itw);
Contracts.AssertValue(schema);
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Data/Commands/TestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void RunCore(IChannel ch)
ch.AssertValue(loader);

ch.Trace("Binding columns");
ISchema schema = loader.Schema;
var schema = loader.Schema;
string label = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Args.LabelColumn),
Args.LabelColumn, DefaultColumnNames.Label);
string features = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Args.FeatureColumn),
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.ML.Data/Commands/TrainCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void RunCore(IChannel ch, string cmd)
ch.Trace("Constructing data pipeline");
IDataView view = CreateLoader();

ISchema schema = view.Schema;
var schema = view.Schema;
var label = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Arguments.LabelColumn), _labelColumn, DefaultColumnNames.Label);
var feature = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Arguments.FeatureColumn), _featureColumn, DefaultColumnNames.Features);
var group = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Arguments.GroupColumn), _groupColumn, DefaultColumnNames.GroupId);
Expand Down Expand Up @@ -221,7 +221,7 @@ public static void CheckTrainer(IExceptionContext ectx, IComponentFactory<ITrain
/// Else, if the user name equals the default name return null.
/// Else, throw an error.
/// </summary>
public static string MatchNameOrDefaultOrNull(IExceptionContext ectx, ISchema schema, string argName, string userName, string defaultName)
public static string MatchNameOrDefaultOrNull(IExceptionContext ectx, Schema schema, string argName, string userName, string defaultName)
{
Contracts.CheckValueOrNull(ectx);
ectx.CheckValue(schema, nameof(schema));
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Data/Commands/TrainTestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private void RunCore(IChannel ch, string cmd)
ch.Trace("Constructing the training pipeline");
IDataView trainPipe = CreateLoader();

ISchema schema = trainPipe.Schema;
var schema = trainPipe.Schema;
string label = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Arguments.LabelColumn),
Args.LabelColumn, DefaultColumnNames.Label);
string features = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Arguments.FeatureColumn),
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.ML.Data/Data/DataViewUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class DataViewUtils
/// Use tag to independently create multiple temporary, unique column
/// names for a single transform.
/// </summary>
public static string GetTempColumnName(this ISchema schema, string tag = null)
public static string GetTempColumnName(this Schema schema, string tag = null)
{
Contracts.CheckValue(schema, nameof(schema));

Expand All @@ -46,7 +46,7 @@ public static string GetTempColumnName(this ISchema schema, string tag = null)
/// Use tag to independently create multiple temporary, unique column
/// names for a single transform.
/// </summary>
public static string[] GetTempColumnNames(this ISchema schema, int n, string tag = null)
public static string[] GetTempColumnNames(this Schema schema, int n, string tag = null)
{
Contracts.CheckValue(schema, nameof(schema));
Contracts.Check(n > 0, "n");
Expand Down Expand Up @@ -175,7 +175,7 @@ public static RowCursor[] CreateSplitCursors(out IRowCursorConsolidator consolid
/// Return whether all the active columns, as determined by the predicate, are
/// cachable - either primitive types or vector types.
/// </summary>
public static bool AllCachable(ISchema schema, Func<int, bool> predicate)
public static bool AllCachable(Schema schema, Func<int, bool> predicate)
{
Contracts.CheckValue(schema, nameof(schema));
Contracts.CheckValue(predicate, nameof(predicate));
Expand Down
11 changes: 6 additions & 5 deletions src/Microsoft.ML.Data/DataLoadSave/Binary/BinarySaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.ML.Data;
using Microsoft.ML.Runtime;
using Microsoft.ML.Runtime.CommandLine;
using Microsoft.ML.Runtime.Data;
Expand Down Expand Up @@ -254,7 +255,7 @@ private void CompressionWorker(BlockingCollection<Block> toCompress, BlockingCol
/// <param name="ch">The channel to which we write any diagnostic information</param>
/// <returns>The offset of the metadata table of contents, or 0 if there was
/// no metadata</returns>
private long WriteMetadata(BinaryWriter writer, ISchema schema, int col, IChannel ch)
private long WriteMetadata(BinaryWriter writer, Schema schema, int col, IChannel ch)
{
_host.AssertValue(writer);
_host.AssertValue(schema);
Expand Down Expand Up @@ -341,9 +342,9 @@ private long WriteMetadata(BinaryWriter writer, ISchema schema, int col, IChanne
return offsets[metadataInfos.Count];
}

private delegate IValueCodec WriteMetadataCoreDelegate(Stream stream, ISchema schema, int col, string kind, ColumnType type, out CompressionKind compression);
private delegate IValueCodec WriteMetadataCoreDelegate(Stream stream, Schema schema, int col, string kind, ColumnType type, out CompressionKind compression);

private IValueCodec WriteMetadataCore<T>(Stream stream, ISchema schema, int col, string kind, ColumnType type, out CompressionKind compressionKind)
private IValueCodec WriteMetadataCore<T>(Stream stream, Schema schema, int col, string kind, ColumnType type, out CompressionKind compressionKind)
{
_host.Assert(typeof(T) == type.RawType);
IValueCodec generalCodec;
Expand Down Expand Up @@ -390,7 +391,7 @@ private IValueCodec WriteMetadataCore<T>(Stream stream, ISchema schema, int col,
}

private void WriteWorker(Stream stream, BlockingCollection<Block> toWrite, ColumnCodec[] activeColumns,
ISchema sourceSchema, int rowsPerBlock, IChannelProvider cp, ExceptionMarshaller exMarshaller)
Schema sourceSchema, int rowsPerBlock, IChannelProvider cp, ExceptionMarshaller exMarshaller)
{
_host.AssertValue(exMarshaller);
try
Expand Down Expand Up @@ -708,7 +709,7 @@ public void SaveData(Stream stream, IDataView data, params int[] colIndices)
}
}

private ColumnCodec[] GetActiveColumns(ISchema schema, int[] colIndices)
private ColumnCodec[] GetActiveColumns(Schema schema, int[] colIndices)
{
_host.AssertValue(schema);
_host.AssertValueOrNull(colIndices);
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.ML.Data/DataLoadSave/PartitionedFileLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ private Schema CreateSchema(IExceptionContext ectx, Column[] cols, IDataLoader s
}
else
{
var schemas = new ISchema[]
var schemas = new Schema[]
{
subSchema,
colSchema
Expand Down Expand Up @@ -636,7 +636,7 @@ private IEnumerable<int> CreateFileOrder(Random rand)
}
}

private bool SchemasMatch(ISchema schema1, ISchema schema2)
private bool SchemasMatch(Schema schema1, Schema schema2)
{
if (schema1.ColumnCount != schema2.ColumnCount)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.ML.Data/DataLoadSave/Text/TextSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.ML.Runtime.Data.IO;
using Microsoft.ML.Runtime.Internal.Utilities;
using Microsoft.ML.Runtime.Internal.Internallearn;
using Microsoft.ML.Data;

[assembly: LoadableClass(TextSaver.Summary, typeof(TextSaver), typeof(TextSaver.Arguments), typeof(SignatureDataSaver),
"Text Saver", "TextSaver", "Text", DocName = "saver/TextSaver.md")]
Expand Down Expand Up @@ -449,7 +450,7 @@ private void WriteSchemaAsComment(TextWriter writer, string str)
writer.WriteLine("#@ }");
}

private string CreateLoaderArguments(ISchema schema, ValueWriter[] pipes, bool hasHeader, IChannel ch)
private string CreateLoaderArguments(Schema schema, ValueWriter[] pipes, bool hasHeader, IChannel ch)
{
StringBuilder sb = new StringBuilder();
if (hasHeader)
Expand Down
Loading