コード例 #1
0
        private TransposeLoader(IHost host, ModelLoadContext ctx, IMultiStreamSource file)
        {
            Contracts.CheckValue(host, nameof(host));
            _host = host;
            _host.CheckValue(file, nameof(file));
            _host.Check(file.Count == 1, "Transposed loader accepts a single file only");

            // *** Binary format **
            // int: Number of threads if explicitly defined, or 0 if the
            //      number of threads was automatically determined

            _threads = ctx.Reader.ReadInt32();
            _host.CheckDecode(_threads >= 0);

            // Dedupe code somehow?
            _file = file;
            using (Stream stream = _file.Open(0))
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    _header = InitHeader(reader);
                    reader.Seek(_header.SubIdvTableOffset);
                    _schemaEntry = new SubIdvEntry.SchemaSubIdv(this, reader);
                    _entries     = new SubIdvEntry.TransposedSubIdv[_header.ColumnCount];
                    for (int c = 0; c < _entries.Length; ++c)
                    {
                        _entries[c] = new SubIdvEntry.TransposedSubIdv(this, reader, c);
                    }
                    _schema = new SchemaImpl(this);
                    if (!HasRowData)
                    {
                        _colTransposers     = new Transposer[_header.ColumnCount];
                        _colTransposersLock = new object();
                    }
                }
        }
コード例 #2
0
        private TransposeLoader(IHost host, ModelLoadContext ctx, IDataView schemaView)
        {
            Contracts.CheckValue(host, nameof(host));
            _host = host;
            _host.CheckValue(schemaView, nameof(schemaView));

            // *** Binary format **
            // int: Number of threads if explicitly defined, or 0 if the
            //      number of threads was automatically determined

            _threads = ctx.Reader.ReadInt32();
            _host.CheckDecode(_threads >= 0);

            _header = new Header()
            {
                ColumnCount = schemaView.Schema.ColumnCount
            };
            _schemaEntry = new SubIdvEntry.SchemaSubIdv(this, schemaView);
            _host.Assert(_schemaEntry.GetViewOrNull() == schemaView);
            _entries = new SubIdvEntry.TransposedSubIdv[_header.ColumnCount];
            for (int c = 0; c < _entries.Length; ++c)
            {
                _entries[c] = new SubIdvEntry.TransposedSubIdv(this, c);
                _host.Assert(_entries[c].GetViewOrNull() == null);
            }
            _host.Assert(HasRowData);
        }
コード例 #3
0
        public TransposeLoader(IHostEnvironment env, Arguments args, IMultiStreamSource file)
        {
            Contracts.CheckValue(env, nameof(env));
            _host = env.Register(LoadName);
            _host.CheckValue(args, nameof(args));
            _host.CheckValue(file, nameof(file));
            _host.Check(file.Count == 1, "Transposed loader accepts a single file only");

            _threads = args.Threads ?? 0;
            if (_threads < 0)
            {
                _threads = 0;
            }

            _file = file;
            using (Stream stream = _file.Open(0))
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    _header = InitHeader(reader);
                    reader.Seek(_header.SubIdvTableOffset);
                    _schemaEntry = new SubIdvEntry.SchemaSubIdv(this, reader);
                    _entries     = new SubIdvEntry.TransposedSubIdv[_header.ColumnCount];
                    for (int c = 0; c < _entries.Length; ++c)
                    {
                        _entries[c] = new SubIdvEntry.TransposedSubIdv(this, reader, c);
                    }
                    _schema = new SchemaImpl(this);
                    if (!HasRowData)
                    {
                        _colTransposers     = new Transposer[_header.ColumnCount];
                        _colTransposersLock = new object();
                    }
                }
        }