public PolynomialCursor(PolynomialState <TInput> view, RowCursor cursor, Func <int, bool> predicate, Arguments args, int column, Func <TInput, TInput, TInput> multiplication) { if (!predicate(column)) { throw view.Host.ExceptValue("Required column is not generated by previous layers."); } _view = view; _args = args; _inputCursor = cursor; _inputGetter = cursor.GetGetter <VBuffer <TInput> >(column); _multiplication = multiplication; }
public PolynomialCursor(PolynomialState <TInput> view, DataViewRowCursor cursor, IEnumerable <DataViewSchema.Column> columnsNeeded, Arguments args, DataViewSchema.Column column, Func <TInput, TInput, TInput> multiplication) { if (!columnsNeeded.Where(c => c.Index == column.Index).Any()) { throw view.Host.ExceptValue("Required column is not generated by previous layers."); } _view = view; _args = args; _inputCursor = cursor; _inputGetter = cursor.GetGetter <VBuffer <TInput> >(column); _multiplication = multiplication; }
/// <summary> /// Create the internal transform (not serialized in the zip file). /// </summary> private IDataTransform CreateTemplatedTransform() { IDataTransform transform = null; // The column is a vector. int index = -1; var schema = _input.Schema; foreach (var col in _args.columns) { if (!schema.TryGetColumnIndex(col.Source, out index)) { throw _host.Except("Unable to find '{0}'", col.Source); } } if (_args.columns.Length != 1) { throw _host.Except("Only one column allowed not '{0}'.", _args.columns.Length); } var typeCol = schema.GetColumnType(index); if (!typeCol.IsVector()) { throw _host.Except("Expected a vector as input."); } typeCol = typeCol.AsVector().ItemType(); // We may consider multiple types here, vector of float, uint, int... // Let's do float and int. switch (typeCol.RawKind()) { case DataKind.R4: transform = new PolynomialState <float>(_host, transform ?? Source, _args, (a, b) => a * b); break; case DataKind.U4: transform = new PolynomialState <UInt32>(_host, transform ?? Source, _args, (a, b) => a * b); break; default: throw Contracts.ExceptNotSupp("Type '{0}' is not handled yet.", typeCol.RawKind()); } return(transform); }