示例#1
0
            public ShakeInputCursor(ShakeInputState <TInput> view, IRowCursor cursor, Func <int, bool> predicate,
                                    Arguments args, int column, IValueMapper[] toShake, TInput[][] shakingValues,
                                    Func <TOutput, TOutput, TOutput> aggregation)
            {
                _view        = view;
                _args        = args;
                _inputCursor = cursor;
                _toShake     = toShake;
                _inputGetter = cursor.GetGetter <VBuffer <TInput> >(column);

                _mappersV = _toShake.Select(c => !c.OutputType.IsVector()
                                ? null
                                : c.GetMapper <VBuffer <TInput>, VBuffer <TOutput> >()).ToArray();
                _mappers = _toShake.Select(c => c.OutputType.IsVector()
                                ? null
                                : c.GetMapper <VBuffer <TInput>, TOutput>()).ToArray();

                for (int i = 0; i < _mappers.Length; ++i)
                {
                    if (_mappers[i] == null && _mappersV[i] == null)
                    {
                        throw Contracts.Except("Type mismatch.");
                    }
                }
                _shakingValues = shakingValues;
                _collected     = new VBuffer <TOutput> [_toShake.Length];
                _aggregation   = aggregation;
            }
示例#2
0
        private IDataTransform CreateTemplatedTransform()
        {
            IDataTransform transform = null;

            int index;

            if (!_input.Schema.TryGetColumnIndex(_args.inputColumn, out index))
            {
                throw _host.Except("Unable to find '{0}'", _args.inputColumn);
            }

            var typeCol = _input.Schema.GetColumnType(index);

            if (!typeCol.IsVector())
            {
                throw _host.Except("Expected a vector as input.");
            }
            typeCol = typeCol.AsVector().ItemType();

            switch (typeCol.RawKind())
            {
            case DataKind.R4:
                transform = new ShakeInputState <float>(_host, transform ?? Source, _toShake, _args);
                break;

            case DataKind.BL:
                transform = new ShakeInputState <bool>(_host, transform ?? Source, _toShake, _args);
                break;

            case DataKind.U1:
                transform = new ShakeInputState <Byte>(_host, transform ?? Source, _toShake, _args);
                break;

            case DataKind.U2:
                transform = new ShakeInputState <UInt16>(_host, transform ?? Source, _toShake, _args);
                break;

            case DataKind.U4:
                transform = new ShakeInputState <UInt32>(_host, transform ?? Source, _toShake, _args);
                break;

            default:
                throw Contracts.ExceptNotSupp("Type '{0}' is not handled yet.", typeCol.RawKind());
            }
            return(transform);
        }
        private IDataTransform CreateTemplatedTransform()
        {
            IDataTransform transform = null;

            int index   = SchemaHelper.GetColumnIndex(_input.Schema, _args.inputColumn);
            var typeCol = _input.Schema[index].Type;

            if (!typeCol.IsVector())
            {
                throw _host.Except("Expected a vector as input.");
            }
            typeCol = typeCol.AsVector().ItemType();

            switch (typeCol.RawKind())
            {
            case DataKind.Single:
                transform = new ShakeInputState <float>(_host, transform ?? Source, _toShake, _args);
                break;

            case DataKind.Boolean:
                transform = new ShakeInputState <bool>(_host, transform ?? Source, _toShake, _args);
                break;

            case DataKind.SByte:
                transform = new ShakeInputState <Byte>(_host, transform ?? Source, _toShake, _args);
                break;

            case DataKind.UInt16:
                transform = new ShakeInputState <UInt16>(_host, transform ?? Source, _toShake, _args);
                break;

            case DataKind.UInt32:
                transform = new ShakeInputState <UInt32>(_host, transform ?? Source, _toShake, _args);
                break;

            default:
                throw Contracts.ExceptNotSupp("Type '{0}' is not handled yet.", typeCol.RawKind());
            }
            return(transform);
        }