protected DataViewBase(IHostEnvironment env, string name, InternalSchemaDefinition schemaDefn)
            {
                Contracts.AssertValue(env);
                env.AssertNonWhiteSpace(name);
                Host = env.Register(name);
                Host.AssertValue(schemaDefn);

                _schemaDefn = schemaDefn;
                _schema     = new Schema(GetSchemaColumns(schemaDefn));
                int n = schemaDefn.Columns.Length;

                _peeks = new Delegate[n];
                for (var i = 0; i < n; i++)
                {
                    var currentColumn = schemaDefn.Columns[i];
                    _peeks[i] = currentColumn.IsComputed
                        ? currentColumn.Generator
                        : ApiUtils.GeneratePeek <DataViewBase <TRow>, TRow>(currentColumn);
                }
            }
Exemplo n.º 2
0
        protected LambdaTransformBase(IHostEnvironment env, string name, Action <BinaryWriter> saveAction, LambdaTransform.LoadDelegate loadFunc)
        {
            Contracts.AssertValue(env);
            env.AssertNonWhiteSpace(name);
            Host = env.Register(name);

            Host.Assert((saveAction == null) == (loadFunc == null));

            if (saveAction != null)
            {
                _saveAction = saveAction;
                // First, verify as best we can, that we can recover the function, by attempting to do it once.
                _loadFuncBytes = SerializableLambdaTransform.GetSerializedStaticDelegate(loadFunc);
                Exception error;
                var       recoveredLoadFunc = SerializableLambdaTransform.DeserializeStaticDelegateOrNull(Host, _loadFuncBytes, out error);
                if (recoveredLoadFunc == null)
                {
                    Host.AssertValue(error);
                    throw Host.Except(error, "Load function does not appear recoverable");
                }
            }

            AssertConsistentSerializable();
        }