Esempio n. 1
0
        public static CommonOutputs.TransformOutput Group(IHostEnvironment env, GroupTransform.Arguments input)
        {
            Contracts.CheckValue(env, nameof(env));
            env.CheckValue(input, nameof(input));

            var h    = EntryPointUtils.CheckArgsAndCreateHost(env, "GroupTransform", input);
            var view = new GroupTransform(h, input, input.Data);

            return(new CommonOutputs.TransformOutput()
            {
                Model = new TransformModel(h, view, input.Data),
                OutputData = view
            });
        }
Esempio n. 2
0
            public Cursor(GroupTransform parent, Func <int, bool> predicate)
                : base(parent.Host)
            {
                Ch.AssertValue(predicate);

                _parent = parent;
                var schema = _parent._schema;

                _active     = Utils.BuildArray(schema.ColumnCount, predicate);
                _groupCount = schema.GroupIds.Length;

                bool[] srcActiveLeading = new bool[_parent.Source.Schema.ColumnCount];
                foreach (var col in schema.GroupIds)
                {
                    srcActiveLeading[col] = true;
                }
                _leadingCursor = parent.Source.GetRowCursor(x => srcActiveLeading[x]);

                bool[] srcActiveTrailing = new bool[_parent.Source.Schema.ColumnCount];
                for (int i = 0; i < _groupCount; i++)
                {
                    if (_active[i])
                    {
                        srcActiveTrailing[schema.GroupIds[i]] = true;
                    }
                }
                for (int i = 0; i < schema.KeepIds.Length; i++)
                {
                    if (_active[i + _groupCount])
                    {
                        srcActiveTrailing[schema.KeepIds[i]] = true;
                    }
                }
                _trailingCursor = parent.Source.GetRowCursor(x => srcActiveTrailing[x]);

                _groupCheckers = new GroupKeyColumnChecker[_groupCount];
                for (int i = 0; i < _groupCount; i++)
                {
                    _groupCheckers[i] = new GroupKeyColumnChecker(_leadingCursor, _parent._schema.GroupIds[i]);
                }

                _aggregators = new KeepColumnAggregator[_parent._schema.KeepIds.Length];
                for (int i = 0; i < _aggregators.Length; i++)
                {
                    if (_active[i + _groupCount])
                    {
                        _aggregators[i] = KeepColumnAggregator.Create(_trailingCursor, _parent._schema.KeepIds[i]);
                    }
                }
            }