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

Add bindings for RowImpl in time series SequentialTransformerBase #3875

Merged
merged 3 commits into from
Jun 18, 2019
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
25 changes: 15 additions & 10 deletions src/Microsoft.ML.TimeSeries/SequentialTransformerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ private protected virtual void CloneCore(TState state)
internal TState StateRef { get; set; }

public int StateRefCount;

/// <summary>
/// The main constructor for the sequential transform
/// </summary>
Expand Down Expand Up @@ -492,7 +491,7 @@ DataViewRow IRowToRowMapper.GetRow(DataViewRow input, IEnumerable<DataViewSchema
var active = RowCursorUtils.FromColumnsToPredicate(activeColumns, OutputSchema);
var getters = _mapper.CreateGetters(input, active, out Action disposer);
var pingers = _mapper.CreatePinger(input, active, out Action pingerDisposer);
return new RowImpl(_bindings.Schema, input, getters, pingers, disposer + pingerDisposer);
return new RowImpl(_bindings, input, getters, pingers, disposer + pingerDisposer);
}
}

Expand All @@ -504,23 +503,24 @@ private sealed class RowImpl : StatefulRow
private readonly Action<long> _pinger;
private readonly Action _disposer;
private bool _disposed;
private readonly ColumnBindings _bindings;

public override DataViewSchema Schema => _schema;

public override long Position => _input.Position;

public override long Batch => _input.Batch;

public RowImpl(DataViewSchema schema, DataViewRow input, Delegate[] getters, Action<long> pinger, Action disposer)
public RowImpl(ColumnBindings bindings, DataViewRow input, Delegate[] getters, Action<long> pinger, Action disposer)
{
Contracts.CheckValue(schema, nameof(schema));
Contracts.CheckValue(bindings, nameof(bindings));
Contracts.CheckValue(input, nameof(input));
Contracts.Check(Utils.Size(getters) == schema.Count);
_schema = schema;
_schema = bindings.Schema;
_input = input;
_getters = getters ?? new Delegate[0];
_pinger = pinger;
_disposer = disposer;
_bindings = bindings;
}

protected override void Dispose(bool disposing)
Expand All @@ -538,9 +538,13 @@ public override ValueGetter<DataViewRowId> GetIdGetter()

public override ValueGetter<T> GetGetter<T>(DataViewSchema.Column column)
{
Contracts.CheckParam(column.Index < _getters.Length, nameof(column), "Invalid col value in GetGetter");
bool isSrc;
int index = _bindings.MapColumnIndex(out isSrc, column.Index);
if (isSrc)
return _input.GetGetter<T>(_input.Schema[index]);
Contracts.CheckParam(index < _getters.Length, nameof(column), "Invalid col value in GetGetter");
Contracts.Check(IsColumnActive(column));
var fn = _getters[column.Index] as ValueGetter<T>;
var fn = _getters[index] as ValueGetter<T>;
if (fn == null)
throw Contracts.Except("Unexpected TValue in GetGetter");
return fn;
Expand All @@ -554,8 +558,9 @@ public override Action<long> GetPinger() =>
/// </summary>
public override bool IsColumnActive(DataViewSchema.Column column)
{
Contracts.Check(column.Index < _getters.Length);
return _getters[column.Index] != null;
int index = _bindings.MapColumnIndex(out bool isSrc, column.Index);
Contracts.Check(index < _getters.Length);
return _getters[index] != null;
}
}

Expand Down
1 change: 1 addition & 0 deletions test/Microsoft.ML.TimeSeries.Tests/TimeSeriesDirectApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ public void ChangePointDetectionWithSeasonalityPredictionEngine()

// Pipeline.
var pipeline = ml.Transforms.Text.FeaturizeText("Text_Featurized", "Text")
.Append(ml.Transforms.Conversion.ConvertType("Value", "Value", DataKind.Single))
.Append(new SsaChangePointEstimator(ml, new SsaChangePointDetector.Options()
{
Confidence = 95,
Expand Down