public override ValueGetter <TValue> GetGetter <TValue>(int col)
 {
     if (col < _inputCursor.Schema.Count)
     {
         return(_inputCursor.GetGetter <TValue>(col));
     }
     else if (col - _inputCursor.Schema.Count >= _collected.Length)
     {
         throw Contracts.Except("Unexpected columns {0} > {1}.", col, _collected.Length + _inputCursor.Schema.Count);
     }
     return(GetBufferGetter(col) as ValueGetter <TValue>);
 }
예제 #2
0
            public SlotCursor(TransposeLoader parent, RowCursor cursor)
                : base(parent._host)
            {
                _parent = parent;
                Ch.AssertValue(cursor);
                Ch.Assert(cursor.Schema.Count == 1);
                Ch.Assert(cursor.Schema[0].Type.RawType == typeof(VBuffer <T>));
                Ch.Assert(cursor.Schema[0].Type is VectorType);
                _rowCursor = cursor;

                _getter = _rowCursor.GetGetter <VBuffer <T> >(0);
            }
 public PolynomialCursor(PolynomialState <TInput> view, RowCursor cursor, Func <int, bool> predicate,
                         Arguments args, int column, Func <TInput, TInput, TInput> multiplication)
 {
     if (!predicate(column))
     {
         throw view.Host.ExceptValue("Required column is not generated by previous layers.");
     }
     _view           = view;
     _args           = args;
     _inputCursor    = cursor;
     _inputGetter    = cursor.GetGetter <VBuffer <TInput> >(column);
     _multiplication = multiplication;
 }
        public void CacheWithCursor()
        {
            // This setup takes very less time to execute as compared to the actual _cursorGetter.
            // The most preferable position for this setup will be in GlobalSetup.
            _cursor       = _cacheDataView.GetRowCursor(colIndex => colIndex == _col.Index);
            _cursorGetter = _cursor.GetGetter <int>(_col.Index);

            int val = 0;

            while (_cursor.MoveNext())
            {
                _cursorGetter(ref val);
            }
        }
예제 #5
0
            public VecValueWriter(RowCursor cursor, VectorType type, int source, char sep)
                : base(type.ItemType, source, sep)
            {
                _getSrc = cursor.GetGetter <VBuffer <T> >(source);
                ColumnType typeNames;

                if (type.IsKnownSizeVector &&
                    (typeNames = cursor.Schema[source].Metadata.Schema.GetColumnOrNull(MetadataUtils.Kinds.SlotNames)?.Type) != null &&
                    typeNames.VectorSize == type.VectorSize && typeNames.ItemType.IsText)
                {
                    cursor.Schema[source].Metadata.GetValue(MetadataUtils.Kinds.SlotNames, ref _slotNames);
                    Contracts.Check(_slotNames.Length == typeNames.VectorSize, "Unexpected slot names length");
                }
                _slotCount = type.VectorSize;
            }
예제 #6
0
            public override ValueGetter <TValue> GetGetter <TValue>(int col)
            {
                _parent._groupBinding.CheckColumnInRange(col);
                if (!_active[col])
                {
                    throw Ch.ExceptParam(nameof(col), "Column #{0} is not active", col);
                }

                if (col < _groupCount)
                {
                    return(_trailingCursor.GetGetter <TValue>(_parent._groupBinding.GroupColumnIndexes[col]));
                }

                Ch.AssertValue(_aggregators[col - _groupCount]);
                return(_aggregators[col - _groupCount].GetGetter <TValue>(Ch));
            }
 /// <summary>
 /// Switches between the replaced column or the values coming
 /// from a view which has a column to be replaced,
 /// or the entire row (ConstantCol == -1, _otherValues).
 /// </summary>
 /// <typeparam name="TValue">column type</typeparam>
 /// <param name="col">column inde</param>
 /// <returns>ValueGetter</returns>
 public override ValueGetter <TValue> GetGetter <TValue>(int col)
 {
     if (_columns.ContainsKey(col))
     {
         return(GetGetterPrivate <TValue>(col) as ValueGetter <TValue>);
     }
     else if (_otherValues != null)
     {
         return(_otherValues.GetGetter <TValue>(col));
     }
     else
     {
         throw Contracts.Except("otherValues is null, unable to access other columns." +
                                "If you are using PrePostTransformPredictor, it means the preprossing transform cannot be " +
                                "converted into a IValueMapper because it relies on more than one columns.");
     }
 }
