From 5161db917174884b23fd334ab1c470bc83b10795 Mon Sep 17 00:00:00 2001 From: kngwyu Date: Thu, 3 Jun 2021 20:29:54 +0900 Subject: [PATCH] Dont use numpy.complex not to suppress warnings --- mujoco_maze/maze_env_utils.py | 20 ++++----- poetry.lock | 80 +++++++++++++++++++++++++++-------- pyproject.toml | 2 +- tests/test_intersect.py | 2 +- 4 files changed, 74 insertions(+), 30 deletions(-) diff --git a/mujoco_maze/maze_env_utils.py b/mujoco_maze/maze_env_utils.py index f9edfe1..21f35d1 100644 --- a/mujoco_maze/maze_env_utils.py +++ b/mujoco_maze/maze_env_utils.py @@ -13,7 +13,7 @@ from typing import Any, List, Optional, Sequence, Tuple, Union import numpy as np Self = Any -Point = np.complex +Point = complex class MazeCell(Enum): @@ -87,11 +87,11 @@ class Line: p1: Union[Sequence[float], Point], p2: Union[Sequence[float], Point], ) -> None: - self.p1 = p1 if isinstance(p1, Point) else np.complex(*p1) - self.p2 = p2 if isinstance(p2, Point) else np.complex(*p2) + self.p1 = p1 if isinstance(p1, Point) else complex(*p1) + self.p2 = p2 if isinstance(p2, Point) else complex(*p2) self.v1 = self.p2 - self.p1 - self.conj_v1 = np.conjugate(self.v1) - self.norm = np.absolute(self.v1) + self.conj_v1 = self.v1.conjugate() + self.norm = abs(self.v1) def _intersect(self, other: Self) -> bool: v2 = other.p1 - self.p1 @@ -100,15 +100,15 @@ class Line: def _projection(self, p: Point) -> Point: nv1 = -self.v1 - nv1_norm = np.absolute(nv1) ** 2 - scale = np.real(np.conjugate(p - self.p1) * nv1) / nv1_norm + nv1_norm = abs(nv1) ** 2 + scale = ((p - self.p1).conjugate() * nv1).real / nv1_norm return self.p1 + nv1 * scale def reflection(self, p: Point) -> Point: return p + 2.0 * (self._projection(p) - p) def distance(self, p: Point) -> float: - return np.absolute(p - self._projection(p)) + return abs(p - self._projection(p)) def intersect(self, other: Self) -> Point: if self._intersect(other) and other._intersect(self): @@ -198,9 +198,9 @@ class CollisionDetector: if len(collisions) == 0: return None col = collisions[0] - dist = np.absolute(col._point - move.p1) + dist = abs(col._point - move.p1) for collision in collisions[1:]: - new_dist = np.absolute(collision._point - move.p1) + new_dist = abs(collision._point - move.p1) if new_dist < dist: col, dist = collision, new_dist return col diff --git a/poetry.lock b/poetry.lock index 832a57f..68d0bf0 100644 --- a/poetry.lock +++ b/poetry.lock @@ -133,12 +133,12 @@ docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"] testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "packaging", "pep517", "pyfakefs", "flufl.flake8", "pytest-black (>=0.3.7)", "pytest-mypy", "importlib-resources (>=1.3)"] [[package]] -name = "more-itertools" -version = "8.8.0" -description = "More routines for operating on iterables, beyond itertools" +name = "iniconfig" +version = "1.1.1" +description = "iniconfig: brain-dead simple config-ini parsing" category = "dev" optional = false -python-versions = ">=3.5" +python-versions = "*" [[package]] name = "mujoco-py" @@ -164,6 +164,17 @@ category = "main" optional = false python-versions = ">=3.7" +[[package]] +name = "packaging" +version = "20.9" +description = "Core utilities for Python packages" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" + +[package.dependencies] +pyparsing = ">=2.0.2" + [[package]] name = "pillow" version = "8.2.0" @@ -210,22 +221,35 @@ category = "main" optional = false python-versions = "*" +[[package]] +name = "pyparsing" +version = "2.4.7" +description = "Python parsing module" +category = "dev" +optional = false +python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" + [[package]] name = "pytest" -version = "3.10.1" +version = "6.2.4" description = "pytest: simple powerful testing with Python" category = "dev" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +python-versions = ">=3.6" [package.dependencies] -atomicwrites = ">=1.0" -attrs = ">=17.4.0" +atomicwrites = {version = ">=1.0", markers = "sys_platform == \"win32\""} +attrs = ">=19.2.0" colorama = {version = "*", markers = "sys_platform == \"win32\""} -more-itertools = ">=4.0.0" -pluggy = ">=0.7" -py = ">=1.5.0" -six = ">=1.10.0" +importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=0.12,<1.0.0a1" +py = ">=1.8.2" +toml = "*" + +[package.extras] +testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xmlschema"] [[package]] name = "scipy" @@ -246,6 +270,14 @@ category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" +[[package]] +name = "toml" +version = "0.10.2" +description = "Python Library for Tom's Obvious, Minimal Language" +category = "dev" +optional = false +python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" + [[package]] name = "typing-extensions" version = "3.10.0.0" @@ -269,7 +301,7 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pyt [metadata] lock-version = "1.1" python-versions = ">=3.7" # Compatible python versions must be declared here -content-hash = "9234f9b51f7c3fab1f9eefcf7f08e01355ce357941e935359e3145e95fb676f3" +content-hash = "0bbe340523b524544248f4376878056ed5f0f57ec672a62c007543474fb83d05" [metadata.files] atomicwrites = [ @@ -400,9 +432,9 @@ importlib-metadata = [ {file = "importlib_metadata-4.4.0-py3-none-any.whl", hash = "sha256:960d52ba7c21377c990412aca380bf3642d734c2eaab78a2c39319f67c6a5786"}, {file = "importlib_metadata-4.4.0.tar.gz", hash = "sha256:e592faad8de1bda9fe920cf41e15261e7131bcf266c30306eec00e8e225c1dd5"}, ] -more-itertools = [ - {file = "more-itertools-8.8.0.tar.gz", hash = "sha256:83f0308e05477c68f56ea3a888172c78ed5d5b3c282addb67508e7ba6c8f813a"}, - {file = "more_itertools-8.8.0-py3-none-any.whl", hash = "sha256:2cf89ec599962f2ddc4d568a05defc40e0a587fbc10d5989713638864c36be4d"}, +iniconfig = [ + {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"}, + {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, ] mujoco-py = [ {file = "mujoco-py-2.0.2.13.tar.gz", hash = "sha256:d6ae66276b565af9063597fda70683a89c7356290f5ac3961b794ee90ec50eea"}, @@ -433,6 +465,10 @@ numpy = [ {file = "numpy-1.20.3-pp37-pypy37_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:4e465afc3b96dbc80cf4a5273e5e2b1e3451286361b4af70ce1adb2984d392f9"}, {file = "numpy-1.20.3.zip", hash = "sha256:e55185e51b18d788e49fe8305fd73ef4470596b33fc2c1ceb304566b99c71a69"}, ] +packaging = [ + {file = "packaging-20.9-py2.py3-none-any.whl", hash = "sha256:67714da7f7bc052e064859c05c595155bd1ee9f69f76557e21f051443c20947a"}, + {file = "packaging-20.9.tar.gz", hash = "sha256:5b327ac1320dc863dca72f4514ecc086f31186744b84a230374cc1fd776feae5"}, +] pillow = [ {file = "Pillow-8.2.0-cp36-cp36m-macosx_10_10_x86_64.whl", hash = "sha256:dc38f57d8f20f06dd7c3161c59ca2c86893632623f33a42d592f097b00f720a9"}, {file = "Pillow-8.2.0-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:a013cbe25d20c2e0c4e85a9daf438f85121a4d0344ddc76e33fd7e3965d9af4b"}, @@ -485,9 +521,13 @@ pyglet = [ {file = "pyglet-1.5.15-py3-none-any.whl", hash = "sha256:4401cc176580e4e17e2df8bbf7536f27e691327dc3f38f209a12f1859c70aed2"}, {file = "pyglet-1.5.15.zip", hash = "sha256:da9d8337388cedabf1f1c5dc21a45bb2b0e5327fba47f996c8573818c3dfa478"}, ] +pyparsing = [ + {file = "pyparsing-2.4.7-py2.py3-none-any.whl", hash = "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"}, + {file = "pyparsing-2.4.7.tar.gz", hash = "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1"}, +] pytest = [ - {file = "pytest-3.10.1-py2.py3-none-any.whl", hash = "sha256:3f193df1cfe1d1609d4c583838bea3d532b18d6160fd3f55c9447fdca30848ec"}, - {file = "pytest-3.10.1.tar.gz", hash = "sha256:e246cf173c01169b9617fc07264b7b1316e78d7a650055235d6d897bc80d9660"}, + {file = "pytest-6.2.4-py3-none-any.whl", hash = "sha256:91ef2131a9bd6be8f76f1f08eac5c5317221d6ad1e143ae03894b862e8976890"}, + {file = "pytest-6.2.4.tar.gz", hash = "sha256:50bcad0a0b9c5a72c8e4e7c9855a3ad496ca6a881a3641b4260605450772c54b"}, ] scipy = [ {file = "scipy-1.6.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:a15a1f3fc0abff33e792d6049161b7795909b40b97c6cc2934ed54384017ab76"}, @@ -514,6 +554,10 @@ six = [ {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, ] +toml = [ + {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, + {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, +] typing-extensions = [ {file = "typing_extensions-3.10.0.0-py2-none-any.whl", hash = "sha256:0ac0f89795dd19de6b97debb0c6af1c70987fd80a2d62d1958f7e56fcc31b497"}, {file = "typing_extensions-3.10.0.0-py3-none-any.whl", hash = "sha256:779383f6086d90c99ae41cf0ff39aac8a7937a9283ce0a414e5dd782f4c94a84"}, diff --git a/pyproject.toml b/pyproject.toml index ea84a8e..d76849c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ gym = ">=0.16" mujoco-py = ">=1.5" [tool.poetry.dev-dependencies] -pytest = "^3.0" +pytest = "^6.2" [tool.poetry.scripts] test = "pytest:main" diff --git a/tests/test_intersect.py b/tests/test_intersect.py index 2378126..3342f41 100644 --- a/tests/test_intersect.py +++ b/tests/test_intersect.py @@ -13,7 +13,7 @@ from mujoco_maze.maze_env_utils import Line ) def test_distance(l1, l2, p, ans): line = Line(l1, l2) - point = np.complex(*p) + point = complex(*p) assert abs(line.distance(point) - ans) <= 1e-8