Chris Elion
4 年前
当前提交
b0e1cfc9
共有 16 个文件被更改,包括 244 次插入 和 57 次删除
-
3com.unity.ml-agents.extensions/Runtime/Sensors/GridSensor.cs
-
12com.unity.ml-agents.extensions/Tests/Editor/Match3/Match3SensorTests.cs
-
7com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs
-
3com.unity.ml-agents/Runtime/Sensors/CameraSensor.cs
-
4com.unity.ml-agents/Runtime/Sensors/ISensor.cs
-
67com.unity.ml-agents/Runtime/Sensors/ObservationSpec.cs
-
27com.unity.ml-agents/Runtime/Sensors/ObservationWriter.cs
-
4com.unity.ml-agents/Runtime/Sensors/StackingSensor.cs
-
14com.unity.ml-agents/Tests/Editor/Communicator/GrpcExtensionsTests.cs
-
3com.unity.ml-agents/Tests/Editor/ParameterLoaderTest.cs
-
2com.unity.ml-agents/Tests/Editor/Sensor/BufferSensorTest.cs
-
3com.unity.ml-agents/Tests/Editor/Sensor/CameraSensorComponentTest.cs
-
2com.unity.ml-agents/Tests/Editor/Sensor/RenderTextureSensorComponentTests.cs
-
2com.unity.ml-agents/Tests/Editor/Sensor/StackingSensorTests.cs
-
145com.unity.ml-agents/Runtime/InplaceArray.cs
-
3com.unity.ml-agents/Runtime/InplaceArray.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq.Expressions; |
|||
|
|||
namespace Unity.MLAgents |
|||
{ |
|||
public struct InplaceArray<T> where T : struct |
|||
{ |
|||
private const int k_MaxLength = 4; |
|||
private int m_Length; |
|||
|
|||
private T m_elem0; |
|||
private T m_elem1; |
|||
private T m_elem2; |
|||
private T m_elem3; |
|||
|
|||
public InplaceArray(T elem0) |
|||
{ |
|||
m_Length = 1; |
|||
m_elem0 = elem0; |
|||
m_elem1 = new T { }; |
|||
m_elem2 = new T { }; |
|||
m_elem3 = new T { }; |
|||
} |
|||
|
|||
public InplaceArray(T elem0, T elem1) |
|||
{ |
|||
m_Length = 2; |
|||
m_elem0 = elem0; |
|||
m_elem1 = elem1; |
|||
m_elem2 = new T { }; |
|||
m_elem3 = new T { }; |
|||
} |
|||
|
|||
public InplaceArray(T elem0, T elem1, T elem2) |
|||
{ |
|||
m_Length = 3; |
|||
m_elem0 = elem0; |
|||
m_elem1 = elem1; |
|||
m_elem2 = elem2; |
|||
m_elem3 = new T { }; |
|||
} |
|||
|
|||
public InplaceArray(T elem0, T elem1, T elem2, T elem3) |
|||
{ |
|||
m_Length = 4; |
|||
m_elem0 = elem0; |
|||
m_elem1 = elem1; |
|||
m_elem2 = elem2; |
|||
m_elem3 = elem3; |
|||
} |
|||
|
|||
public static InplaceArray<T> FromList(IList<T> elems) |
|||
{ |
|||
switch (elems.Count) |
|||
{ |
|||
case 1: |
|||
return new InplaceArray<T>(elems[0]); |
|||
case 2: |
|||
return new InplaceArray<T>(elems[0], elems[1]); |
|||
case 3: |
|||
return new InplaceArray<T>(elems[0], elems[1], elems[2]); |
|||
case 4: |
|||
return new InplaceArray<T>(elems[0], elems[1], elems[2], elems[3]); |
|||
default: |
|||
throw new ArgumentOutOfRangeException(); |
|||
} |
|||
} |
|||
|
|||
public T this[int index] |
|||
{ |
|||
get |
|||
{ |
|||
if (index < 0 || index >= k_MaxLength) |
|||
{ |
|||
throw new ArgumentOutOfRangeException(); |
|||
} |
|||
|
|||
switch (index) |
|||
{ |
|||
case 0: |
|||
return m_elem0; |
|||
case 1: |
|||
return m_elem1; |
|||
case 2: |
|||
return m_elem2; |
|||
case 3: |
|||
return m_elem3; |
|||
default: |
|||
throw new ArgumentOutOfRangeException(); |
|||
} |
|||
} |
|||
|
|||
internal set |
|||
{ |
|||
if (index < 0 || index >= k_MaxLength) |
|||
{ |
|||
throw new ArgumentOutOfRangeException(); |
|||
} |
|||
|
|||
switch (index) |
|||
{ |
|||
case 0: |
|||
m_elem0 = value; |
|||
break; |
|||
case 1: |
|||
m_elem1 = value; |
|||
break; |
|||
case 2: |
|||
m_elem2 = value; |
|||
break; |
|||
case 3: |
|||
m_elem3 = value; |
|||
break; |
|||
default: |
|||
throw new ArgumentOutOfRangeException(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public int Length |
|||
{ |
|||
get => m_Length; |
|||
} |
|||
|
|||
public override string ToString() |
|||
{ |
|||
switch (m_Length) |
|||
{ |
|||
case 0: |
|||
return "[]"; |
|||
case 1: |
|||
return $"[{m_elem0}]"; |
|||
case 2: |
|||
return $"[{m_elem0}, {m_elem1}]"; |
|||
case 3: |
|||
return $"[{m_elem0}, {m_elem1}, {m_elem2}]"; |
|||
case 4: |
|||
return $"[{m_elem0}, {m_elem1}, {m_elem2}, {m_elem3}]"; |
|||
default: |
|||
throw new ArgumentOutOfRangeException(); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c1a80abee18a41c8aee89aeb33f5985d |
|||
timeCreated: 1615506199 |
撰写
预览
正在加载...
取消
保存
Reference in new issue