Skip to content

Rider suggested cleanup, part 1 #5265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.Sensors.Reflection;

public class Ball3DHardAgent : Agent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override ActionSpec ActionSpec
/// <summary>
/// Simple actuator that converts the action into a {-1, 0, 1} direction
/// </summary>
public class BasicActuator : IActuator, IHeuristicProvider
public class BasicActuator : IActuator
{
public BasicController basicController;
ActionSpec m_ActionSpec;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using UnityEngine;
using Unity.MLAgents;
using Unity.Barracuda;
using Unity.MLAgents.Actuators;
using Unity.MLAgentsExamples;
using Unity.MLAgents.Sensors;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SimpleNPC : MonoBehaviour
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void MoveAgent(ActionBuffers actionBuffers)
dirToGo += transform.right * right;
rotateDir = -transform.up * rotate;

var shootCommand = (int)discreteActions[0] > 0;
var shootCommand = discreteActions[0] > 0;
if (shootCommand)
{
m_Shoot = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Integrations.Match3;

namespace Unity.MLAgentsExamples
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Unity.MLAgents;
using Unity.MLAgents.Integrations.Match3;

namespace Unity.MLAgentsExamples
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//Put this script on your blue cube.

using System.Collections;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//Put this script on your blue cube.

using System;
using System.Collections;
using UnityEngine;
using Unity.MLAgents;
Expand All @@ -18,7 +16,7 @@ public class PushBlockWithInputAgentBasic : Agent

/// <summary>
/// The area bounds.
/// </summary'PushAgentBasic'>
/// </summary>
[HideInInspector]
public Bounds areaBounds;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using UnityEngine;
using Random = UnityEngine.Random;
using Unity.MLAgents;
using UnityEngine.Events;

namespace Unity.MLAgentsExamples
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using Unity.MLAgents;
using UnityEngine;
Expand Down Expand Up @@ -91,7 +90,7 @@ public void ResetBall()
var randomPosX = Random.Range(-2.5f, 2.5f);
var randomPosZ = Random.Range(-2.5f, 2.5f);

ball.transform.position = m_BallStartingPos + new Vector3(randomPosX, 0f, randomPosZ); ;
ball.transform.position = m_BallStartingPos + new Vector3(randomPosX, 0f, randomPosZ);
ballRb.velocity = Vector3.zero;
ballRb.angularVelocity = Vector3.zero;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NumberTile : MonoBehaviour
Expand All @@ -8,7 +6,7 @@ public class NumberTile : MonoBehaviour
public Material DefaultMaterial;
public Material SuccessMaterial;

private bool m_Visited = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how people feel about. My instinct is to a) be explicit (from python) and b) always initialize everything (coming from C++), but Rider likes to complain about it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think making them explicit is not a bad thing and sometimes it feels safer (I know it works that way but I like seeing it written that way).
No strong opinions anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

traumatized by c++

private bool m_Visited;
private MeshRenderer m_Renderer;

public bool IsVisited
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public override void CollectObservations(VectorSensor sensor)
// Here, the observation for the tile is added to the BufferSensor
m_BufferSensor.AppendObservation(listObservation);

};
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ void FixedUpdate()
Vector3 GetAvgVelocity()
{
Vector3 velSum = Vector3.zero;
Vector3 avgVel = Vector3.zero;

//ALL RBS
int numOfRb = 0;
Expand All @@ -271,7 +270,7 @@ Vector3 GetAvgVelocity()
velSum += item.rb.velocity;
}

avgVel = velSum / numOfRb;
var avgVel = velSum / numOfRb;
return avgVel;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using UnityEngine;
using Unity.MLAgents;
using Unity.Barracuda;
using Unity.MLAgents.Actuators;
using Unity.MLAgentsExamples;
using Unity.MLAgents.Sensors;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#if MLA_INPUT_SYSTEM
using Unity.MLAgents.Actuators;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.LowLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#if MLA_INPUT_SYSTEM
using System;
using Unity.MLAgents.Actuators;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.LowLevel;

