Skip to content

Commit 342e13f

Browse files
authored
Remove some ISchema (#1861)
* Remove ISchema in many simple cases (not finished yet) * Some more easy cases resolved * One more easy round
1 parent 25abf91 commit 342e13f

File tree

92 files changed

+248
-236
lines changed

Some content is hidden

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

92 files changed

+248
-236
lines changed

src/Microsoft.ML.Core/Data/IEstimator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Microsoft.ML.Core.Data
1414
{
1515
/// <summary>
1616
/// A set of 'requirements' to the incoming schema, as well as a set of 'promises' of the outgoing schema.
17-
/// This is more relaxed than the proper <see cref="ISchema"/>, since it's only a subset of the columns,
17+
/// This is more relaxed than the proper <see cref="Schema"/>, since it's only a subset of the columns,
1818
/// and also since it doesn't specify exact <see cref="ColumnType"/>'s for vectors and keys.
1919
/// </summary>
2020
public sealed class SchemaShape : IReadOnlyList<SchemaShape.Column>
@@ -287,7 +287,7 @@ public interface ITransformer
287287
/// <summary>
288288
/// The estimator (in Spark terminology) is an 'untrained transformer'. It needs to 'fit' on the data to manufacture
289289
/// a transformer.
290-
/// It also provides the 'schema propagation' like transformers do, but over <see cref="SchemaShape"/> instead of <see cref="ISchema"/>.
290+
/// It also provides the 'schema propagation' like transformers do, but over <see cref="SchemaShape"/> instead of <see cref="Schema"/>.
291291
/// </summary>
292292
public interface IEstimator<out TTransformer>
293293
where TTransformer : ITransformer

src/Microsoft.ML.Core/Data/ISchemaBindableMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public interface IRowToRowMapper
8787

8888
/// <summary>
8989
/// Given a predicate specifying which columns are needed, return a predicate indicating which input columns are
90-
/// needed. The domain of the function is defined over the indices of the columns of <see cref="ISchema.ColumnCount"/>
90+
/// needed. The domain of the function is defined over the indices of the columns of <see cref="Schema.ColumnCount"/>
9191
/// for <see cref="InputSchema"/>.
9292
/// </summary>
9393
Func<int, bool> GetDependencies(Func<int, bool> predicate);

src/Microsoft.ML.Core/Data/RoleMappedSchema.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Microsoft.ML.Runtime.Data
1111
/// <summary>
1212
/// This contains information about a column in an <see cref="IDataView"/>. It is essentially a convenience cache
1313
/// containing the name, column index, and column type for the column. The intended usage is that users of <see cref="RoleMappedSchema"/>
14-
/// will have a convenient method of getting the index and type without having to separately query it through the <see cref="ISchema"/>,
14+
/// will have a convenient method of getting the index and type without having to separately query it through the <see cref="Schema"/>,
1515
/// since practically the first thing a consumer of a <see cref="RoleMappedSchema"/> will want to do once they get a mappping is get
1616
/// the type and index of the corresponding column.
1717
/// </summary>
@@ -32,7 +32,7 @@ private ColumnInfo(string name, int index, ColumnType type)
3232
/// Create a ColumnInfo for the column with the given name in the given schema. Throws if the name
3333
/// doesn't map to a column.
3434
/// </summary>
35-
public static ColumnInfo CreateFromName(ISchema schema, string name, string descName)
35+
public static ColumnInfo CreateFromName(Schema schema, string name, string descName)
3636
{
3737
if (!TryCreateFromName(schema, name, out var colInfo))
3838
throw Contracts.ExceptParam(nameof(name), $"{descName} column '{name}' not found");
@@ -44,7 +44,7 @@ public static ColumnInfo CreateFromName(ISchema schema, string name, string desc
4444
/// Tries to create a ColumnInfo for the column with the given name in the given schema. Returns
4545
/// false if the name doesn't map to a column.
4646
/// </summary>
47-
public static bool TryCreateFromName(ISchema schema, string name, out ColumnInfo colInfo)
47+
public static bool TryCreateFromName(Schema schema, string name, out ColumnInfo colInfo)
4848
{
4949
Contracts.CheckValue(schema, nameof(schema));
5050
Contracts.CheckNonEmpty(name, nameof(name));
@@ -62,7 +62,7 @@ public static bool TryCreateFromName(ISchema schema, string name, out ColumnInfo
6262
/// of the column might actually map to a different column, so this should be used with care
6363
/// and rarely.
6464
/// </summary>
65-
public static ColumnInfo CreateFromIndex(ISchema schema, int index)
65+
public static ColumnInfo CreateFromIndex(Schema schema, int index)
6666
{
6767
Contracts.CheckValue(schema, nameof(schema));
6868
Contracts.CheckParam(0 <= index && index < schema.ColumnCount, nameof(index));
@@ -72,7 +72,7 @@ public static ColumnInfo CreateFromIndex(ISchema schema, int index)
7272
}
7373

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

186186
/// <summary>
187-
/// The source <see cref="ISchema"/>.
187+
/// The source <see cref="Schema"/>.
188188
/// </summary>
189189
public Schema Schema { get; }
190190

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

277-
private static Dictionary<string, List<ColumnInfo>> MapFromNames(ISchema schema, IEnumerable<KeyValuePair<ColumnRole, string>> roles, bool opt = false)
277+
private static Dictionary<string, List<ColumnInfo>> MapFromNames(Schema schema, IEnumerable<KeyValuePair<ColumnRole, string>> roles, bool opt = false)
278278
{
279279
Contracts.AssertValue(schema);
280280
Contracts.AssertValue(roles);

src/Microsoft.ML.Core/Data/Schema.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public ColumnType GetMetadataTypeOrNull(string kind, int col)
328328
var meta = this[col].Metadata;
329329
if (meta == null)
330330
return null;
331-
if (((ISchema)meta.Schema).TryGetColumnIndex(kind, out int metaCol))
331+
if (meta.Schema.TryGetColumnIndex(kind, out int metaCol))
332332
return meta.Schema[metaCol].Type;
333333
return null;
334334
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataV
143143
using (var ch = env.Register("EvaluateTransform").Start("Create Transform"))
144144
{
145145
ch.Trace("Binding columns");
146-
ISchema schema = input.Schema;
146+
var schema = input.Schema;
147147
string label = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Arguments.LabelColumn),
148148
args.LabelColumn, DefaultColumnNames.Label);
149149
string group = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Arguments.GroupColumn),
@@ -218,7 +218,7 @@ private void RunCore(IChannel ch)
218218
(env, source) => new IO.BinaryLoader(env, new IO.BinaryLoader.Arguments(), source));
219219

220220
ch.Trace("Binding columns");
221-
ISchema schema = view.Schema;
221+
var schema = view.Schema;
222222
string label = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Arguments.LabelColumn),
223223
Args.LabelColumn, DefaultColumnNames.Label);
224224
string group = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Arguments.GroupColumn),

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Linq;
1010
using System.Reflection;
1111
using System.Text;
12+
using Microsoft.ML.Data;
1213
using Microsoft.ML.Runtime;
1314
using Microsoft.ML.Runtime.Command;
1415
using Microsoft.ML.Runtime.CommandLine;
@@ -113,7 +114,7 @@ private static IEnumerable<IDataView> GetViewChainReversed(IDataView data)
113114
}
114115
}
115116

