예제 #1
0
        public sealed override DataViewRowCursor[] GetRowCursorSet(IEnumerable <DataViewSchema.Column> columnsNeeded, int n, Random rand = null)
        {
            Host.CheckValueOrNull(rand);

            var predicate = RowCursorUtils.FromColumnsToPredicate(columnsNeeded, OutputSchema);

            var inputCols = _bindings.GetDependencies(columnsNeeded);
            var inputs    = Source.GetRowCursorSet(inputCols, n, rand);

            Host.AssertNonEmpty(inputs);

            if (inputs.Length == 1 && n > 1 && WantParallelCursors(predicate))
            {
                inputs = DataViewUtils.CreateSplitCursors(Host, inputs[0], n);
            }
            Host.AssertNonEmpty(inputs);

            var cursors = new DataViewRowCursor[inputs.Length];
            var active  = _bindings.GetActive(predicate);

            for (int i = 0; i < inputs.Length; i++)
            {
                cursors[i] = new Cursor(Host, this, inputs[i], active);
            }
            return(cursors);
        }
예제 #2
0
        public sealed override IRowCursor[] GetRowCursorSet(out IRowCursorConsolidator consolidator,
                                                            Func <int, bool> predicate, int n, IRandom rand = null)
        {
            Host.CheckValue(predicate, nameof(predicate));
            Host.CheckValueOrNull(rand);

            var inputPred = _bindings.GetDependencies(predicate);
            var active    = _bindings.GetActive(predicate);
            var inputs    = Source.GetRowCursorSet(out consolidator, inputPred, n, rand);

            Host.AssertNonEmpty(inputs);

            if (inputs.Length == 1 && n > 1 && _bindings.AnyNewColumnsActive(predicate))
            {
                inputs = DataViewUtils.CreateSplitCursors(out consolidator, Host, inputs[0], n);
            }
            Host.AssertNonEmpty(inputs);

            var cursors = new IRowCursor[inputs.Length];

            for (int i = 0; i < inputs.Length; i++)
            {
                cursors[i] = new RowCursor(this, inputs[i], active);
            }
            return(cursors);
        }
예제 #3
0
        public override RowCursor[] GetRowCursorSet(IEnumerable <Schema.Column> columnsNeeded, int n, Random rand = null)
        {
            Host.CheckValueOrNull(rand);

            var predicate = RowCursorUtils.FromColumnsToPredicate(columnsNeeded, OutputSchema);

            var bindings = GetBindings();
            Func <int, bool> inputPred;
            Func <int, bool> predicateMapper;
            var active = GetActive(bindings, predicate, out inputPred, out predicateMapper);

            var inputCols = Source.Schema.Where(x => inputPred(x.Index));
            var inputs    = Source.GetRowCursorSet(inputCols, n, rand);

            Contracts.AssertNonEmpty(inputs);

            if (inputs.Length == 1 && n > 1 && WantParallelCursors(predicate) && (Source.GetRowCount() ?? int.MaxValue) > n)
            {
                inputs = DataViewUtils.CreateSplitCursors(Host, inputs[0], n);
            }
            Contracts.AssertNonEmpty(inputs);

            var cursors = new RowCursor[inputs.Length];

            for (int i = 0; i < inputs.Length; i++)
            {
                cursors[i] = new Cursor(Host, this, inputs[i], active, predicateMapper);
            }
            return(cursors);
        }
예제 #4
0
        public override RowCursor[] GetRowCursorSet(Func <int, bool> predicate, int n, Random rand = null)
        {
            Host.CheckValue(predicate, nameof(predicate));
            Host.CheckValueOrNull(rand);

            var bindings = GetBindings();
            Func <int, bool> predicateInput;
            Func <int, bool> predicateMapper;
            var active = GetActive(bindings, predicate, out predicateInput, out predicateMapper);
            var inputs = Source.GetRowCursorSet(predicateInput, n, rand);

            Contracts.AssertNonEmpty(inputs);

            if (inputs.Length == 1 && n > 1 && WantParallelCursors(predicate) && (Source.GetRowCount() ?? int.MaxValue) > n)
            {
                inputs = DataViewUtils.CreateSplitCursors(Host, inputs[0], n);
            }
            Contracts.AssertNonEmpty(inputs);

            var cursors = new RowCursor[inputs.Length];

            for (int i = 0; i < inputs.Length; i++)
            {
                cursors[i] = new Cursor(Host, this, inputs[i], active, predicateMapper);
            }
            return(cursors);
        }
예제 #5
0
        /// <summary>
        /// Create a set of cursors with additional active columns.
        /// </summary>
        /// <param name="additionalColumnsPredicate">Predicate that denotes which additional columns to include in the cursor,
        /// in addition to the columns that are needed for populating the <typeparamref name="TRow"/> object.</param>
        /// <param name="n">Number of cursors to create</param>
        /// <param name="rand">Random generator to use</param>
        public RowCursor <TRow>[] GetCursorSet(Func <int, bool> additionalColumnsPredicate, int n, Random rand)
        {
            _host.CheckValue(additionalColumnsPredicate, nameof(additionalColumnsPredicate));
            _host.CheckValueOrNull(rand);

            var inputs = _data.GetRowCursorSet(_data.Schema.Where(col => _columnIndices.Contains(col.Index) || additionalColumnsPredicate(col.Index)), n, rand);

            _host.AssertNonEmpty(inputs);

            if (inputs.Length == 1 && n > 1)
            {
                inputs = DataViewUtils.CreateSplitCursors(_host, inputs[0], n);
            }
            _host.AssertNonEmpty(inputs);

            return(inputs
                   .Select(rc => (RowCursor <TRow>)(new RowCursorImplementation(new TypedCursor(this, rc))))
                   .ToArray());
        }
예제 #6
0
        /// <summary>
        /// Create a set of cursors with additional active columns.
        /// </summary>
        /// <param name="consolidator">The consolidator for the original row cursors</param>
        /// <param name="additionalColumnsPredicate">Predicate that denotes which additional columns to include in the cursor,
        /// in addition to the columns that are needed for populating the <typeparamref name="TRow"/> object.</param>
        /// <param name="n">Number of cursors to create</param>
        /// <param name="rand">Random generator to use</param>
        public IRowCursor <TRow>[] GetCursorSet(out IRowCursorConsolidator consolidator,
                                                Func <int, bool> additionalColumnsPredicate, int n, IRandom rand)
        {
            _host.CheckValue(additionalColumnsPredicate, nameof(additionalColumnsPredicate));
            _host.CheckValueOrNull(rand);

            Func <int, bool> inputPredicate = col => _columnIndices.Contains(col) || additionalColumnsPredicate(col);
            var inputs = _data.GetRowCursorSet(out consolidator, inputPredicate, n, rand);

            _host.AssertNonEmpty(inputs);

            if (inputs.Length == 1 && n > 1)
            {
                inputs = DataViewUtils.CreateSplitCursors(out consolidator, _host, inputs[0], n);
            }
            _host.AssertNonEmpty(inputs);

            return(inputs
                   .Select(rc => (IRowCursor <TRow>)(new TypedCursor(this, rc)))
                   .ToArray());
        }