Skip to content

Commit

Permalink
lint: Use same convention everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
ayan-b committed Aug 4, 2020
1 parent da6c8f5 commit 3815f74
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 55 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ jobs:
install: pip install flake8
script:
# stop the build if there are Python syntax errors or undefined names
- flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
- flake8 . --show-source --statistics
# exit-zero treats all errors as warnings
- flake8 . --exit-zero
- flake8 .
28 changes: 15 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@


compiler_directives = {
'language_level': 3,
"language_level": 3,
}

# Disable assertions; one is failing geodesic_mesh.h:405
define_macros = [('NDEBUG', 1)]
define_macros = [("NDEBUG", 1)]

if 'COVERAGE' in os.environ:
compiler_directives['linetrace'] = True
if "COVERAGE" in os.environ:
compiler_directives["linetrace"] = True
define_macros.append(("CYTHON_TRACE_NOGIL", "1"))

GEODESIC_NAME = "gdist"
Expand All @@ -68,8 +68,8 @@
sources=["gdist.pyx"], # Filename of Cython source
language="c++", # Cython create C++ source
define_macros=define_macros,
extra_compile_args=['--std=c++14'],
extra_link_args=['--std=c++14'],
extra_compile_args=["--std=c++14"],
extra_link_args=["--std=c++14"],
include_dirs=[numpy.get_include(), "geodesic_library"],
)
]
Expand All @@ -81,11 +81,12 @@

TEAM = "Danil Kirsanov, Gaurav Malhotra and Stuart Knock"

INSTALL_REQUIREMENTS = ['numpy', 'scipy', 'cython']
INSTALL_REQUIREMENTS = ["numpy", "scipy", "cython"]

with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as fd:
with open(os.path.join(os.path.dirname(__file__), "README.rst")) as fd:
DESCRIPTION = fd.read()


class new_build_ext(build_ext):
def finalize_options(self):
self.distribution.ext_modules = cythonize(
Expand All @@ -100,18 +101,19 @@ def finalize_options(self):
self.include_dirs.append(numpy.get_include())
super().finalize_options()


setuptools.setup(
name="tvb-" + GEODESIC_NAME,
version='2.1.0',
version="2.1.0",
ext_modules=GEODESIC_MODULE,
include_dirs=INCLUDE_DIRS,
cmdclass={"build_ext": new_build_ext},
install_requires=INSTALL_REQUIREMENTS,
description="Compute geodesic distances",
long_description=DESCRIPTION,
license='GPL v3',
license="GPL v3",
author=TEAM,
author_email='tvb.admin@thevirtualbrain.org',
url='https://github.com/the-virtual-brain/tvb-gdist',
keywords="gdist geodesic distance geo tvb"
author_email="tvb.admin@thevirtualbrain.org",
url="https://github.com/the-virtual-brain/tvb-gdist",
keywords="gdist geodesic distance geo tvb",
)
14 changes: 6 additions & 8 deletions tests/test_equality_with_stable.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,19 @@


def test_equality_with_stable():
surface_datas = ['inner_skull_642', 'outer_skull_642', 'scalp_1082']
surface_datas = ["inner_skull_642", "outer_skull_642", "scalp_1082"]
for surface_data in surface_datas:
expected = np.loadtxt(
f'data/surface_data/{surface_data}/gdist_matrix.txt')
f"data/surface_data/{surface_data}/gdist_matrix.txt"
)
vertices = np.loadtxt(
f'data/surface_data/{surface_data}/vertices.txt',
dtype=np.float64,
f"data/surface_data/{surface_data}/vertices.txt", dtype=np.float64,
)
triangles = np.loadtxt(
f'data/surface_data/{surface_data}/triangles.txt',
dtype=np.int32,
f"data/surface_data/{surface_data}/triangles.txt", dtype=np.int32,
)
actual = gdist.local_gdist_matrix(
vertices=vertices,
triangles=triangles,
vertices=vertices, triangles=triangles,
)
actual = actual.toarray()
np.testing.assert_array_almost_equal(actual, expected)
43 changes: 11 additions & 32 deletions tests/test_gdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,36 +38,28 @@
import gdist


