Exemplo n.º 1
0
        private UngroupTransform(IHost host, ModelLoadContext ctx, IDataView input)
            : base(host, input)
        {
            Host.AssertValue(ctx);

            // *** Binary format ***
            // (binding)
            _ungroupBinding = UngroupBinding.Create(ctx, host, input.Schema);
        }
Exemplo n.º 2
0
        public UngroupTransform(IHostEnvironment env, Arguments args, IDataView input)
            : base(env, LoaderSignature, input)
        {
            Host.CheckValue(args, nameof(args));
            Host.CheckUserArg(Utils.Size(args.Column) > 0, nameof(args.Column), "There must be at least one pivot column");
            Host.CheckUserArg(args.Column.Distinct().Count() == args.Column.Length, nameof(args.Column),
                              "Duplicate pivot columns are not allowed");

            _ungroupBinding = new UngroupBinding(Host, Source.Schema, args.Mode, args.Column);
        }
Exemplo n.º 3
0
            public Cursor(IChannelProvider provider, RowCursor input, UngroupBinding schema, Func <int, bool> predicate)
                : base(provider, input)
            {
                _ungroupBinding = schema;
                _active         = Utils.BuildArray(_ungroupBinding.InputColumnCount, predicate);
                _cachedGetters  = new Delegate[_ungroupBinding.InputColumnCount];
                _colSizes       = new int[_ungroupBinding.InputColumnCount];

                int sizeColumnsLim = _ungroupBinding.Mode == UngroupMode.First ? 1 : _ungroupBinding.PivotColumnCount;

                _fixedSize = 0;
                var needed = new List <Func <int> >();

                for (int i = 0; i < sizeColumnsLim; i++)
                {
                    var info = _ungroupBinding.GetPivotColumnInfo(i);
                    if (info.Size > 0)
                    {
                        if (_fixedSize == 0)
                        {
                            _fixedSize = info.Size;
                        }
                        else if (_ungroupBinding.Mode == UngroupMode.Inner && _fixedSize > info.Size)
                        {
                            _fixedSize = info.Size;
                        }
                        else if (_ungroupBinding.Mode == UngroupMode.Outer && _fixedSize < info.Size)
                        {
                            _fixedSize = info.Size;
                        }
                    }
                    else
                    {
                        // This will also create and cache a getter for the pivot column.
                        // That's why MakeSizeGetter is an instance method.
                        var rawItemType             = info.ItemType.RawType;
                        Func <int, Func <int> > del = MakeSizeGetter <int>;
                        var mi         = del.GetMethodInfo().GetGenericMethodDefinition().MakeGenericMethod(rawItemType);
                        var sizeGetter = (Func <int>)mi.Invoke(this, new object[] { info.Index });
                        needed.Add(sizeGetter);
                    }
                }

                _sizeGetters = needed.ToArray();
                Ch.Assert(_fixedSize > 0 || _sizeGetters.Length > 0);
            }