namespace Unity.MLAgents.Extensions.Input
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if MLA_INPUT_SYSTEM
using System;
using Unity.MLAgents.Actuators;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using Unity.MLAgents.Actuators;
using Unity.MLAgents.Policies;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Profiling;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#if MLA_INPUT_TESTS
using System;
using NUnit.Framework;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Extensions.Input;
using UnityEngine;
using UnityEngine.InputSystem;

namespace Unity.MLAgents.Extensions.Tests.Runtime.Input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void TestCountingSensor()

gridSensor.Update();

subarrayIndicies = new int[] { 77, 78, 87, 88 };
subarrayIndicies = new[] { 77, 78, 87, 88 };
expectedSubarrays = DuplicateArray(new float[] { 2, 0 }, 4);
expectedDefault = new float[] { 0, 0 };
AssertSubarraysAtIndex(gridSensor.PerceptionBuffer, subarrayIndicies, expectedSubarrays, expectedDefault);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Runtime.CompilerServices;
using UnityEngine;
using NUnit.Framework;
using Unity.MLAgents.Sensors;
Expand Down
2 changes: 0 additions & 2 deletions com.unity.ml-agents/Editor/DemonstrationDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using System.Text;
using UnityEditor;
using Unity.MLAgents.Demonstrations;
using Unity.MLAgents.Policies;


namespace Unity.MLAgents.Editor
{
Expand Down
1 change: 0 additions & 1 deletion com.unity.ml-agents/Runtime/Actuators/ActionSpec.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

Expand Down
1 change: 0 additions & 1 deletion com.unity.ml-agents/Runtime/Actuators/ActuatorComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using UnityEngine;

namespace Unity.MLAgents.Actuators
Expand Down
2 changes: 0 additions & 2 deletions com.unity.ml-agents/Runtime/Actuators/IDiscreteActionMask.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Collections.Generic;

namespace Unity.MLAgents.Actuators
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class InferenceAnalytics
/// <summary>
/// Whether or not we've registered this particular event yet
/// </summary>
static bool s_EventRegistered = false;
static bool s_EventRegistered;

/// <summary>
/// Hourly limit for this event name
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Runtime/Analytics/TrainingAnalytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal static class TrainingAnalytics
/// <summary>
/// Whether or not we've registered this particular event yet
/// </summary>
static bool s_EventsRegistered = false;
static bool s_EventsRegistered;

/// <summary>
/// Behaviors that we've already sent events for.
Expand Down
6 changes: 3 additions & 3 deletions com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal static class GrpcExtensions
/// <summary>
/// Static flag to make sure that we only fire the warning once.
/// </summary>
private static bool s_HaveWarnedTrainerCapabilitiesAgentGroup = false;
private static bool s_HaveWarnedTrainerCapabilitiesAgentGroup;

/// <summary>
/// Converts a AgentInfo to a protobuf generated AgentInfoActionPairProto
Expand Down Expand Up @@ -326,8 +326,8 @@ public static ActionBuffers ToActionBuffers(this AgentActionProto proto)
/// <summary>
/// Static flag to make sure that we only fire the warning once.
/// </summary>
private static bool s_HaveWarnedTrainerCapabilitiesMultiPng = false;
private static bool s_HaveWarnedTrainerCapabilitiesMapping = false;
private static bool s_HaveWarnedTrainerCapabilitiesMultiPng;
private static bool s_HaveWarnedTrainerCapabilitiesMapping;

/// <summary>
/// Generate an ObservationProto for the sensor using the provided ObservationWriter.
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Runtime/DecisionRequester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Unity.MLAgents
///
/// The DecisionRequester component provides a convenient and flexible way to
/// trigger the agent decision making process. Without a DecisionRequester,
/// your <see cref="Agent"/> implmentation must manually call its
/// your <see cref="Agent"/> implementation must manually call its
/// <seealso cref="Agent.RequestDecision"/> function.
/// </remarks>
[AddComponentMenu("ML Agents/Decision Requester", (int)MenuGroup.Default)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ public static bool HasDiscreteOutputs(this Model model)
}
else
{
return model.outputs.Contains(TensorNames.DiscreteActionOutput) &&
(int)model.DiscreteOutputSize() > 0;
return model.outputs.Contains(TensorNames.DiscreteActionOutput) && model.DiscreteOutputSize() > 0;
}
}

