public ExtendedCacheTransform(IHostEnvironment env, Arguments args, IDataView input)
            : base(env, RegistrationName, input)
        {
            Host.CheckValue(args, "args");
            Host.CheckUserArg(args.inDataFrame || !string.IsNullOrEmpty(args.cacheFile), "cacheFile cannot be empty if inDataFrame is false.");
            Host.CheckUserArg(!args.async || args.inDataFrame, "inDataFrame must be true if async is true.");
            Host.CheckUserArg(!args.numTheads.HasValue || args.numTheads > 0, "numThread must be > 0 if specified.");
            var saverSettings = args.saverSettings as ICommandLineComponentFactory;

            Host.CheckValue(saverSettings, nameof(saverSettings));
            _saverSettings = string.Format("{0}{{{1}}}", saverSettings.Name, saverSettings.GetSettingsString());
            _saverSettings = _saverSettings.Replace("{}", "");
            if (!_saverSettings.ToLower().StartsWith("binary"))
            {
                throw env.ExceptNotSupp("Only binary format is supported.");
            }
            _inDataFrame = args.inDataFrame;
            _cacheFile   = args.cacheFile;
            _reuse       = args.reuse;
            _async       = args.async;
            _numThreads  = args.numTheads;

            var saver = ComponentCreation.CreateSaver(Host, _saverSettings);

            if (saver == null)
            {
                throw Host.Except("Cannot parse '{0}'", _saverSettings);
            }

            _pipedTransform = CreatePipeline(env, input);
        }
Ejemplo n.º 2
0
        public SortInDataFrameTransform(IHostEnvironment env, Arguments args, IDataView input)
            : base(env, RegistrationName, input)
        {
            Host.CheckValue(args, "args");
            Host.CheckUserArg(!args.numThreads.HasValue || args.numThreads.Value > 0, "numThreads cannot be negative.");

            if (!string.IsNullOrEmpty(args.sortColumn))
            {
                var schema = input.Schema;
                int index  = SchemaHelper.GetColumnIndex(schema, args.sortColumn);
                var type   = schema[index].Type;
                Host.Check(!type.IsVector(), "sortColumn cannot be a vector.");
            }

            _reverse    = args.reverse;
            _sortColumn = args.sortColumn;
            _numThreads = args.numThreads;
            _transform  = CreateTemplatedTransform();
        }
Ejemplo n.º 3
0
        private SortInDataFrameTransform(IHost host, ModelLoadContext ctx, IDataView input) : base(host, input)
        {
            Host.CheckValue(input, "input");
            Host.CheckValue(ctx, "ctx");

            _sortColumn = ctx.Reader.ReadString();
            Host.AssertValue(_sortColumn);
            var schema = input.Schema;
            int index  = SchemaHelper.GetColumnIndex(schema, _sortColumn);
            var type   = schema[index].Type;

            Host.Check(!type.IsVector(), "sortColumn cannot be a vector.");
            _reverse    = ctx.Reader.ReadBoolean();
            _numThreads = ctx.Reader.ReadInt32();
            if (_numThreads < 0)
            {
                _numThreads = null;
            }
            _transform = CreateTemplatedTransform();
        }
        private ExtendedCacheTransform(IHost host, ModelLoadContext ctx, IDataView input) :
            base(host, input)
        {
            Host.CheckValue(input, "input");
            Host.CheckValue(ctx, "ctx");

            _inDataFrame = ctx.Reader.ReadBoolean();
            _async       = ctx.Reader.ReadBoolean();
            _numThreads  = ctx.Reader.ReadInt32();
            host.Check(_numThreads > -2, "_numThreads");
            if (_numThreads < 0)
            {
                _numThreads = null;
            }
            _saverSettings = ctx.Reader.ReadString();
            if (_inDataFrame)
            {
                _cacheFile = null;
                _reuse     = false;
            }
            else
            {
                _cacheFile = ctx.Reader.ReadString();
                _reuse     = ctx.Reader.ReadBoolean();
                host.CheckValue(_cacheFile, "_cacheFile");
            }

            var saver = ComponentCreation.CreateSaver(Host, _saverSettings);

            if (saver == null)
            {
                throw Host.Except("Cannot parse '{0}'", _saverSettings);
            }

            _pipedTransform = CreatePipeline(host, input);
        }