浏览代码

remove unused methods from Utilities.cs (#3495)

/asymm-envs
GitHub 5 年前
当前提交
aee0611a
共有 2 个文件被更改,包括 3 次插入80 次删除
  1. 1
      com.unity.ml-agents/CHANGELOG.md
  2. 82
      com.unity.ml-agents/Runtime/Utilities.cs

1
com.unity.ml-agents/CHANGELOG.md


- 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)

82
com.unity.ml-agents/Runtime/Utilities.cs


using System;
using UnityEngine;
using System.Collections.Generic;
namespace MLAgents
{

/// being stored in the tensor.
/// </param>
/// <returns>The number of floats written</returns>
public static int TextureToTensorProxy(
internal static int TextureToTensorProxy(
Texture2D texture,
WriteAdapter adapter,
bool grayScale)

/// Input array whose elements will be cumulatively added
/// </param>
/// <returns> The cumulative sum of the input array.</returns>
public static int[] CumSum(int[] input)
internal static int[] CumSum(int[] input)
{
var runningSum = 0;
var result = new int[input.Length + 1];

result[actionIndex + 1] = runningSum;
}
return result;
}
/// <summary>
/// Shifts list elements to the left by the specified amount (in-place).
/// <param name="list">
/// List whose elements will be shifted
/// </param>
/// <param name="shiftAmount">
/// Amount to shift the elements to the left by
/// </param>
/// </summary>
public static void ShiftLeft<T>(List<T> list, int shiftAmount)
{
for (var i = shiftAmount; i < list.Count; i++)
{
list[i - shiftAmount] = list[i];
}
}
/// <summary>
/// Replaces target list elements with source list elements starting at specified position
/// in target list.
/// <param name="dst">
/// Target list, where the elements are added to
/// </param>
/// <param name="src">
/// Source array, where the elements are copied from
/// </param>
/// <param name="start">
/// Starting position in target list to copy elements to
/// </param>
/// </summary>
public static void ReplaceRange<T>(List<T> dst, List<T> src, int start)
{
for (var i = 0; i < src.Count; i++)
{
dst[i + start] = src[i];
}
}
/// <summary>
/// Adds elements to list without extra temp allocations (assuming it fits pre-allocated
/// capacity of the list). The built-in List/<T/>.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.
/// <param name="dst">
/// Target list, where the elements are added to
/// </param>
/// <param name="src">
/// Source array, where the elements are copied from
/// </param>
/// </summary>
// ReSharper disable once ParameterTypeCanBeEnumerable.Global
public static void AddRangeNoAlloc<T>(List<T> dst, T[] src)
{
// ReSharper disable once LoopCanBeConvertedToQuery
foreach (var item in src)
{
dst.Add(item);
}
}
/// <summary>
/// Calculates the number of uncompressed floats in a list of ISensor
/// </summary>
public static int GetSensorFloatObservationSize(this List<ISensor> 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

正在加载...
取消
保存