Expand Down
1 change: 0 additions & 1 deletion com.unity.ml-agents/Runtime/Inference/GeneratorImpl.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System;
using UnityEngine;
using Unity.Barracuda;
using Unity.MLAgents.Inference.Utils;
using Unity.MLAgents.Sensors;
Expand Down
1 change: 0 additions & 1 deletion com.unity.ml-agents/Runtime/Inference/ModelRunner.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using Unity.Barracuda;
using UnityEngine.Profiling;
Expand Down
12 changes: 6 additions & 6 deletions com.unity.ml-agents/Runtime/InplaceArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public InplaceArray(T elem0)
{
m_Length = 1;
m_Elem0 = elem0;
m_Elem1 = new T { };
m_Elem2 = new T { };
m_Elem3 = new T { };
m_Elem1 = new T();
m_Elem2 = new T();
m_Elem3 = new T();
}

/// <summary>
Expand All @@ -44,8 +44,8 @@ public InplaceArray(T elem0, T elem1)
m_Length = 2;
m_Elem0 = elem0;
m_Elem1 = elem1;
m_Elem2 = new T { };
m_Elem3 = new T { };
m_Elem2 = new T();
m_Elem3 = new T();
}

/// <summary>
Expand All @@ -60,7 +60,7 @@ public InplaceArray(T elem0, T elem1, T elem2)
m_Elem0 = elem0;
m_Elem1 = elem1;
m_Elem2 = elem2;
m_Elem3 = new T { };
m_Elem3 = new T();
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Runtime/Integrations/Match3/Move.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static Move FromMoveIndex(int moveIndex, BoardSize maxBoardSize)

if (moveIndex < 0 || moveIndex >= NumPotentialMoves(maxBoardSize))
{
throw new ArgumentOutOfRangeException("Invalid move index.");
throw new ArgumentOutOfRangeException("moveIndex");
}
Direction dir;
int row, col;
Expand Down
1 change: 0 additions & 1 deletion com.unity.ml-agents/Runtime/MLAgentsSettingsManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
Copy link
Contributor Author

@chriselion chriselion Apr 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only needed in non-editor compilation.

using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Runtime/MultiAgentGroupIdCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal static class MultiAgentGroupIdCounter
static int s_Counter;
public static int GetGroupId()
{
return Interlocked.Increment(ref s_Counter); ;
return Interlocked.Increment(ref s_Counter);
}
}
}
1 change: 0 additions & 1 deletion com.unity.ml-agents/Runtime/Policies/HeuristicPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ internal class HeuristicPolicy : IPolicy
NullList m_NullList = new NullList();


/// <inheritdoc />
public HeuristicPolicy(ActuatorManager actuatorManager, ActionSpec actionSpec)
{
m_ActuatorManager = actuatorManager;
Expand Down
1 change: 0 additions & 1 deletion com.unity.ml-agents/Runtime/Policies/RemotePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ internal class RemotePolicy : IPolicy
/// </summary>
private IList<IActuator> m_Actuators;

/// <inheritdoc />
public RemotePolicy(
ActionSpec actionSpec,
IList<IActuator> actuators,
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Runtime/Sensors/BoxOverlapChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void InitCellLocalPositions()

/// <summary>Converts the index of the cell to the 3D point (y is zero) relative to grid center</summary>
/// <returns>Vector3 of the position of the center of the cell relative to grid center</returns>
/// <param name="cell">The index of the cell</param>
/// <param name="cellIndex">The index of the cell</param>
Vector3 GetCellLocalPosition(int cellIndex)
{
float x = (cellIndex / m_GridSize.z - m_CellCenterOffset.x) * m_CellScale.x;
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Unity.MLAgents.Sensors
{
/// <summary>
/// A SensorComponent that creates a <see cref="GridSensor"/>.
/// A SensorComponent that creates a <see cref="GridSensorBase"/>.
/// </summary>
[AddComponentMenu("ML Agents/Grid Sensor", (int)MenuGroup.Sensors)]
public class GridSensorComponent : SensorComponent
Expand Down
Loading