Skip to content

Commit cb37c7e

Browse files
authored
Remove ISchematized interface from the codebase. (#1759)
* Remove ISchematized interface from the codebase. 1. Remove ISchematized 2. For any class that requires a Schema, we add an Schema as its field 3. Rename Schema to OutputSchema in IRowToRowMapper * Address comments * Clean redundant Schema field and point Schema to OutputSchema * Replace Schema in SingleValueRowMapper with OutputSchema
1 parent be115f4 commit cb37c7e

File tree

52 files changed

+238
-182
lines changed

Some content is hidden

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

52 files changed

+238
-182
lines changed

src/Microsoft.ML.Api/PredictionEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ private protected PredictionEngineBase(IHostEnvironment env, ITransformer transf
196196
internal virtual void PredictionEngineCore(IHostEnvironment env, DataViewConstructionUtils.InputRow<TSrc> inputRow, IRowToRowMapper mapper, bool ignoreMissingColumns,
197197
SchemaDefinition inputSchemaDefinition, SchemaDefinition outputSchemaDefinition, out Action disposer, out IRowReadableAs<TDst> outputRow)
198198
{
199-
var cursorable = TypedCursorable<TDst>.Create(env, new EmptyDataView(env, mapper.Schema), ignoreMissingColumns, outputSchemaDefinition);
199+
var cursorable = TypedCursorable<TDst>.Create(env, new EmptyDataView(env, mapper.OutputSchema), ignoreMissingColumns, outputSchemaDefinition);
200200
var outputRowLocal = mapper.GetRow(_inputRow, col => true, out disposer);
201201
outputRow = cursorable.GetRow(outputRowLocal);
202202
}

src/Microsoft.ML.Api/StatefulFilterTransform.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ private StatefulFilterTransform(IHostEnvironment env, StatefulFilterTransform<TS
9898

9999
public bool CanShuffle { get { return false; } }
100100

101-
public Schema Schema => _bindings.Schema;
101+
Schema IDataView.Schema => OutputSchema;
102+
103+
public Schema OutputSchema => _bindings.Schema;
102104

103105
public long? GetRowCount()
104106
{

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,11 @@ public interface ISchema
6060
void GetMetadata<TValue>(string kind, int col, ref TValue value);
6161
}
6262

63-
/// <summary>
64-
/// Base interface for schematized information. IDataView and IRowCursor both derive from this.
65-
/// </summary>
66-
public interface ISchematized
67-
{
68-
/// <summary>
69-
/// Gets an instance of Schema.
70-
/// </summary>
71-
Schema Schema { get; }
72-
}
73-
7463
/// <summary>
7564
/// The input and output of Query Operators (Transforms). This is the fundamental data pipeline
7665
/// type, comparable to IEnumerable for LINQ.
7766
/// </summary>
78-
public interface IDataView : ISchematized
67+
public interface IDataView
7968
{
8069
/// <summary>
8170
/// Whether this IDataView supports shuffling of rows, to any degree.
@@ -124,6 +113,11 @@ public interface IDataView : ISchematized
124113
/// <returns></returns>
125114
IRowCursor[] GetRowCursorSet(out IRowCursorConsolidator consolidator,
126115
Func<int, bool> needCol, int n, Random rand = null);
116+
117+
/// <summary>
118+
/// Gets an instance of Schema.
119+
/// </summary>
120+
Schema Schema { get; }
127121
}
128122

129123
/// <summary>
@@ -148,7 +142,7 @@ public interface IRowCursorConsolidator
148142
/// A logical row. May be a row of an IDataView or a stand-alone row. If/when its contents
149143
/// change, its ICounted.Counter value is incremented.
150144
/// </summary>
151-
public interface IRow : ISchematized, ICounted
145+
public interface IRow : ICounted
152146
{
153147
/// <summary>
154148
/// Returns whether the given column is active in this row.
@@ -161,6 +155,13 @@ public interface IRow : ISchematized, ICounted
161155
/// <typeparamref name="TValue"/> differs from this column's type.
162156
/// </summary>
163157
ValueGetter<TValue> GetGetter<TValue>(int col);
158+
159+
/// <summary>
160+
/// Gets a <see cref="Schema"/>, which provides name and type information for variables
161+
/// (i.e., columns in ML.NET's type system) stored in this row.
162+
/// </summary>
163+
Schema Schema { get; }
164+
164165
}
165166

166167
/// <summary>

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@ public interface ISchemaBindableMapper
3030
/// This interface is used to map a schema from input columns to output columns. The <see cref="ISchemaBoundMapper"/> should keep track
3131
/// of the input columns that are needed for the mapping.
3232
/// </summary>
33-
public interface ISchemaBoundMapper : ISchematized
33+
public interface ISchemaBoundMapper
3434
{
3535
/// <summary>
3636
/// The <see cref="RoleMappedSchema"/> that was passed to the <see cref="ISchemaBoundMapper"/> in the binding process.
3737
/// </summary>
3838
RoleMappedSchema InputRoleMappedSchema { get; }
3939

40+
/// <summary>
41+
/// Gets schema of this mapper's output.
42+
/// </summary>
43+
Schema OutputSchema { get; }
44+
4045
/// <summary>
4146
/// A property to get back the <see cref="ISchemaBindableMapper"/> that produced this <see cref="ISchemaBoundMapper"/>.
4247
/// </summary>
@@ -53,6 +58,11 @@ public interface ISchemaBoundMapper : ISchematized
5358
/// </summary>
5459
public interface ISchemaBoundRowMapper : ISchemaBoundMapper, IRowToRowMapper
5560
{
61+
/// <summary>
62+
/// There are two schemas from <see cref="ISchemaBoundMapper"/> and <see cref="IRowToRowMapper"/>.
63+
/// Since the two parent schema's are identical in all derived classes, we merge them into <see cref="OutputSchema"/>.
64+
/// </summary>
65+
new Schema OutputSchema { get; }
5666
}
5767

5868
/// <summary>
@@ -61,15 +71,20 @@ public interface ISchemaBoundRowMapper : ISchemaBoundMapper, IRowToRowMapper
6171
/// return a subset of the input columns.
6272
/// This interface is similar to <see cref="ISchemaBoundRowMapper"/>, except it does not have any input role mappings,
6373
/// so to rebind, the same input column names must be used.
64-
/// Implementing of this object are typically created using a definie input <see cref="ISchema"/>.
74+
/// Implementations of this interface are typically created over defined input <see cref="Schema"/>.
6575
/// </summary>
66-
public interface IRowToRowMapper : ISchematized
76+
public interface IRowToRowMapper
6777
{
6878
/// <summary>
6979
/// Mappers are defined as accepting inputs with this very specific schema.
7080
/// </summary>
7181
Schema InputSchema { get; }
7282

83+
/// <summary>
84+
/// Gets an instance of <see cref="Schema"/> which describes the columns' names and types in the output generated by this mapper.
85+
/// </summary>
86+
Schema OutputSchema { get; }
87+
7388
/// <summary>
7489
/// Given a predicate specifying which columns are needed, return a predicate indicating which input columns are
7590
/// needed. The domain of the function is defined over the indices of the columns of <see cref="ISchema.ColumnCount"/>
@@ -82,9 +97,9 @@ public interface IRowToRowMapper : ISchematized
8297
/// The active columns are those for which <paramref name="active"/> returns true. Getting values on inactive
8398
/// columns of the returned row will throw. Null predicates are disallowed.
8499
///
85-
/// The <see cref="ISchematized.Schema"/> of <paramref name="input"/> should be the same object as
100+
/// The <see cref="IRow.Schema"/> of <paramref name="input"/> should be the same object as
86101
/// <see cref="InputSchema"/>. Implementors of this method should throw if that is not the case. Conversely,
87-
/// the returned value must have the same schema as <see cref="ISchematized.Schema"/>.
102+
/// the returned value must have the same schema as <see cref="OutputSchema"/>.
88103
///
89104
/// This method creates a live connection between the input <see cref="IRow"/> and the output <see
90105
/// cref="IRow"/>. In particular, when the getters of the output <see cref="IRow"/> are invoked, they invoke the

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ public RoleMappedSchema(Schema schema, string label, string feature,
467467
/// <summary>
468468
/// Encapsulates an <see cref="IDataView"/> plus a corresponding <see cref="RoleMappedSchema"/>.
469469
/// Note that the schema of <see cref="RoleMappedSchema.Schema"/> of <see cref="Schema"/> is
470-
/// guaranteed to equal the the <see cref="ISchematized.Schema"/> of <see cref="Data"/>.
470+
/// guaranteed to equal the the <see cref="IDataView.Schema"/> of <see cref="Data"/>.
471471
/// </summary>
472472
public sealed class RoleMappedData
473473
{
@@ -478,7 +478,7 @@ public sealed class RoleMappedData
478478

479479
/// <summary>
480480
/// The role mapped schema. Note that <see cref="Schema"/>'s <see cref="RoleMappedSchema.Schema"/> is
481-
/// guaranteed to be the same as <see cref="Data"/>'s <see cref="ISchematized.Schema"/>.
481+
/// guaranteed to be the same as <see cref="Data"/>'s <see cref="IDataView.Schema"/>.
482482
/// </summary>
483483
public RoleMappedSchema Schema { get; }
484484

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace Microsoft.ML.Data
1515
{
1616
/// <summary>
17-
/// This class represents the schema of an <see cref="ISchematized"/> object (like an <see cref="IDataView"/> or an <see cref="IRow"/>).
17+
/// This class represents the <see cref="Schema"/> of an object like, for interstance, an <see cref="IDataView"/> or an <see cref="IRow"/>.
1818
/// On the high level, the schema is a collection of 'columns'. Each column has the following properties:
1919
/// - Column name.
2020
/// - Column type.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ public static TScorerFactory GetScorerComponent(
306306

307307
ComponentCatalog.LoadableClassInfo info = null;
308308
ReadOnlyMemory<char> scoreKind = default;
309-
if (mapper.Schema.Count > 0 &&
310-
mapper.Schema.TryGetMetadata(TextType.Instance, MetadataUtils.Kinds.ScoreColumnKind, 0, ref scoreKind) &&
309+
if (mapper.OutputSchema.Count > 0 &&
310+
mapper.OutputSchema.TryGetMetadata(TextType.Instance, MetadataUtils.Kinds.ScoreColumnKind, 0, ref scoreKind) &&
311311
!scoreKind.IsEmpty)
312312
{
313313
var loadName = scoreKind.ToString();

src/Microsoft.ML.Data/Data/IRowSeekable.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using Microsoft.ML.Data;
56
using System;
67

78
namespace Microsoft.ML.Runtime.Data
@@ -11,9 +12,11 @@ namespace Microsoft.ML.Runtime.Data
1112
/// <summary>
1213
/// Represents a data view that supports random access to a specific row.
1314
/// </summary>
14-
public interface IRowSeekable : ISchematized
15+
public interface IRowSeekable
1516
{
1617
IRowSeeker GetSeeker(Func<int, bool> predicate);
18+
19+
Schema Schema { get; }
1720
}
1821

1922
/// <summary>

src/Microsoft.ML.Data/Data/ITransposeDataView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public interface ITransposeDataView : IDataView
2828
/// <summary>
2929
/// An enhanced schema, containing information on the transposition properties, if any,
3030
/// of each column. Note that there is no contract or suggestion that this property
31-
/// should be equal to <see cref="ISchematized.Schema"/>.
31+
/// should be equal to <see cref="IDataView.Schema"/>.
3232
/// </summary>
3333
ITransposeSchema TransposeSchema { get; }
3434

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public IRowToRowMapper GetRowToRowMapper(Schema inputSchema)
227227
for (int i = 0; i < mappers.Length; ++i)
228228
{
229229
mappers[i] = _transformers[i].GetRowToRowMapper(schema);
230-
schema = mappers[i].Schema;
230+
schema = mappers[i].OutputSchema;
231231
}
232232
return new CompositeRowToRowMapper(inputSchema, mappers);
233233
}

0 commit comments

Comments
 (0)