Skip to content

Commit e672ece

Browse files
committed
ISchemaBoundRowMapper does not inherit from IRowToRowMapper, but from IRowToRowMapperBase.
Renaming ISchemaBoundRowMapper.GetDependencies to GetDependenciesForNewColumns
1 parent 4773889 commit e672ece

File tree

14 files changed

+39
-50
lines changed

14 files changed

+39
-50
lines changed

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

+9-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ namespace Microsoft.ML.Data
1616
/// so to rebind, the same input column names must be used.
1717
/// Implementations of this interface are typically created over defined input <see cref="DataViewSchema"/>.
1818
/// </summary>
19-
public interface IRowToRowMapper
19+
public interface IRowToRowMapper : IRowToRowMapperBase
20+
{
21+
/// <summary>
22+
/// Given a set of columns, return the input columns that are needed to generate those output columns.
23+
/// </summary>
24+
IEnumerable<DataViewSchema.Column> GetDependencies(IEnumerable<DataViewSchema.Column> dependingColumns);
25+
}
26+
27+
public interface IRowToRowMapperBase
2028
{
2129
/// <summary>
2230
/// Mappers are defined as accepting inputs with this very specific schema.
@@ -28,11 +36,6 @@ public interface IRowToRowMapper
2836
/// </summary>
2937
DataViewSchema OutputSchema { get; }
3038

31-
/// <summary>
32-
/// Given a set of columns, return the input columns that are needed to generate those output columns.
33-
/// </summary>
34-
IEnumerable<DataViewSchema.Column> GetDependencies(IEnumerable<DataViewSchema.Column> dependingColumns);
35-
3639
/// <summary>
3740
/// Get an <see cref="DataViewRow"/> with the indicated active columns, based on the input <paramref name="input"/>.
3841
/// The active columns are those for which <paramref name="active"/> returns true. Getting values on inactive

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Microsoft.ML.Data
1818
/// features column. New predictors can implement <see cref="ISchemaBindableMapper"/> directly. Implementing <see cref="ISchemaBindableMapper"/>
1919
/// includes implementing a corresponding <see cref="ISchemaBoundMapper"/> (or <see cref="ISchemaBoundRowMapper"/>) and a corresponding ISchema
2020
/// for the output schema of the <see cref="ISchemaBoundMapper"/>. In case the <see cref="ISchemaBoundRowMapper"/> interface is implemented,
21-
/// the SimpleRow class can be used in the <see cref="IRowToRowMapper.GetRow"/> method.
21+
/// the SimpleRow class can be used in the <see cref="IRowToRowMapperBase.GetRow"/> method.
2222
/// </summary>
2323
[BestFriend]
2424
internal interface ISchemaBindableMapper
@@ -58,12 +58,17 @@ internal interface ISchemaBoundMapper
5858
/// This interface combines <see cref="ISchemaBoundMapper"/> with <see cref="IRowToRowMapper"/>.
5959
/// </summary>
6060
[BestFriend]
61-
internal interface ISchemaBoundRowMapper : ISchemaBoundMapper, IRowToRowMapper
61+
internal interface ISchemaBoundRowMapper : ISchemaBoundMapper, IRowToRowMapperBase
6262
{
6363
/// <summary>
6464
/// There are two schemas from <see cref="ISchemaBoundMapper"/> and <see cref="IRowToRowMapper"/>.
6565
/// Since the two parent schema's are identical in all derived classes, we merge them into <see cref="OutputSchema"/>.
6666
/// </summary>
6767
new DataViewSchema OutputSchema { get; }
68+
69+
/// <summary>
70+
/// Given a set of columns, from the newly generated ones, return the input columns that are needed to generate those output columns.
71+
/// </summary>
72+
IEnumerable<DataViewSchema.Column> GetDependenciesForNewColumns(IEnumerable<DataViewSchema.Column> dependingColumns);
6873
}
6974
}

