/// <summary> /// Fills the coordinates and values of cells having non-zero values into the specified lists. /// Fills into the lists, starting at index 0. /// After this call returns the specified lists all have a new size, the number of non-zero values. /// </summary> /// <param name="indexList"> /// The list to be filled with indexes, can have any size. /// </param> /// <param name="valueList"> /// The list to be filled with values, can have any size. /// </param> public override void GetNonZeros(IntArrayList indexList, List <double> valueList) { bool fillIndexList = indexList != null; bool fillValueList = valueList != null; if (fillIndexList) { indexList.Clear(); } if (fillValueList) { valueList.Clear(); } AutoParallel.AutoParallelForEach(Elements, (e) => { if (fillIndexList) { indexList.Add(e.Key); } if (fillValueList) { valueList.Add(e.Value); } }); }
public void MergeFrom(RewriterConfig other) { if (other == null) { return; } if (other.OptimizeTensorLayout != false) { OptimizeTensorLayout = other.OptimizeTensorLayout; } if (other.DisableModelPruning != false) { DisableModelPruning = other.DisableModelPruning; } if (other.ConstantFolding != false) { ConstantFolding = other.ConstantFolding; } if (other.MemoryOptimization != 0) { MemoryOptimization = other.MemoryOptimization; } if (other.autoParallel_ != null) { if (autoParallel_ == null) { autoParallel_ = new global::Tensorflow.AutoParallelOptions(); } AutoParallel.MergeFrom(other.AutoParallel); } optimizers_.Add(other.optimizers_); }
public void Dispose() { var waitForThreads = false; lock (this._tasks) { if (!this._disposed) { GC.SuppressFinalize(this); this._disallowAdd = true; // wait for all tasks to finish processing while not allowing any more new tasks while (this._tasks.Count > 0) { Monitor.Wait(this._tasks); } this._disposed = true; Monitor.PulseAll(this._tasks); // wake all workers (none of them will be active at this point; disposed flag will cause then to finish so that we can join them) waitForThreads = true; } } if (waitForThreads) { AutoParallel.AutoParallelForEach(this._workers, (worker) => { worker.Join(); }); } }
public override int GetHashCode() { int hash = 1; if (OptimizeTensorLayout != false) { hash ^= OptimizeTensorLayout.GetHashCode(); } if (DisableModelPruning != false) { hash ^= DisableModelPruning.GetHashCode(); } if (ConstantFolding != false) { hash ^= ConstantFolding.GetHashCode(); } if (MemoryOptimization != 0) { hash ^= MemoryOptimization.GetHashCode(); } if (autoParallel_ != null) { hash ^= AutoParallel.GetHashCode(); } hash ^= optimizers_.GetHashCode(); return(hash); }
/// <summary> /// Assigns the result of a function to each cell; <tt>x[i] = function(x[i])</tt>. /// (Iterates downwards from <tt>[size()-1]</tt> to <tt>[0]</tt>). /// </summary> /// <param name="function"> /// A function taking as argument the current cell's value. /// </param> /// <returns> /// <tt>this</tt> (for convenience only). /// </returns> public override DoubleMatrix1D Assign(DoubleFunction function) { var indices = new int[Elements.Count]; Elements.Keys.CopyTo(indices, 0); AutoParallel.AutoParallelForEach(indices, (i) => { Elements[i] = function(Elements[i]); }); return(this); }
public TaskRunnerGroup(int size) { this._workers = new LinkedList <Thread>(); AutoParallel.AutoParallelFor(0, size, (i) => { var worker = new Thread(this.Worker) { Name = string.Concat("Worker ", i) }; worker.Start(); this._workers.AddLast(worker); }); }
/// <summary> /// Trim the excess items from the Dictionary /// </summary> /// <typeparam name="TKey"></typeparam> /// <typeparam name="TValue"></typeparam> /// <param name="dic"></param> /// <returns></returns> public static IDictionary <TKey, TValue> TrimExcess <TKey, TValue>(this IDictionary <TKey, TValue> dic) { var kv = new KeyValuePair <TKey, TValue> [dic.Count]; dic.CopyTo(kv, 0); List <KeyValuePair <TKey, TValue> > l = kv.ToList(); l.TrimExcess(); var newDic = new Dictionary <TKey, TValue>(l.Count); AutoParallel.AutoParallelForEach(l, (p) => { newDic.Add(p.Key, p.Value); }); return(newDic); }
public void MergeFrom(RewriterConfig other) { if (other == null) { return; } if (other.LayoutOptimizer != 0) { LayoutOptimizer = other.LayoutOptimizer; } if (other.ConstantFolding != 0) { ConstantFolding = other.ConstantFolding; } if (other.ArithmeticOptimization != 0) { ArithmeticOptimization = other.ArithmeticOptimization; } if (other.DependencyOptimization != 0) { DependencyOptimization = other.DependencyOptimization; } if (other.DisableModelPruning != false) { DisableModelPruning = other.DisableModelPruning; } if (other.MemoryOptimization != 0) { MemoryOptimization = other.MemoryOptimization; } if (other.MemoryOptimizerTargetNodeNamePrefix.Length != 0) { MemoryOptimizerTargetNodeNamePrefix = other.MemoryOptimizerTargetNodeNamePrefix; } if (other.autoParallel_ != null) { if (autoParallel_ == null) { autoParallel_ = new global::Tensorflow.AutoParallelOptions(); } AutoParallel.MergeFrom(other.AutoParallel); } optimizers_.Add(other.optimizers_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); }
public override int GetHashCode() { int hash = 1; if (LayoutOptimizer != 0) { hash ^= LayoutOptimizer.GetHashCode(); } if (ConstantFolding != 0) { hash ^= ConstantFolding.GetHashCode(); } if (ArithmeticOptimization != 0) { hash ^= ArithmeticOptimization.GetHashCode(); } if (DependencyOptimization != 0) { hash ^= DependencyOptimization.GetHashCode(); } if (DisableModelPruning != false) { hash ^= DisableModelPruning.GetHashCode(); } if (MemoryOptimization != 0) { hash ^= MemoryOptimization.GetHashCode(); } if (MemoryOptimizerTargetNodeNamePrefix.Length != 0) { hash ^= MemoryOptimizerTargetNodeNamePrefix.GetHashCode(); } if (autoParallel_ != null) { hash ^= AutoParallel.GetHashCode(); } hash ^= optimizers_.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
/// <summary> /// Applies a function to each cell and aggregates the results. /// </summary> /// <param name="aggr"> /// An aggregation function taking as first argument the current aggregation and as second argument the transformed current cell value. /// </param> /// <param name="f"> /// A function transforming the current cell value. /// </param> /// <returns> /// The aggregated measure. /// </returns> public override double Aggregate(DoubleDoubleFunction aggr, DoubleFunction f) { double result = double.NaN; bool first = true; AutoParallel.AutoParallelForEach(Elements.Values, (e) => { if (first) { first = false; result = f(e); } else { result = aggr(result, f(e)); } }); return(result); }
/// <summary> /// Assigns the result of a function to each <i>non-zero</i> cell; <tt>x[row,col] = function(x[row,col])</tt>. /// </summary> /// <param name="function"> /// A function taking as argument the current non-zero cell's row, column and value. /// </param> /// <returns> /// <tt>this</tt> (for convenience only). /// </returns> public override DoubleMatrix2D ForEachNonZero(IntIntDoubleFunction function) { if (IsView) { base.ForEachNonZero(function); } else { AutoParallel.AutoParallelForEach(Elements, (e) => { int i = e.Key / Columns; int j = e.Key & Columns; double r = function(i, j, e.Value); if (r != e.Value) { Elements[e.Key] = e.Value; } }); } return(this); }