Skip to content

Commit

Permalink
Fix extra import error and format tests with black
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Hynes committed Mar 15, 2019
1 parent e8cb5f6 commit a0eb25a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
1 change: 0 additions & 1 deletion skspatial/reduction.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Functions related to dimension reduction."""

from dpcontracts import ensure
from numpy.linalg import matrix_rank

from skspatial.transformation import mean_center
Expand Down
6 changes: 2 additions & 4 deletions skspatial/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,10 @@ def mean_center(points):

@types(points=np.ndarray)
@require(
"The points dimension cannot be greater than the desired dimension.",
lambda args: args.points.shape[1] <= args.dim
"The points dimension cannot be greater than the desired dimension.", lambda args: args.points.shape[1] <= args.dim
)
@ensure(
"The output must have the desired dimensions.",
lambda args, result: result.shape == (len(args.points), args.dim)
"The output must have the desired dimensions.", lambda args, result: result.shape == (len(args.points), args.dim)
)
@ensure("The output must be an ndarray.", lambda _, result: isinstance(result, np.ndarray))
def set_dimension(points, dim):
Expand Down
34 changes: 29 additions & 5 deletions tests/unit/test_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,36 @@ def test_best_fit_line(points, line_expected):
([[0, 0], [1, 1], [0, 2]], Plane([1 / 3, 1, 0], [0, 0, 1])),
([[0, 0], [0, 1], [1, 0], [1, 1]], Plane([0.5, 0.5], [0, 0, 1])),
([[0, 0, 0], [1, 0, 0], [0, 0, 1]], Plane([1 / 3, 0, 1 / 3], [0, 1, 0])),
([[1, 0, 0], [-1, 0, 0], [1, 1, 1], [-1, 1, 1]], Plane([0, 0.5, 0.5], [0, 1, -1])),
([[1, 0, 1], [1, 1, 1], [-1, 0, -1], [-1, 1, -1]], Plane([0, 0.5, 0], [1, 0, -1])),
([[1, 0, 1], [1, 1, 1], [-1, 0, -1], [-1, 1, -1], [0, 0, 0]], Plane([0, 0.4, 0], [1, 0, -1])),
(
[[1, 0, 0], [-1, 0, 0], [1, 1, 1], [-1, 1, 1]],
Plane([0, 0.5, 0.5], [0, 1, -1]),
),
(
[[1, 0, 1], [1, 1, 1], [-1, 0, -1], [-1, 1, -1]],
Plane([0, 0.5, 0], [1, 0, -1]),
),
(
[[1, 0, 1], [1, 1, 1], [-1, 0, -1], [-1, 1, -1], [0, 0, 0]],
Plane([0, 0.4, 0], [1, 0, -1]),
),
# The points are not coplanar.
([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]], Plane([0.25, 0.25, 0.25], [1, 1, 1])),
([[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]], Plane([0.5, 0.5, 0.5], [0, 1, 0]))
(
[[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]],
Plane([0.25, 0.25, 0.25], [1, 1, 1]),
),
(
[
[0, 0, 0],
[0, 0, 1],
[0, 1, 0],
[0, 1, 1],
[1, 0, 0],
[1, 0, 1],
[1, 1, 0],
[1, 1, 1],
],
Plane([0.5, 0.5, 0.5], [0, 1, 0]),
),
],
)
def test_best_fit_plane(points, plane_expected):
Expand Down

0 comments on commit a0eb25a

Please sign in to comment.