116-
private static void PrintSchema(TextWriter writer, Arguments args, ISchema schema, ITransposeSchema tschema)
117+
private static void PrintSchema(TextWriter writer, Arguments args, Schema schema, ITransposeSchema tschema)
117118
{
118119
Contracts.AssertValue(writer);
119120
Contracts.AssertValue(args);
@@ -179,7 +180,7 @@ private static void PrintSchema(TextWriter writer, Arguments args, ISchema schem
179180
}
180181
}
181182

182-
private static void ShowMetadata(IndentedTextWriter itw, ISchema schema, int col, bool showVals)
183+
private static void ShowMetadata(IndentedTextWriter itw, Schema schema, int col, bool showVals)
183184
{
184185
Contracts.AssertValue(itw);
185186
Contracts.AssertValue(schema);
@@ -205,7 +206,7 @@ private static void ShowMetadata(IndentedTextWriter itw, ISchema schema, int col
205206
}
206207
}
207208

208-
private static void ShowMetadataValue(IndentedTextWriter itw, ISchema schema, int col, string kind, ColumnType type)
209+
private static void ShowMetadataValue(IndentedTextWriter itw, Schema schema, int col, string kind, ColumnType type)
209210
{
210211
Contracts.AssertValue(itw);
211212
Contracts.AssertValue(schema);
@@ -220,12 +221,12 @@ private static void ShowMetadataValue(IndentedTextWriter itw, ISchema schema, in
220221
return;
221222
}
222223

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

228-
private static void ShowMetadataValue<T>(IndentedTextWriter itw, ISchema schema, int col, string kind, ColumnType type)
229+
private static void ShowMetadataValue<T>(IndentedTextWriter itw, Schema schema, int col, string kind, ColumnType type)
229230
{
230231
Contracts.AssertValue(itw);
231232
Contracts.AssertValue(schema);
@@ -245,7 +246,7 @@ private static void ShowMetadataValue<T>(IndentedTextWriter itw, ISchema schema,
245246
itw.Write(": '{0}'", sb);
246247
}
247248

248-
private static void ShowMetadataValueVec(IndentedTextWriter itw, ISchema schema, int col, string kind, ColumnType type)
249+
private static void ShowMetadataValueVec(IndentedTextWriter itw, Schema schema, int col, string kind, ColumnType type)
249250
{
250251
Contracts.AssertValue(itw);
251252
Contracts.AssertValue(schema);
@@ -260,12 +261,12 @@ private static void ShowMetadataValueVec(IndentedTextWriter itw, ISchema schema,
260261
return;
261262
}
262263

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

268-
private static void ShowMetadataValueVec<T>(IndentedTextWriter itw, ISchema schema, int col, string kind, ColumnType type)
269+
private static void ShowMetadataValueVec<T>(IndentedTextWriter itw, Schema schema, int col, string kind, ColumnType type)
269270
{
270271
Contracts.AssertValue(itw);
271272
Contracts.AssertValue(schema);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private void RunCore(IChannel ch)
9494
ch.AssertValue(loader);
9595

9696
ch.Trace("Binding columns");
97-
ISchema schema = loader.Schema;
97+
var schema = loader.Schema;
9898
string label = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Args.LabelColumn),
9999
Args.LabelColumn, DefaultColumnNames.Label);
100100
string features = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Args.FeatureColumn),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private void RunCore(IChannel ch, string cmd)
146146
ch.Trace("Constructing data pipeline");
147147
IDataView view = CreateLoader();
148148

149-
ISchema schema = view.Schema;
149+
var schema = view.Schema;
150150
var label = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Arguments.LabelColumn), _labelColumn, DefaultColumnNames.Label);
151151
var feature = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Arguments.FeatureColumn), _featureColumn, DefaultColumnNames.Features);
152152
var group = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Arguments.GroupColumn), _groupColumn, DefaultColumnNames.GroupId);
@@ -221,7 +221,7 @@ public static void CheckTrainer(IExceptionContext ectx, IComponentFactory<ITrain
221221
/// Else, if the user name equals the default name return null.
222222
/// Else, throw an error.
223223
/// </summary>
224-
public static string MatchNameOrDefaultOrNull(IExceptionContext ectx, ISchema schema, string argName, string userName, string defaultName)
224+
public static string MatchNameOrDefaultOrNull(IExceptionContext ectx, Schema schema, string argName, string userName, string defaultName)
225225
{
226226
Contracts.CheckValueOrNull(ectx);
227227
ectx.CheckValue(schema, nameof(schema));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private void RunCore(IChannel ch, string cmd)
130130
ch.Trace("Constructing the training pipeline");
131131
IDataView trainPipe = CreateLoader();
132132

133-
ISchema schema = trainPipe.Schema;
133+
var schema = trainPipe.Schema;
134134
string label = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Arguments.LabelColumn),
135135
Args.LabelColumn, DefaultColumnNames.Label);
136136
string features = TrainUtils.MatchNameOrDefaultOrNull(ch, schema, nameof(Arguments.FeatureColumn),

src/Microsoft.ML.Data/Data/DataViewUtils.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static class DataViewUtils
2222
/// Use tag to independently create multiple temporary, unique column
2323
/// names for a single transform.
2424
/// </summary>
25-
public static string GetTempColumnName(this ISchema schema, string tag = null)
25+
public static string GetTempColumnName(this Schema schema, string tag = null)
2626
{
2727
Contracts.CheckValue(schema, nameof(schema));
2828

@@ -46,7 +46,7 @@ public static string GetTempColumnName(this ISchema schema, string tag = null)
4646
/// Use tag to independently create multiple temporary, unique column
4747
/// names for a single transform.
4848
/// </summary>
49-
public static string[] GetTempColumnNames(this ISchema schema, int n, string tag = null)
49+
public static string[] GetTempColumnNames(this Schema schema, int n, string tag = null)
5050
{
5151
Contracts.CheckValue(schema, nameof(schema));
5252
Contracts.Check(n > 0, "n");
@@ -175,7 +175,7 @@ public static RowCursor[] CreateSplitCursors(out IRowCursorConsolidator consolid
175175
/// Return whether all the active columns, as determined by the predicate, are
176176
/// cachable - either primitive types or vector types.
177177
/// </summary>
178-
public static bool AllCachable(ISchema schema, Func<int, bool> predicate)
178+
public static bool AllCachable(Schema schema, Func<int, bool> predicate)
179179
{
180180
Contracts.CheckValue(schema, nameof(schema));
181181
Contracts.CheckValue(predicate, nameof(predicate));

src/Microsoft.ML.Data/DataLoadSave/Binary/BinarySaver.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Text;
1313
using System.Threading;
1414
using System.Threading.Tasks;
15+
using Microsoft.ML.Data;
1516
using Microsoft.ML.Runtime;
1617
using Microsoft.ML.Runtime.CommandLine;
1718
using Microsoft.ML.Runtime.Data;
@@ -254,7 +255,7 @@ private void CompressionWorker(BlockingCollection<Block> toCompress, BlockingCol
254255
/// <param name="ch">The channel to which we write any diagnostic information</param>
255256
/// <returns>The offset of the metadata table of contents, or 0 if there was
256257
/// no metadata</returns>
257-
private long WriteMetadata(BinaryWriter writer, ISchema schema, int col, IChannel ch)
258+
private long WriteMetadata(BinaryWriter writer, Schema schema, int col, IChannel ch)
258259
{
259260
_host.AssertValue(writer);
260261
_host.AssertValue(schema);
@@ -341,9 +342,9 @@ private long WriteMetadata(BinaryWriter writer, ISchema schema, int col, IChanne
341342
return offsets[metadataInfos.Count];
342343
}
343344

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

346-
private IValueCodec WriteMetadataCore<T>(Stream stream, ISchema schema, int col, string kind, ColumnType type, out CompressionKind compressionKind)
347+
private IValueCodec WriteMetadataCore<T>(Stream stream, Schema schema, int col, string kind, ColumnType type, out CompressionKind compressionKind)
347348
{
348349
_host.Assert(typeof(T) == type.RawType);
349350
IValueCodec generalCodec;
@@ -390,7 +391,7 @@ private IValueCodec WriteMetadataCore<T>(Stream stream, ISchema schema, int col,
390391
}
391392

392393
private void WriteWorker(Stream stream, BlockingCollection<Block> toWrite, ColumnCodec[] activeColumns,
393-
ISchema sourceSchema, int rowsPerBlock, IChannelProvider cp, ExceptionMarshaller exMarshaller)
394+
Schema sourceSchema, int rowsPerBlock, IChannelProvider cp, ExceptionMarshaller exMarshaller)
394395
{
395396
_host.AssertValue(exMarshaller);
396397
try
@@ -708,7 +709,7 @@ public void SaveData(Stream stream, IDataView data, params int[] colIndices)
708709
}
709710
}
710711

711-
private ColumnCodec[] GetActiveColumns(ISchema schema, int[] colIndices)
712+
private ColumnCodec[] GetActiveColumns(Schema schema, int[] colIndices)
712713
{
713714
_host.AssertValue(schema);
714715
_host.AssertValueOrNull(colIndices);

src/Microsoft.ML.Data/DataLoadSave/PartitionedFileLoader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ private Schema CreateSchema(IExceptionContext ectx, Column[] cols, IDataLoader s
329329
}
330330
else
331331
{
332-
var schemas = new ISchema[]
332+
var schemas = new Schema[]
333333
{
334334
subSchema,
335335
colSchema
@@ -636,7 +636,7 @@ private IEnumerable<int> CreateFileOrder(Random rand)
636636
}
637637
}
638638

639-
private bool SchemasMatch(ISchema schema1, ISchema schema2)
639+
private bool SchemasMatch(Schema schema1, Schema schema2)
640640
{
641641
if (schema1.ColumnCount != schema2.ColumnCount)
642642
{

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Microsoft.ML.Runtime.Data.IO;
1313
using Microsoft.ML.Runtime.Internal.Utilities;
1414
using Microsoft.ML.Runtime.Internal.Internallearn;
15+
using Microsoft.ML.Data;
1516

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

452-
private string CreateLoaderArguments(ISchema schema, ValueWriter[] pipes, bool hasHeader, IChannel ch)
453+
private string CreateLoaderArguments(Schema schema, ValueWriter[] pipes, bool hasHeader, IChannel ch)
453454
{
454455
StringBuilder sb = new StringBuilder();
455456
if (hasHeader)

0 commit comments

Comments
 (0)