예제 #1
0
            private static void SetupCursor(TextLoader parent, bool[] active, int n,
                                            out int srcNeeded, out int cthd)
            {
                // Note that files is allowed to be empty.
                Contracts.AssertValue(parent);
                Contracts.AssertValue(parent._files);
                Contracts.Assert(active == null || active.Length == parent._bindings.Infos.Length);

                var bindings = parent._bindings;

                // This ensures _srcNeeded is >= 0.
                int srcLim = 1;

                for (int i = 0; i < bindings.Infos.Length; i++)
                {
                    if (active != null && !active[i])
                    {
                        continue;
                    }
                    var info = bindings.Infos[i];
                    foreach (var seg in info.Segments)
                    {
                        if (srcLim < seg.Lim)
                        {
                            srcLim = seg.Lim;
                        }
                    }
                }

                if (srcLim > parent._inputSize && parent._inputSize > 0)
                {
                    srcLim = parent._inputSize;
                }
                srcNeeded = srcLim - 1;
                Contracts.Assert(srcNeeded >= 0);

                // Determine the number of threads to use.
                cthd = DataViewUtils.GetThreadCount(parent._host, n, !parent._useThreads);

                long cblkMax = parent._maxRows / BatchSize;

                if (cthd > cblkMax)
                {
                    cthd = Math.Max(1, (int)cblkMax);
                }
            }
예제 #2
0
        public IRowCursor[] GetRowCursorSet(out IRowCursorConsolidator consolidator, Func <int, bool> predicate, int n, IRandom rand = null)
        {
            var host = new ConsoleEnvironment().Register("Estimate n threads");

            n = DataViewUtils.GetThreadCount(host, n);

            if (n <= 1)
            {
                consolidator = null;
                return(new IRowCursor[] { GetRowCursor(predicate, rand) });
            }
            else
            {
                var cursors = Source.GetRowCursorSet(out consolidator, i => predicate(i) || predicate(SchemaHelper.NeedColumn(_columnMapping, i)),
                                                     n, rand);
                for (int i = 0; i < cursors.Length; ++i)
                {
                    cursors[i] = new AddRandomCursor(this, cursors[i]);
                }
                return(cursors);
            }
        }
예제 #3
0
        public DataViewRowCursor[] GetRowCursorSet(IEnumerable <DataViewSchema.Column> columnsNeeded, int n, Random rand = null)
        {
            n = DataViewUtils.GetThreadCount(n);

            if (n <= 1)
            {
                return new DataViewRowCursor[] { GetRowCursor(columnsNeeded, rand) }
            }
            ;
            else
            {
                //var cols = SchemaHelper.ColumnsNeeded(columnsNeeded, Schema, _args.columns);
                var cols = SchemaHelper.ColumnsNeeded(columnsNeeded, Source.Schema);

                var cursors = Source.GetRowCursorSet(cols, n, rand);
                for (int i = 0; i < cursors.Length; ++i)
                {
                    cursors[i] = new AddRandomCursor(this, cursors[i]);
                }
                return(cursors);
            }
        }