protected virtual string GetCacheKey() { var page = PortalContext.Current.Page; var pagePath = page == null ? string.Empty : page.Path; return(OutputCache.GetCacheKey(this.CustomCacheKey, pagePath, this.ClientID, this.CacheByPath, this.CacheByParams, this.CacheByLanguage)); }
// Internals ////////////////////////////////////////////////////////////// private void InsertOutputIntoCache(string output) { AddPortletDependency(); var cacheDependency = (this.Dependencies.Count > 1) ? new AggregateCacheDependency() : ((this.Dependencies.Count > 0) ? this.Dependencies[0] : null); if (this.Dependencies.Count > 1) { foreach (var dep in this.Dependencies) { ((AggregateCacheDependency)cacheDependency).Add(dep); } } this._dependencies = null; var od = new OutputCacheData { Output = output, ScriptReferences = CachedScripts, StyleSheetReferences = CachedStyleSheets }; OutputCache.InsertOutputIntoCache(AbsoluteExpiration, SlidingExpirationMinutes, GetCacheKey(), od, cacheDependency); }
// A helper method should one want to add new serialized type arrays void WriteSerializedBytes(string filePath, string varName, object data) { byte[] bytes; using (var ms = new MemoryStream()) { OutputCache.Serialize(ms, data); ms.Flush(); bytes = ms.GetBuffer(); if (bytes == null) { return; } using (var sw = File.AppendText(filePath)) { sw.Write("byte[] {0} = {{", varName); bool first = true; foreach (byte b in bytes) { if (first) { first = false; } else { sw.Write(","); } sw.Write("0x{0:X}", b); } sw.WriteLine("};"); } } }
byte[] SerializeElement(ResponseElement e) { using (var ms = new MemoryStream()) { OutputCache.Serialize(ms, e); ms.Flush(); return(ms.GetBuffer()); } }
internal static void ResetOutputCache() { if (OutputCache == null) { OutputCache = Kernel.Get <OutputCache>(); } OutputCache.Reset("App.OutputCacheKey", Guid.NewGuid().ToString()); }
protected override Delegate MakeGetter(Row input, int iinfo, Func<int, bool> activeOutput, out Action disposer) { disposer = null; Host.AssertValue(input); //Host.Assert(typeof(T) == _outputItemRawType); var outputCache = new OutputCache(); var activeOutputColNames = _parent.Outputs.Where((x, i) => activeOutput(i)).ToArray(); var type = OnnxUtils.OnnxToMlNetType(_parent.Model.ModelInfo.OutputsInfo[iinfo].Type).RawType; Host.Assert(type == _parent.OutputTypes[iinfo].ItemType.RawType); var srcNamedValueGetters = GetNamedOnnxValueGetters(input, _parent.Inputs, _inputColIndices, _isInputVector, _inputOnnxTypes, _inputTensorShapes); return Utils.MarshalInvoke(MakeGetter<int>, type, input, iinfo, srcNamedValueGetters, activeOutputColNames, outputCache); }
private bool CheckCachedOutput() { // if the output was once read from the cache and contains anything the function returns with true // if it is empty or null it returns with false if (IsCacheRead) { return(!String.IsNullOrEmpty(CachedOutput)); } // if the output was not read from the cache, we load the cached value // if the cached value is empty or null, we return false, otherwise true CachedOutput = OutputCache.GetCachedOutput(this.GetCacheKey()); IsCacheRead = true; return(!String.IsNullOrEmpty(CachedOutput)); }
public static void RemoveOutputCacheItem(string path, string providerName) { if (path == null) { throw new ArgumentNullException("path"); } if (path.Length > 0 && path [0] != '/') { throw new ArgumentException("Invalid path for HttpResponse.RemoveOutputCacheItem: '" + path + "'. An absolute virtual path is expected"); } OutputCache.RemoveFromProvider(path, providerName); }
public void Deserialize() { AssertExtensions.Throws <ArgumentNullException> (() => { OutputCache.Deserialize(null); }, "#A1"); foreach (object o in serializeObjects) { using (var m = new MemoryStream(SerializeToBinary(o))) { AssertExtensions.Throws <ArgumentException> (() => { OutputCache.Deserialize(m); }, String.Format("#A2-{0}", o.GetType())); } } MemoryResponseElement mre, mreOrig; FileResponseElement fre, freOrig; SubstitutionResponseElement sre, sreOrig, sreBad, sreBadOrig; MemoryStream ms; CreateElements(out mre, out fre, out sre, out sreBad); using (ms = new MemoryStream(memoryResponseElement)) mreOrig = OutputCache.Deserialize(ms) as MemoryResponseElement; Assert.IsNotNull(mreOrig, "#B1-1"); AssertExtensions.AreEqual(mreOrig.Buffer, mre.Buffer, "#B1-2"); Assert.AreEqual(mreOrig.Length, mre.Length, "#B1-3"); using (ms = new MemoryStream(fileResponseElement)) freOrig = OutputCache.Deserialize(ms) as FileResponseElement; Assert.IsNotNull(freOrig, "#C1-1"); Assert.AreEqual(freOrig.Length, fre.Length, "#C1-2"); Assert.AreEqual(freOrig.Offset, fre.Offset, "#C1-3"); Assert.AreEqual(freOrig.Path, fre.Path, "#C1-4"); using (ms = new MemoryStream(substitutionResponseElement)) sreOrig = OutputCache.Deserialize(ms) as SubstitutionResponseElement; Assert.IsNotNull(sreOrig); Assert.AreEqual(sreOrig.Callback, sre.Callback, "#D1"); // Callback here is not a static method - Substitution delegates must be static AssertExtensions.Throws <ArgumentException> (() => { using (ms = new MemoryStream(badSubstitutionResponseElement)) sreBadOrig = OutputCache.Deserialize(ms) as SubstitutionResponseElement; }, "#E1"); }
protected override Delegate MakeGetter(DataViewRow input, int iinfo, Func <int, bool> activeOutput, out Action disposer) { disposer = null; Host.AssertValue(input); var outputCache = new OutputCache(); var activeOutputColNames = _parent.Outputs.Where((x, i) => activeOutput(i)).ToArray(); var type = Tf2MlNetType(_parent.TFOutputTypes[iinfo]).RawType; Host.Assert(type == _parent.OutputTypes[iinfo].GetItemType().RawType); var srcTensorGetters = GetTensorValueGetters(input, _inputColIndices, _isInputVector, _parent.TFInputTypes, _fullySpecifiedShapes); return(Utils.MarshalInvoke(MakeGetter <int>, type, input, iinfo, srcTensorGetters, activeOutputColNames, outputCache)); }
public void Serialize() { ResponseElement data = new MemoryResponseElement(new byte[10], 10); AssertExtensions.Throws <ArgumentNullException> (() => { OutputCache.Serialize(null, data); }, "#A1"); var ms = new MemoryStream(); AssertExtensions.Throws <ArgumentException> (() => { OutputCache.Serialize(ms, null); }, "#A2"); foreach (object o in serializeObjects) { AssertExtensions.Throws <ArgumentException> (() => { OutputCache.Serialize(ms, o); }, String.Format("#A3-{0}", o.GetType())); } MemoryResponseElement mre; FileResponseElement fre; SubstitutionResponseElement sre, sreBad; CreateElements(out mre, out fre, out sre, out sreBad); // WriteSerializedBytes ("/tmp/bytes.txt", "memoryResponseElement", mre); // WriteSerializedBytes ("/tmp/bytes.txt", "fileResponseElement", fre); // WriteSerializedBytes ("/tmp/bytes.txt", "substitutionResponseElement", sre); // WriteSerializedBytes ("/tmp/bytes.txt", "badSubstitutionResponseElement", sreBad); byte[] bytes = SerializeElement(mre); AssertExtensions.AreEqual(bytes, memoryResponseElement, "#B1"); bytes = SerializeElement(fre); AssertExtensions.AreEqual(bytes, fileResponseElement, "#B2"); bytes = SerializeElement(sre); AssertExtensions.AreEqual(bytes, substitutionResponseElement, "#B3"); bytes = SerializeElement(sreBad); AssertExtensions.AreEqual(bytes, badSubstitutionResponseElement, "#B3"); }
internal override void ProcessOutputCacheDirective(string directiveName, IDictionary directive) { Util.GetAndRemoveBooleanAttribute(directive, "shared", ref this._fSharedPartialCaching); this._provider = Util.GetAndRemoveNonEmptyAttribute(directive, "providerName"); if (this._provider == "AspNetInternalProvider") { this._provider = null; } OutputCache.ThrowIfProviderNotFound(this._provider); string andRemoveNonEmptyAttribute = Util.GetAndRemoveNonEmptyAttribute(directive, "sqldependency"); if (andRemoveNonEmptyAttribute != null) { SqlCacheDependency.ValidateOutputCacheDependencyString(andRemoveNonEmptyAttribute, false); base.OutputCacheParameters.SqlDependency = andRemoveNonEmptyAttribute; } base.ProcessOutputCacheDirective(directiveName, directive); }
OutputCacheProvider GetProvider() { string providerName = ProviderName; OutputCacheProvider provider; if (String.IsNullOrEmpty(providerName)) { provider = OutputCache.DefaultProvider; } else { provider = OutputCache.GetProvider(providerName); if (provider == null) { provider = OutputCache.DefaultProvider; } } return(provider); }
protected virtual void InsertOutputIntoCache(string output) { var dep = new AggregateCacheDependency(); // Add application Id dep.Add(new NodeIdDependency(this.Id)); // Add contextNode dep.Add(new NodeIdDependency(PortalContext.Current.ContextNodeHead.Id)); if (WithChildren) { foreach (var node in PortalContext.Current.ContextNode.PhysicalChildArray) { dep.Add(new NodeIdDependency(node.Id)); } } OutputCache.InsertOutputIntoCache(AbsoluteExpiration, SlidingExpirationMinutes, GetCacheKey(), output, dep); }
// Internals ////////////////////////////////////////////////////////////// private void InsertOutputIntoCache(string output) { AddPortletDependency(); var cacheDependency = (this.Dependencies.Count > 1) ? new AggregateCacheDependency() : ((this.Dependencies.Count > 0) ? this.Dependencies[0] : null); if (this.Dependencies.Count > 1) { foreach (var dep in this.Dependencies) { ((AggregateCacheDependency)cacheDependency).Add(dep); } } this._dependencies = null; OutputCache.InsertOutputIntoCache(AbsoluteExpiration, SlidingExpirationMinutes, this.GetCacheKey(), output, cacheDependency, CacheItemPriority.Normal); }
private Delegate[] MakeGetters(IRow input, Func <int, bool> activeOutput) { _host.AssertValue(input); var outputCache = new OutputCache(); var activeOutputColNames = _parent.Outputs.Where((x, i) => activeOutput(i)).ToArray(); var valueGetters = new List <Delegate>(); for (int i = 0; i < _parent.Outputs.Length; i++) { if (activeOutput(i)) { var type = TFTensor.TypeFromTensorType(_parent.TFOutputTypes[i]); _host.Assert(type == _parent.OutputTypes[i].ItemType.RawType); var srcTensorGetters = GetTensorValueGetters(input); valueGetters.Add(Utils.MarshalInvoke(MakeGetter <int>, type, input, i, srcTensorGetters, activeOutputColNames, outputCache)); } } return(valueGetters.ToArray()); }
private void AddCachedReferences() { if (!Cacheable) { return; } var cachedData = OutputCache.GetCachedData(GetCacheKey()); if (cachedData == null) { return; } if (cachedData.ScriptReferences != null) { // add all cached script references foreach (var reference in cachedData.ScriptReferences) { UITools.AddScript(reference); } } if (cachedData.StyleSheetReferences != null) { var header = UITools.GetHeader(); // add all cached stylesheet references foreach (var reference in cachedData.StyleSheetReferences) { UITools.AddStyleSheetToHeader(header, reference.CssPath, reference.Order, reference.Rel, reference.Type, reference.Media, reference.Title, reference.AllowBundlingIfEnabled); } } }
/* * Process the contents of the <%@ OutputCache ... %> directive */ internal override void ProcessOutputCacheDirective(string directiveName, IDictionary directive) { string sqlDependency; Util.GetAndRemoveBooleanAttribute(directive, "shared", ref _fSharedPartialCaching); _provider = Util.GetAndRemoveNonEmptyAttribute(directive, "providerName"); if (_provider == OutputCache.ASPNET_INTERNAL_PROVIDER_NAME) { _provider = null; } OutputCache.ThrowIfProviderNotFound(_provider); sqlDependency = Util.GetAndRemoveNonEmptyAttribute(directive, "sqldependency"); if (sqlDependency != null) { // Validate the sqldependency attribute SqlCacheDependency.ValidateOutputCacheDependencyString(sqlDependency, false); OutputCacheParameters.SqlDependency = sqlDependency; } base.ProcessOutputCacheDirective(directiveName, directive); }
private Delegate MakeGetter <T>(IRow input, int iinfo, ITensorValueGetter[] srcTensorGetters, string[] activeOutputColNames, OutputCache outputCache) { Host.AssertValue(input); ValueGetter <VBuffer <T> > valuegetter = (ref VBuffer <T> dst) => { UpdateCacheIfNeeded(input.Position, srcTensorGetters, activeOutputColNames, outputCache); var tensor = outputCache.Outputs[_parent.Outputs[iinfo]]; var editor = VBufferEditor.Create(ref dst, tensor.GetSize()); OnnxUtils.CopyTo(tensor, editor.Values); dst = editor.Commit(); }; return(valuegetter); }
internal override void InitRecursive(Control namingContainer) { HashCodeCombiner combinedHashCode = new HashCodeCombiner(); _cacheKey = ComputeNonVaryCacheKey(combinedHashCode); // Save the non-varying hash, so we don't need to recalculate it later _nonVaryHashCode = combinedHashCode.CombinedHash; PartialCachingCacheEntry cacheEntry = null; // Check if there is a cache entry for the non-varying key object tmpCacheEntry = OutputCache.GetFragment(_cacheKey, _provider); if (tmpCacheEntry != null) { ControlCachedVary cachedVary = tmpCacheEntry as ControlCachedVary; if (cachedVary != null) { string varyCachedKey = ComputeVaryCacheKey(combinedHashCode, cachedVary); // Check if there is a cache entry for the varying key cacheEntry = (PartialCachingCacheEntry)OutputCache.GetFragment(varyCachedKey, _provider); if (cacheEntry != null && cacheEntry._cachedVaryId != cachedVary.CachedVaryId) { cacheEntry = null; // explicitly remove the entry OutputCache.RemoveFragment(varyCachedKey, _provider); } } else { // If it wasn't a ControlCachedVary, it must be a PartialCachingCacheEntry cacheEntry = (PartialCachingCacheEntry)tmpCacheEntry; } } // If it's a cache miss, create the control and make it our child if (cacheEntry == null) { // Cache miss _cacheEntry = new PartialCachingCacheEntry(); _cachedCtrl = CreateCachedControl(); Controls.Add(_cachedCtrl); // Make sure the Page knows about us while the control's OnInit is called Page.PushCachingControl(this); base.InitRecursive(namingContainer); Page.PopCachingControl(); } else { // Cache hit _outputString = cacheEntry.OutputString; _cssStyleString = cacheEntry.CssStyleString; // If any calls to Register* API's were made when the control was run, // make them now to restore correct behavior (VSWhidbey 80907) if (cacheEntry.RegisteredClientCalls != null) { foreach (RegisterCallData registerCallData in cacheEntry.RegisteredClientCalls) { switch (registerCallData.Type) { case ClientAPIRegisterType.WebFormsScript: Page.RegisterWebFormsScript(); break; case ClientAPIRegisterType.PostBackScript: Page.RegisterPostBackScript(); break; case ClientAPIRegisterType.FocusScript: Page.RegisterFocusScript(); break; case ClientAPIRegisterType.ClientScriptBlocks: case ClientAPIRegisterType.ClientScriptBlocksWithoutTags: case ClientAPIRegisterType.ClientStartupScripts: case ClientAPIRegisterType.ClientStartupScriptsWithoutTags: Page.ClientScript.RegisterScriptBlock(registerCallData.Key, registerCallData.StringParam2, registerCallData.Type); break; case ClientAPIRegisterType.OnSubmitStatement: Page.ClientScript.RegisterOnSubmitStatementInternal(registerCallData.Key, registerCallData.StringParam2); break; case ClientAPIRegisterType.ArrayDeclaration: Page.ClientScript.RegisterArrayDeclaration(registerCallData.StringParam1, registerCallData.StringParam2); break; case ClientAPIRegisterType.HiddenField: Page.ClientScript.RegisterHiddenField(registerCallData.StringParam1, registerCallData.StringParam2); break; case ClientAPIRegisterType.ExpandoAttribute: Page.ClientScript.RegisterExpandoAttribute(registerCallData.StringParam1, registerCallData.StringParam2, registerCallData.StringParam3, false); break; case ClientAPIRegisterType.EventValidation: if (_registeredCallDataForEventValidation == null) { _registeredCallDataForEventValidation = new ArrayList(); } _registeredCallDataForEventValidation.Add(registerCallData); break; default: Debug.Assert(false); break; } } } base.InitRecursive(namingContainer); } }
private void UpdateCacheIfNeeded(long position, ITensorValueGetter[] srcTensorGetters, string[] activeOutputColNames, OutputCache outputCache) { if (outputCache.Position != position) { var inputTensors = new List <Tensor>(); for (int i = 0; i < _inputColIndices.Length; i++) { inputTensors.Add(srcTensorGetters[i].GetTensor()); } var outputTensors = _parent.Model.Run(inputTensors); Contracts.Assert(outputTensors.Count > 0); for (int j = 0; j < outputTensors.Count; j++) { outputCache.Outputs[activeOutputColNames[j]] = outputTensors[j]; } outputCache.Position = position; } }
private Delegate MakeGetter <T>(DataViewRow input, int iinfo, INamedOnnxValueGetter[] srcNamedValueGetters, string[] activeOutputColNames, OutputCache outputCache) { Host.AssertValue(input); ValueGetter <VBuffer <T> > valuegetter = (ref VBuffer <T> dst) => { UpdateCacheIfNeeded(input.Position, srcNamedValueGetters, activeOutputColNames, outputCache); var namedOnnxValue = outputCache.Outputs[_parent.Outputs[iinfo]]; var denseTensor = namedOnnxValue.AsTensor <T>() as System.Numerics.Tensors.DenseTensor <T>; if (denseTensor == null) { throw Host.Except($"Output column {namedOnnxValue.Name} doesn't contain a DenseTensor of expected type {typeof(T)}"); } var editor = VBufferEditor.Create(ref dst, (int)denseTensor.Length); denseTensor.Buffer.Span.CopyTo(editor.Values); dst = editor.Commit(); }; return(valuegetter); }
/// <internalonly/> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> protected internal override void Render(HtmlTextWriter output) { CacheDependency sqlCacheDep = null; // If the output is cached, use it and do nothing else if (_outputString != null) { output.Write(_outputString); RegisterValidationEvents(); return; } // If caching was turned off, just render the control if (_cachingDisabled || !RuntimeConfig.GetAppConfig().OutputCache.EnableFragmentCache) { _cachedCtrl.RenderControl(output); return; } // Create SQL cache dependency before we render the page if (_sqlDependency != null) { sqlCacheDep = SqlCacheDependency.CreateOutputCacheDependency(_sqlDependency); } _cacheEntry.CssStyleString = GetCssStyleRenderString(output.GetType()); // Create a new HtmlTextWriter, with the same type as the current one (see ASURT 118922) StringWriter tmpWriter = new StringWriter(); HtmlTextWriter tmpHtmlWriter = Page.CreateHtmlTextWriterFromType(tmpWriter, output.GetType()); CacheDependency cacheDep; TextWriter savedWriter = Context.Response.SwitchWriter(tmpWriter); try { // Make sure the Page knows about us while the control's OnPreRender is called Page.PushCachingControl(this); _cachedCtrl.RenderControl(tmpHtmlWriter); Page.PopCachingControl(); } finally { Context.Response.SwitchWriter(savedWriter); } _cacheEntry.OutputString = tmpWriter.ToString(); // Send the output to the response output.Write(_cacheEntry.OutputString); // Cache the output cacheDep = _cacheDependency; if (sqlCacheDep != null) { if (cacheDep == null) { cacheDep = sqlCacheDep; } else { AggregateCacheDependency aggr = new AggregateCacheDependency(); aggr.Add(cacheDep); aggr.Add(sqlCacheDep); cacheDep = aggr; } } ControlCachedVary cachedVary = null; string realItemCacheKey; // If there are no varies, use the non-varying key if (_varyByParamsCollection == null && _varyByControlsCollection == null && _varyByCustom == null) { realItemCacheKey = _cacheKey; } else { string[] varyByParams = null; if (_varyByParamsCollection != null) { varyByParams = _varyByParamsCollection.GetParams(); } cachedVary = new ControlCachedVary(varyByParams, _varyByControlsCollection, _varyByCustom); HashCodeCombiner combinedHashCode = new HashCodeCombiner(_nonVaryHashCode); realItemCacheKey = ComputeVaryCacheKey(combinedHashCode, cachedVary); } // Compute the correct expiration, sliding or absolute DateTime utcExpirationTime; TimeSpan slidingExpiration; if (_useSlidingExpiration) { utcExpirationTime = Cache.NoAbsoluteExpiration; slidingExpiration = _utcExpirationTime - DateTime.UtcNow; } else { utcExpirationTime = _utcExpirationTime; slidingExpiration = Cache.NoSlidingExpiration; } try { OutputCache.InsertFragment(_cacheKey, cachedVary, realItemCacheKey, _cacheEntry, cacheDep /*dependencies*/, utcExpirationTime, slidingExpiration, _provider); } catch { if (cacheDep != null) { cacheDep.Dispose(); } throw; } }
private void UpdateCacheIfNeeded(long position, ITensorValueGetter[] srcTensorGetters, string[] activeOutputColNames, OutputCache outputCache) { if (outputCache.Position != position) { var runner = _parent.Session.GetRunner(); for (int i = 0; i < _inputColIndices.Length; i++) { var inputName = _parent.Inputs[i]; runner.AddInput(inputName, srcTensorGetters[i].GetTensor()); } var tensors = runner.Fetch(activeOutputColNames).Run(); Contracts.Assert(tensors.Length > 0); for (int j = 0; j < tensors.Length; j++) { outputCache.Outputs[activeOutputColNames[j]] = tensors[j]; } outputCache.Position = position; } }
private void UpdateCacheIfNeeded(long position, INamedOnnxValueGetter[] srcNamedOnnxValueGetters, string[] activeOutputColNames, OutputCache outputCache) { if (outputCache.Position != position) { var inputNameOnnxValues = new List <NamedOnnxValue>(); for (int i = 0; i < _inputColIndices.Length; i++) { inputNameOnnxValues.Add(srcNamedOnnxValueGetters[i].GetNamedOnnxValue()); } var outputNamedOnnxValues = _parent.Model.Run(inputNameOnnxValues); Contracts.Assert(outputNamedOnnxValues.Count > 0); foreach (var outputNameOnnxValue in outputNamedOnnxValues) { outputCache.Outputs[outputNameOnnxValue.Name] = outputNameOnnxValue; } outputCache.Position = position; } }
private Delegate MakeGetter <T>(IRow input, int iinfo, ITensorValueGetter[] srcTensorGetters, string[] activeOutputColNames, OutputCache outputCache) { _host.AssertValue(input); ValueGetter <VBuffer <T> > valuegetter = (ref VBuffer <T> dst) => { UpdateCacheIfNeeded(input.Position, srcTensorGetters, activeOutputColNames, outputCache); var values = dst.Values; var indices = dst.Indices; if (Utils.Size(values) < _parent.OutputTypes[iinfo].VectorSize) { values = new T[_parent.OutputTypes[iinfo].VectorSize]; indices = new int[_parent.OutputTypes[iinfo].VectorSize]; } TensorFlowUtils.FetchData <T>(outputCache.Outputs[_parent.Outputs[iinfo]].Data, values); dst = new VBuffer <T>(values.Length, values, indices); }; return(valuegetter); }
public void SetUp() { theOutputCache = new OutputCache(); }
private void UpdateCacheIfNeeded(long position, ITensorValueGetter[] srcTensorGetters, string[] activeOutputColNames, OutputCache outputCache) { if (outputCache.Position != position) { if (_parent.Graph.graph_key != tf.get_default_graph().graph_key) { _parent.Session.graph.as_default(); } Runner runner = new Runner(_parent.Session, _parent.Inputs.ToArray(), _parent.Outputs.ToArray()); // Feed inputs to the graph. for (int i = 0; i < _parent.Inputs.Length; i++) { runner.AddInput(srcTensorGetters[i].GetTensor(), i); } // Execute the graph. var tensors = runner.Run(); runner.Dispose(); Contracts.Assert(tensors.Length > 0); for (int j = 0; j < activeOutputColNames.Length; j++) { if (outputCache.Outputs.TryGetValue(activeOutputColNames[j], out Tensor outTensor)) { outTensor.Dispose(); } outputCache.Outputs[activeOutputColNames[j]] = tensors[j]; } outputCache.Position = position; } }
private Delegate MakeGetter <T>(DataViewRow input, int iinfo, ITensorValueGetter[] srcTensorGetters, string[] activeOutputColNames, OutputCache outputCache) where T : unmanaged { Host.AssertValue(input); if (_parent.OutputTypes[iinfo].IsStandardScalar()) { ValueGetter <T> valuegetter = (ref T dst) => { UpdateCacheIfNeeded(input.Position, srcTensorGetters, activeOutputColNames, outputCache); var tensor = outputCache.Outputs[_parent.Outputs[iinfo]]; tensor.ToScalar <T>(ref dst); }; return(valuegetter); } else { if (_parent.TFOutputTypes[iinfo] == TF_DataType.TF_STRING) { ValueGetter <VBuffer <T> > valuegetter = (ref VBuffer <T> dst) => { UpdateCacheIfNeeded(input.Position, srcTensorGetters, activeOutputColNames, outputCache); var tensor = outputCache.Outputs[_parent.Outputs[iinfo]]; var tensorSize = tensor.TensorShape.dims.Where(x => x > 0).Aggregate((x, y) => x * y); var editor = VBufferEditor.Create(ref dst, (int)tensorSize); FetchStringData(tensor, editor.Values); dst = editor.Commit(); }; return(valuegetter); } else { ValueGetter <VBuffer <T> > valuegetter = (ref VBuffer <T> dst) => { UpdateCacheIfNeeded(input.Position, srcTensorGetters, activeOutputColNames, outputCache); var tensor = outputCache.Outputs[_parent.Outputs[iinfo]]; var tensorSize = tensor.TensorShape.dims.Where(x => x > 0).Aggregate((x, y) => x * y); var editor = VBufferEditor.Create(ref dst, (int)tensorSize); tensor.CopyTo <T>(editor.Values); dst = editor.Commit(); }; return(valuegetter); } } }
private Delegate MakeGetter <T>(IRow input, int iinfo, ITensorValueGetter[] srcTensorGetters, string[] activeOutputColNames, OutputCache outputCache) { _host.AssertValue(input); ValueGetter <VBuffer <T> > valuegetter = (ref VBuffer <T> dst) => { UpdateCacheIfNeeded(input.Position, srcTensorGetters, activeOutputColNames, outputCache); var tensor = outputCache.Outputs[_parent.Outputs[iinfo]]; var tensorSize = tensor.Shape.Where(x => x > 0).Aggregate((x, y) => x * y); var values = dst.Values; if (Utils.Size(values) < tensorSize) { values = new T[tensorSize]; } TensorFlowUtils.FetchData <T>(tensor.Data, values); dst = new VBuffer <T>(values.Length, values, dst.Indices); }; return(valuegetter); }