From 3f4297af2f5ce1c794ba17c8b7b1a8ade1282296 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Tue, 25 Feb 2020 15:35:45 -0800 Subject: [PATCH 1/4] remove unused methods from Utilities.cs --- com.unity.ml-agents/Runtime/Utilities.cs | 78 ------------------------ 1 file changed, 78 deletions(-) diff --git a/com.unity.ml-agents/Runtime/Utilities.cs b/com.unity.ml-agents/Runtime/Utilities.cs index 4bc78d8919..a518f19cc8 100644 --- a/com.unity.ml-agents/Runtime/Utilities.cs +++ b/com.unity.ml-agents/Runtime/Utilities.cs @@ -1,6 +1,5 @@ using System; using UnityEngine; -using System.Collections.Generic; namespace MLAgents { @@ -75,83 +74,6 @@ public static int[] CumSum(int[] input) return result; } - /// - /// Shifts list elements to the left by the specified amount (in-place). - /// - /// List whose elements will be shifted - /// - /// - /// Amount to shift the elements to the left by - /// - /// - public static void ShiftLeft(List list, int shiftAmount) - { - for (var i = shiftAmount; i < list.Count; i++) - { - list[i - shiftAmount] = list[i]; - } - } - - /// - /// Replaces target list elements with source list elements starting at specified position - /// in target list. - /// - /// Target list, where the elements are added to - /// - /// - /// Source array, where the elements are copied from - /// - /// - /// Starting position in target list to copy elements to - /// - /// - public static void ReplaceRange(List dst, List src, int start) - { - for (var i = 0; i < src.Count; i++) - { - dst[i + start] = src[i]; - } - } - - /// - /// Adds elements to list without extra temp allocations (assuming it fits pre-allocated - /// capacity of the list). The built-in List/.AddRange() unfortunately allocates - /// a temporary list to add items (even if the original array has sufficient capacity): - /// https://stackoverflow.com/questions/2123161/listt-addrange-implementation-suboptimal - /// Note: this implementation might be slow with a large source array. - /// - /// Target list, where the elements are added to - /// - /// - /// Source array, where the elements are copied from - /// - /// - // ReSharper disable once ParameterTypeCanBeEnumerable.Global - public static void AddRangeNoAlloc(List dst, T[] src) - { - // ReSharper disable once LoopCanBeConvertedToQuery - foreach (var item in src) - { - dst.Add(item); - } - } - - /// - /// Calculates the number of uncompressed floats in a list of ISensor - /// - public static int GetSensorFloatObservationSize(this List sensors) - { - int numFloatObservations = 0; - for (var i = 0; i < sensors.Count; i++) - { - if (sensors[i].GetCompressionType() == SensorCompressionType.None) - { - numFloatObservations += sensors[i].ObservationSize(); - } - } - return numFloatObservations; - } - #if DEBUG internal static void DebugCheckNanAndInfinity(float value, string valueCategory, string caller) { From fd543e983715c68c04c4e6b60880aa5a024d5eb5 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Tue, 25 Feb 2020 15:39:09 -0800 Subject: [PATCH 2/4] changelog --- com.unity.ml-agents/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.ml-agents/CHANGELOG.md b/com.unity.ml-agents/CHANGELOG.md index 0ffffa0c17..bb6b11e453 100755 --- a/com.unity.ml-agents/CHANGELOG.md +++ b/com.unity.ml-agents/CHANGELOG.md @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - The method `GetStepCount()` on the Agent class has been replaced with the property getter `StepCount` - `RayPerceptionSensorComponent` and related classes now display the debug gizmos whenever the Agent is selected (not just Play mode). - Most fields on `RayPerceptionSensorComponent` can now be changed while the editor is in Play mode. The exceptions to this are fields that affect the number of observations. + - Unused static methods from the `Utilities` class (ShiftLeft, ReplaceRange, AddRangeNoAlloc, and GetSensorFloatObservationSize) were removed. ### Bugfixes - Fixed an issue which caused self-play training sessions to consume a lot of memory. (#3451) From 47d83354a4ce7c5a487cc017d3a894b5f0c1c4e6 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Tue, 25 Feb 2020 15:52:13 -0800 Subject: [PATCH 3/4] Update com.unity.ml-agents/Runtime/Utilities.cs Co-Authored-By: Vincent-Pierre BERGES --- com.unity.ml-agents/Runtime/Utilities.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.ml-agents/Runtime/Utilities.cs b/com.unity.ml-agents/Runtime/Utilities.cs index a518f19cc8..297ae15df8 100644 --- a/com.unity.ml-agents/Runtime/Utilities.cs +++ b/com.unity.ml-agents/Runtime/Utilities.cs @@ -75,7 +75,7 @@ public static int[] CumSum(int[] input) } #if DEBUG - internal static void DebugCheckNanAndInfinity(float value, string valueCategory, string caller) + public static void DebugCheckNanAndInfinity(float value, string valueCategory, string caller) { if (float.IsNaN(value)) From d9d0d2ad1f413ae736c6bf43691a9759fce69e3a Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Tue, 25 Feb 2020 15:52:55 -0800 Subject: [PATCH 4/4] Make other methods internal --- com.unity.ml-agents/Runtime/Utilities.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/com.unity.ml-agents/Runtime/Utilities.cs b/com.unity.ml-agents/Runtime/Utilities.cs index 297ae15df8..661607affb 100644 --- a/com.unity.ml-agents/Runtime/Utilities.cs +++ b/com.unity.ml-agents/Runtime/Utilities.cs @@ -19,7 +19,7 @@ internal static class Utilities /// being stored in the tensor. /// /// The number of floats written - public static int TextureToTensorProxy( + internal static int TextureToTensorProxy( Texture2D texture, WriteAdapter adapter, bool grayScale) @@ -62,7 +62,7 @@ public static int TextureToTensorProxy( /// Input array whose elements will be cumulatively added /// /// The cumulative sum of the input array. - public static int[] CumSum(int[] input) + internal static int[] CumSum(int[] input) { var runningSum = 0; var result = new int[input.Length + 1]; @@ -75,7 +75,7 @@ public static int[] CumSum(int[] input) } #if DEBUG - public static void DebugCheckNanAndInfinity(float value, string valueCategory, string caller) + internal static void DebugCheckNanAndInfinity(float value, string valueCategory, string caller) { if (float.IsNaN(value))