예제 #8
0
        public static Delegate GetColumnGetter(RowCursor cur, int col, Schema sch = null)
        {
            if (sch == null)
            {
                sch = cur.Schema;
            }
            var colType = sch[col].Type;

            if (colType.IsVector())
            {
                switch (colType.ItemType().RawKind())
                {
                case DataKind.BL: return(GetGetterChoice <VBufferEqSort <bool>, VBuffer <bool> >(cur, col));

                case DataKind.I4: return(GetGetterChoice <VBufferEqSort <int>, VBuffer <int> >(cur, col));

                case DataKind.U4: return(GetGetterChoice <VBufferEqSort <uint>, VBuffer <uint> >(cur, col));

                case DataKind.I8: return(GetGetterChoice <VBufferEqSort <long>, VBuffer <long> >(cur, col));

                case DataKind.R4: return(GetGetterChoice <VBufferEqSort <float>, VBuffer <float> >(cur, col));

                case DataKind.R8: return(GetGetterChoice <VBufferEqSort <double>, VBuffer <double> >(cur, col));

                case DataKind.TX: return(GetGetterChoice <VBufferEqSort <DvText>, VBuffer <DvText>, VBuffer <ReadOnlyMemory <char> > >(cur, col));

                default:
                    throw new NotImplementedException(string.Format("Not implemented for kind {0}", colType));
                }
            }
            else
            {
                switch (colType.RawKind())
                {
                case DataKind.BL: return(cur.GetGetter <bool>(col));

                case DataKind.I4: return(cur.GetGetter <int>(col));

                case DataKind.U4: return(cur.GetGetter <uint>(col));

                case DataKind.I8: return(cur.GetGetter <Int64>(col));

                case DataKind.R4: return(cur.GetGetter <float>(col));

                case DataKind.R8: return(cur.GetGetter <double>(col));

                case DataKind.TX: return(GetGetterChoice <DvText, ReadOnlyMemory <char> >(cur, col));

                default:
                    throw new NotImplementedException(string.Format("Not implemented for kind {0}", colType));
                }
            }
        }
예제 #9
0
        private void EstimatorCore <T>(RowCursor cursor, ColumnCodec col,
                                       out Func <long> fetchWriteEstimator, out IValueWriter writer)
        {
            ValueGetter <T> getter = cursor.GetGetter <T>(col.SourceIndex);
            IValueCodec <T> codec  = col.Codec as IValueCodec <T>;

            _host.AssertValue(codec);
            IValueWriter <T> specificWriter = codec.OpenWriter(Stream.Null);

            writer = specificWriter;
            T val = default(T);

            fetchWriteEstimator = () =>
            {
                getter(ref val);
                specificWriter.Write(in val);
                return(specificWriter.GetCommitLengthEstimate());
            };
        }
예제 #10
0
 public override ValueGetter <TValue> GetGetter <TValue>(int col)
 {
     if (col < _view.Source.Schema.Count)
     {
         return(_inputCursor.GetGetter <TValue>(col));
     }
     else if (col == _view.Source.Schema.Count) // Cluster
     {
         return(GetGetterCluster() as ValueGetter <TValue>);
     }
     else if (col == _view.Source.Schema.Count + 1) // Score
     {
         return(GetGetterScore() as ValueGetter <TValue>);
     }
     else
     {
         throw new IndexOutOfRangeException();
     }
 }
            public override ValueGetter <TValue> GetGetter <TValue>(int col)
            {
                // If the column is part of the input view.
                var schema = _inputCursor.Schema;

                if (col < schema.Count)
                {
                    return(_inputCursor.GetGetter <TValue>(col));
                }
                // If it is the added column.
                else if (col == schema.Count)
                {
                    return(PolynomialBuilder() as ValueGetter <TValue>);
                }
                // Otherwise, it is an error.
                else
                {
                    throw Contracts.Except("Unexpected columns {0} > {1}.", col, schema.Count);
                }
            }
