public void CacheWithSeekerSetup()
        {
            var col = _cacheDataView.Schema.GetColumnOrNull("A").Value;

            _seeker = ((IRowSeekable)_cacheDataView).GetSeeker(colIndex => colIndex == col.Index);
            _getter = _seeker.GetGetter <int>(col.Index);
        }
Beispiel #2
0
        public void Setup()
        {
            var ctx     = new MLContext(1);
            var builder = new ArrayDataViewBuilder(ctx);

            int[] values = new int[Length];
            for (int i = 0; i < values.Length; ++i)
            {
                values[i] = i;
            }
            builder.AddColumn("A", NumberDataViewType.Int32, values);
            var dv      = builder.GetDataView();
            var cacheDv = ctx.Data.Cache(dv);

            var col = cacheDv.Schema.GetColumnOrNull("A").Value;

            // First do one pass through.
            using (var cursor = cacheDv.GetRowCursor(col))
            {
                var getter = cursor.GetGetter <int>(col);
                int val    = 0;
                int count  = 0;
                while (cursor.MoveNext())
                {
                    getter(ref val);
                    if (val != cursor.Position)
                    {
                        throw new Exception($"Unexpected value {val} at {cursor.Position}");
                    }
                    count++;
                }
                if (count != Length)
                {
                    throw new Exception($"Expected {Length} values in cache but only saw {count}");
                }
            }
            _cacheDataView = cacheDv;

            // Only needed for seeker, but may as well set it.
            _positions = new long[Length];
            var rand = new Random(0);

            for (int i = 0; i < _positions.Length; ++i)
            {
                _positions[i] = rand.Next(Length);
            }

            _col          = _cacheDataView.Schema["A"];
            _seeker       = ((IRowSeekable)_cacheDataView).GetSeeker(colIndex => colIndex == _col.Index);
            _seekerGetter = _seeker.GetGetter <int>(_col);
        }