class TestComputeGdist():
class TestComputeGdist:
def test_flat_triangular_mesh(self):
data = np.loadtxt("data/flat_triangular_mesh.txt", skiprows=1)
vertices = data[0:121].astype(np.float64)
triangles = data[121:].astype(np.int32)
source = np.array([1], dtype=np.int32)
target = np.array([2], dtype=np.int32)
distance = gdist.compute_gdist(
vertices,
triangles,
source_indices=source,
target_indices=target
vertices, triangles, source_indices=source, target_indices=target
)
np.testing.assert_array_almost_equal(distance, [0.2])

def test_flat_triangular_mesh_1_indexed(self):
data = np.loadtxt(
"data/flat_triangular_mesh_1_indexed.txt",
skiprows=1,
"data/flat_triangular_mesh_1_indexed.txt", skiprows=1,
)
vertices = data[0:121].astype(np.float64)
triangles = data[121:].astype(np.int32)
source = np.array([2], dtype=np.int32)
target = np.array([3], dtype=np.int32)
distance = gdist.compute_gdist(
vertices,
triangles,
source,
target,
is_one_indexed=True,
vertices, triangles, source, target, is_one_indexed=True,
)
np.testing.assert_array_almost_equal(distance, [0.2])

Expand All @@ -77,12 +69,7 @@ def test_flat_triangular_mesh_no_target(self):
triangles = data[121:].astype(np.int32)
source = None
target = None
distance = gdist.compute_gdist(
vertices,
triangles,
source,
target,
)
distance = gdist.compute_gdist(vertices, triangles, source, target,)
expected = np.loadtxt("data/flat_triangular_mesh_no_target.txt")
np.testing.assert_array_almost_equal(distance, expected)

Expand All @@ -93,10 +80,7 @@ def test_hedgehog_mesh(self):
source = np.array([0], dtype=np.int32)
target = np.array([1], dtype=np.int32)
distance = gdist.compute_gdist(
vertices,
triangles,
source_indices=source,
target_indices=target
vertices, triangles, source_indices=source, target_indices=target
)
np.testing.assert_array_almost_equal(distance, [1.40522])

Expand All @@ -107,7 +91,7 @@ def test_flat_triangular_mesh(self):
vertices = data[0:121].astype(np.float64)
triangles = data[121:].astype(np.int32)
distances = gdist.local_gdist_matrix(vertices, triangles)
epsilon = 1e-6 # the default value used in `assert_array_almost_equal`
epsilon = 1e-6 # the default value used in `assert_array_almost_equal`
# test if the obtained matrix is symmetric
assert (abs(distances - distances.T) > epsilon).nnz == 0
np.testing.assert_array_almost_equal(distances.toarray()[1][0], 0.2)
Expand All @@ -119,15 +103,12 @@ def test_flat_triangular_mesh(self):

def test_flat_triangular_mesh_1_indexed(self):
data = np.loadtxt(
"data/flat_triangular_mesh_1_indexed.txt",
skiprows=1,
"data/flat_triangular_mesh_1_indexed.txt", skiprows=1,
)
vertices = data[0:121].astype(np.float64)
triangles = data[121:].astype(np.int32)
distances = gdist.local_gdist_matrix(
vertices,
triangles,
is_one_indexed=True
vertices, triangles, is_one_indexed=True
)
epsilon = 1e-6 # the default value used in `assert_array_almost_equal`
# test if the obtained matrix is symmetric
Expand All @@ -144,7 +125,7 @@ def test_hedgehog_mesh(self):
vertices = data[0:300].astype(np.float64)
triangles = data[300:].astype(np.int32)
distances = gdist.local_gdist_matrix(vertices, triangles)
epsilon = 1e-6 # the default value used in `assert_array_almost_equal`
epsilon = 1e-6 # the default value used in `assert_array_almost_equal`
# test if the obtained matrix is symmetric
assert (abs(distances - distances.T) > epsilon).nnz == 0
np.testing.assert_array_almost_equal(
Expand All @@ -164,9 +145,7 @@ def test_flat_triangular_mesh(self):
triangles = data[121:].astype(np.int32)
points = np.array([2, 5, 10, 12, 14, 16], dtype=np.int32)
distances = gdist.distance_matrix_of_selected_points(
vertices,
triangles,
points,
vertices, triangles, points,
)
epsilon = 1e-6
expected = np.loadtxt("data/flat_triangular_mesh_pairwise_matrix.txt")
Expand Down

0 comments on commit 3815f74

Please sign in to comment.