예제 #12
0
        void LoadCache <TClass>(Random rand, RowCursor cur, int classColumn, TClass valueClass, IChannel ch)
        {
            _cacheReplica = new Dictionary <RowId, int>();
            var    hist  = new Dictionary <TClass, long>();
            var    gid   = cur.GetIdGetter();
            var    gcl   = cur.GetGetter <TClass>(classColumn);
            RowId  did   = default(RowId);
            TClass cl    = default(TClass);
            long   nbIn  = 0;
            long   nbOut = 0;
            int    rep;

            while (cur.MoveNext())
            {
                gcl(ref cl);
                gid(ref did);
                if (!hist.ContainsKey(cl))
                {
                    hist[cl] = 1;
                }
                else
                {
                    ++hist[cl];
                }
                if (cl.Equals(valueClass))
                {
                    rep = NextPoisson(_args.lambda, rand);
                    ++nbIn;
                }
                else
                {
                    rep = 1;
                    ++nbOut;
                }
                _cacheReplica[did] = rep;
            }
            if (nbIn == 0)
            {
                ch.Warning(MessageSensitivity.UserData, "Resample on a condition never happened: nbIn={0} nbOut={1}", nbIn, nbOut);
            }
        }
 public override ValueGetter <TValue> GetGetter <TValue>(int col)
 {
     if (col < _view.Source.Schema.Count)
     {
         return(_inputCursor.GetGetter <TValue>(col));
     }
     else if (col == _view.Source.Schema.Count) // Ordering
     {
         return(GetGetterOrdering() as ValueGetter <TValue>);
     }
     else if (col == _view.Source.Schema.Count + 1) // Reachability Distance
     {
         return(GetGetterReachabilityDistance() as ValueGetter <TValue>);
     }
     else if (col == _view.Source.Schema.Count + 2) // Core Distance
     {
         return(GetGetterCoreDistance() as ValueGetter <TValue>);
     }
     else
     {
         throw new IndexOutOfRangeException();
     }
 }
 public override ValueGetter <TValue> GetGetter <TValue>(int col)
 {
     if (col == _view.ConstantCol)
     {
         return(GetGetterPrivate(col) as ValueGetter <TValue>);
     }
     else if (_otherValues != null)
     {
         return(_otherValues.GetGetter <TValue>(col));
     }
     else if (_ignoreOtherColumn)
     {
         return (ref TValue value) =>
                {
                    value = default(TValue);
                }
     }
     ;
     else
     {
         throw Contracts.Except("otherValues is null, unable to access other columns.");
     }
 }
예제 #15
0
            public override ValueGetter <TValue> GetGetter <TValue>(int col)
            {
                if (col < _view.Source.Schema.Count)
                {
                    return(_inputCursor.GetGetter <TValue>(col));
                }
                else if (col < _view.Schema.Count)
                {
                    var colType = _schema[_view._columnMapping[col]].Type;
                    if (colType.IsVector())
                    {
                        switch (colType.ItemType().RawKind())
                        {
                        case DataKind.BL: return(GetGetterVector(col, false) as ValueGetter <TValue>);

                        case DataKind.I4: return(GetGetterVector(col, 0) as ValueGetter <TValue>);

                        case DataKind.U4: return(GetGetterVector(col, (uint)0) as ValueGetter <TValue>);

                        case DataKind.I8: return(GetGetterVector(col, (Int64)0) as ValueGetter <TValue>);

                        case DataKind.R4: return(GetGetterVector(col, 0f) as ValueGetter <TValue>);

                        case DataKind.R8: return(GetGetterVector(col, 0.0) as ValueGetter <TValue>);

                        case DataKind.TX: return(GetGetterVector(col, new ReadOnlyMemory <char>()) as ValueGetter <TValue>);

                        default:
                            throw Contracts.ExceptNotImpl($"Unsupported type '{colType.ItemType().RawKind()}'.");
                        }
                    }
                    else
                    {
                        switch (colType.RawKind())
                        {
                        case DataKind.BL: return(GetGetter(col, false) as ValueGetter <TValue>);

                        case DataKind.I4: return(GetGetter(col, 0) as ValueGetter <TValue>);

                        case DataKind.U4: return(GetGetter(col, (uint)0) as ValueGetter <TValue>);

                        case DataKind.I8: return(GetGetter(col, (Int64)0) as ValueGetter <TValue>);

                        case DataKind.R4: return(GetGetter(col, 0f) as ValueGetter <TValue>);

                        case DataKind.R8: return(GetGetter(col, 0.0) as ValueGetter <TValue>);

                        case DataKind.TX: return(GetGetter(col, new ReadOnlyMemory <char>()) as ValueGetter <TValue>);

                        default:
                            throw Contracts.ExceptNotImpl($"Unsupported type '{colType.ItemType().RawKind()}'.");
                        }
                    }
                }
                else
                {
                    throw _view._host.Except("Column index {0} does not exist.", col);
                }
            }
예제 #16
0
            public override ValueGetter <TValue> GetGetter <TValue>(int col)
            {
                int index = _mapper.GetInputIndex(col);

                return(_inputCursor.GetGetter <TValue>(index));
            }
예제 #17
0
 public ValueWriter(RowCursor cursor, PrimitiveType type, int source, char sep)
     : base(type, source, sep)
 {
     _getSrc     = cursor.GetGetter <T>(source);
     _columnName = cursor.Schema[source].Name;
 }
 public override ValueGetter <TValue> GetGetter <TValue>(int col)
 {
     return(_cursor.GetGetter <TValue>(col));
 }