src/Microsoft.ML.Data/Prediction/Calibrator.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -618,10 +618,10 @@ public Bound(IHostEnvironment env, SchemaBindableCalibratedModelParameters<TSubM
618618
/// <summary>
619619
/// Given a set of columns, return the input columns that are needed to generate those output columns.
620620
/// </summary>
621-
IEnumerable<DataViewSchema.Column> IRowToRowMapper.GetDependencies(IEnumerable<DataViewSchema.Column> dependingColumns)
621+
IEnumerable<DataViewSchema.Column> ISchemaBoundRowMapper.GetDependenciesForNewColumns(IEnumerable<DataViewSchema.Column> dependingColumns)
622622
{
623623
if (dependingColumns.Count() > 0)
624-
return _predictor.GetDependencies(OutputSchema);
624+
return _predictor.GetDependenciesForNewColumns(OutputSchema);
625625

626626
return Enumerable.Empty<DataViewSchema.Column>();
627627
}

src/Microsoft.ML.Data/Scorers/FeatureContributionCalculation.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public RowMapper(IHostEnvironment env, BindableMapper parent, RoleMappedSchema s
352352
/// <summary>
353353
/// Returns the input columns needed for the requested output columns.
354354
/// </summary>
355-
IEnumerable<DataViewSchema.Column> IRowToRowMapper.GetDependencies(IEnumerable<DataViewSchema.Column> dependingColumns)
355+
IEnumerable<DataViewSchema.Column> ISchemaBoundRowMapper.GetDependenciesForNewColumns(IEnumerable<DataViewSchema.Column> dependingColumns)
356356
{
357357
if (dependingColumns.Count() == 0)
358358
return Enumerable.Empty<DataViewSchema.Column>();

src/Microsoft.ML.Data/Scorers/MultiClassClassifierScorer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ private DataViewSchema DecorateOutputSchema(DataViewSchema partialSchema, int sc
330330
/// <summary>
331331
/// Given a set of columns, return the input columns that are needed to generate those output columns.
332332
/// </summary>
333-
IEnumerable<DataViewSchema.Column> IRowToRowMapper.GetDependencies(IEnumerable<DataViewSchema.Column> dependingColumns)
334-
=> _mapper.GetDependencies(dependingColumns);
333+
IEnumerable<DataViewSchema.Column> ISchemaBoundRowMapper.GetDependenciesForNewColumns(IEnumerable<DataViewSchema.Column> dependingColumns)
334+
=> _mapper.GetDependenciesForNewColumns(dependingColumns);
335335

336336
public IEnumerable<KeyValuePair<RoleMappedSchema.ColumnRole, string>> GetInputColumnRoles() => _mapper.GetInputColumnRoles();
337337

src/Microsoft.ML.Data/Scorers/RowToRowScorerBase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private static bool[] GetActive(BindingsBase bindings,
9898

9999
// Get the active output columns
100100
var activeOutputCols = bindings.RowMapper.OutputSchema.Where(c => localMapper(c.Index));
101-
var colsInputForMapper = bindings.RowMapper.GetDependencies(activeOutputCols);
101+
var colsInputForMapper = bindings.RowMapper.GetDependenciesForNewColumns(activeOutputCols);
102102

103103
var activeInCols = bindings.Input.Where(c => c.Index < activeInput.Length && activeInput[c.Index]);
104104
inputColumns = activeInCols.Union(colsInputForMapper);

src/Microsoft.ML.Data/Scorers/SchemaBindablePredictorWrapper.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,12 @@ public SingleValueRowMapper(RoleMappedSchema schema, SchemaBindablePredictorWrap
218218
/// <summary>
219219
/// Given a set of columns, return the input columns that are needed to generate those output columns.
220220
/// </summary>
221-
IEnumerable<DataViewSchema.Column> IRowToRowMapper.GetDependencies(IEnumerable<DataViewSchema.Column> dependingColumns)
221+
IEnumerable<DataViewSchema.Column> ISchemaBoundRowMapper.GetDependenciesForNewColumns(IEnumerable<DataViewSchema.Column> dependingColumns)
222222
{
223223
if (!InputRoleMappedSchema.Feature.HasValue || dependingColumns.Count() == 0)
224224
return Enumerable.Empty<DataViewSchema.Column>();
225225

226-
return InputSchema.Where(col => col.Index == InputRoleMappedSchema.Feature.Value.Index);
226+
return Enumerable.Repeat(InputRoleMappedSchema.Feature.Value, 1); ;
227227
}
228228

229229
public IEnumerable<KeyValuePair<RoleMappedSchema.ColumnRole, string>> GetInputColumnRoles()
@@ -502,13 +502,13 @@ public CalibratedRowMapper(RoleMappedSchema schema, SchemaBindableBinaryPredicto
502502
/// <summary>
503503
/// Given a set of columns, return the input columns that are needed to generate those output columns.
504504
/// </summary>
505-
IEnumerable<DataViewSchema.Column> IRowToRowMapper.GetDependencies(IEnumerable<DataViewSchema.Column> dependingColumns)
505+
IEnumerable<DataViewSchema.Column> ISchemaBoundRowMapper.GetDependenciesForNewColumns(IEnumerable<DataViewSchema.Column> dependingColumns)
506506
{
507507

508508
if (dependingColumns.Count() == 0 || !InputRoleMappedSchema.Feature.HasValue)
509509
return Enumerable.Empty<DataViewSchema.Column>();
510510

511-
return InputSchema.Where(col => col.Index == InputRoleMappedSchema.Feature.Value.Index);
511+
return Enumerable.Repeat(InputRoleMappedSchema.Feature.Value, 1);
512512
}
513513

514514
public IEnumerable<KeyValuePair<RoleMappedSchema.ColumnRole, string>> GetInputColumnRoles()

src/Microsoft.ML.Data/Transforms/ColumnBindingsBase.cs

+5-24
Original file line numberDiff line numberDiff line change
@@ -587,19 +587,13 @@ protected virtual void GetMetadataCore<TValue>(string kind, int iinfo, ref TValu
587587
/// predicate on each column index.
588588
/// </summary>
589589
public bool[] GetActive(Func<int, bool> predicate)
590-
{
591-
return Utils.BuildArray(ColumnCount, predicate);
592-
}
590+
=> Utils.BuildArray(ColumnCount, predicate);
593591

594592
/// <summary>
595-
/// The given predicate maps from output column index to whether the column is active.
596-
/// This builds an array of bools of length ColumnCount containing the results of calling
597-
/// predicate on each column index.
593+
/// This builds an array of bools of length ColumnCount indicating the index of the active column.
598594
/// </summary>
599595
public bool[] GetActive(IEnumerable<DataViewSchema.Column> columns)
600-
{
601-
return Utils.BuildArray(ColumnCount, columns);
602-
}
596+
=> Utils.BuildArray(ColumnCount, columns);
603597

604598
/// <summary>
605599
/// The given predicate maps from output column index to whether the column is active.
@@ -622,9 +616,8 @@ public bool[] GetActiveInput(Func<int, bool> predicate)
622616
}
623617

624618
/// <summary>
625-
/// The given predicate maps from output column index to whether the column is active.
626-
/// This builds an array of bools of length Input.ColumnCount containing the results of calling
627-
/// predicate on the output column index corresponding to each input column index.
619+
/// This builds an array of bools of length Input.ColumnCount containing indicating the index of the
620+
/// active input columns, given the actual columns.
628621
/// </summary>
629622
public bool[] GetActiveInput(IEnumerable<DataViewSchema.Column> inputColumns)
630623
{
@@ -788,18 +781,6 @@ public bool[] GetActiveInput(Func<int, bool> predicate)
788781
}
789782
return active;
790783
}
791-
792-
/// <summary>
793-
/// The given predicate maps from output column index to whether the column is active.
794-
/// This builds an array of bools of length Input.ColumnCount containing the results of calling
795-
/// predicate on the output column index corresponding to each input column index.
796-
/// </summary>
797-
public bool[] GetActiveInput(IEnumerable<DataViewSchema.Column> activeColumns)
798-
{
799-
Contracts.AssertValue(activeColumns);
800-
var predicate = RowCursorUtils.FromColumnsToPredicate(activeColumns, Schema);
801-
return GetActiveInput(predicate);
802-
}
803784
}
804785

805786
/// <summary>

src/Microsoft.ML.Data/Transforms/NopTransform.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal sealed class NopTransform : IDataTransform, IRowToRowMapper
2727

2828
public IDataView Source { get; }
2929

30-
DataViewSchema IRowToRowMapper.InputSchema => Source.Schema;
30+
DataViewSchema IRowToRowMapperBase.InputSchema => Source.Schema;
3131

3232
/// <summary>
3333
/// Creates a NopTransform if the input is not an IDataTransform.

src/Microsoft.ML.Ensemble/PipelineEnsemble.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public BoundBase(SchemaBindablePipelineEnsembleBase parent, RoleMappedSchema sch
9393
/// <summary>
9494
/// Given a set of columns, return the input columns that are needed to generate those output columns.
9595
/// </summary>
96-
IEnumerable<DataViewSchema.Column> IRowToRowMapper.GetDependencies(IEnumerable<DataViewSchema.Column> dependingColumns)
96+
IEnumerable<DataViewSchema.Column> ISchemaBoundRowMapper.GetDependenciesForNewColumns(IEnumerable<DataViewSchema.Column> dependingColumns)
9797
{
9898
if (dependingColumns.Count() == 0)
9999
return Enumerable.Empty<DataViewSchema.Column>();
@@ -138,7 +138,7 @@ internal override Delegate CreateScoreGetter(DataViewRow input, out Action dispo
138138
// First get the output row from the pipelines. The input predicate of the predictor
139139
// is the output predicate of the pipeline.
140140
var mapperColumns = Mappers[i].OutputSchema.Where(col => col.Name == DefaultColumnNames.Score);
141-
var inputColumns = Mappers[i].GetDependencies(mapperColumns);
141+
var inputColumns = Mappers[i].GetDependenciesForNewColumns(mapperColumns);
142142

143143
Func<int, bool> inputPredicate = c => inputColumns.Any(col => col.Index == c);
144144
var pipelineRow = BoundPipelines[i].GetRow(input, inputPredicate);
@@ -185,7 +185,7 @@ public ValueGetter<Single> GetWeightGetter(DataViewRow input, int i, out Action
185185
}
186186
var weightCol = Mappers[i].InputRoleMappedSchema.Weight.Value;
187187
// The weight should be in the output row of the i'th pipeline if it exists.
188-
var inputColumns = Mappers[i].GetDependencies(Enumerable.Repeat(weightCol, 1));
188+
var inputColumns = Mappers[i].GetDependenciesForNewColumns(Enumerable.Repeat(weightCol, 1));
189189

190190
Func<int, bool> inputPredicate = c => inputColumns.Any(col => col.Index == c);
191191
var pipelineRow = BoundPipelines[i].GetRow(input, inputPredicate);

src/Microsoft.ML.FastTree/TreeEnsembleFeaturizer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ private void EnsureCachedPosition()
333333
/// <summary>
334334
/// Given a set of columns, return the input columns that are needed to generate those output columns.
335335
/// </summary>
336-
public IEnumerable<DataViewSchema.Column> GetDependencies(IEnumerable<DataViewSchema.Column> dependingColumns)
336+
public IEnumerable<DataViewSchema.Column> GetDependenciesForNewColumns(IEnumerable<DataViewSchema.Column> dependingColumns)
337337
{
338338
if (dependingColumns.Count() == 0)
339339
return Enumerable.Empty<DataViewSchema.Column>();

src/Microsoft.ML.Recommender/MatrixFactorizationPredictor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public RowMapper(IHostEnvironment env, MatrixFactorizationModelParameters parent
337337
/// <summary>
338338
/// Given a set of columns, return the input columns that are needed to generate those output columns.
339339
/// </summary>
340-
public IEnumerable<DataViewSchema.Column> GetDependencies(IEnumerable<DataViewSchema.Column> dependingColumns)
340+
public IEnumerable<DataViewSchema.Column> GetDependenciesForNewColumns(IEnumerable<DataViewSchema.Column> dependingColumns)
341341
{
342342
if (dependingColumns.Count() == 0)
343343
return Enumerable.Empty<DataViewSchema.Column>();

src/Microsoft.ML.StandardLearners/FactorizationMachine/FieldAwareFactorizationMachineUtils.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public DataViewRow GetRow(DataViewRow input, Func<int, bool> predicate)
136136
/// <summary>
137137
/// Given a set of columns, return the input columns that are needed to generate those output columns.
138138
/// </summary>
139-
IEnumerable<DataViewSchema.Column> IRowToRowMapper.GetDependencies(IEnumerable<DataViewSchema.Column> columns)
139+
IEnumerable<DataViewSchema.Column> ISchemaBoundRowMapper.GetDependenciesForNewColumns(IEnumerable<DataViewSchema.Column> columns)
140140
{
141141
if (columns.Count() == 0)
142142
return Enumerable.Empty<DataViewSchema.Column>();

src/Microsoft.ML.TimeSeries/SequentialTransformerBase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ void ISaveAsPfa.SaveAsPfa(BoundPfaContext ctx)
784784
return GetActive(predicate);
785785
}
786786

787-
DataViewSchema IRowToRowMapper.InputSchema => Source.Schema;
787+
DataViewSchema IRowToRowMapperBase.InputSchema => Source.Schema;
788788

789789
public DataViewRow GetRow(DataViewRow input, Func<int, bool> active)
790790
{

0 commit comments

Comments
 (0)