Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 727fc3a

Browse files
committedMar 11, 2023
up
1 parent e09f3cd commit 727fc3a

File tree

10 files changed

+45
-138
lines changed

10 files changed

+45
-138
lines changed
 

‎benchmarks/test_computations.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_python_clip_vector(benchmark: Any) -> None:
1818
fastvector.python_clip_vector,
1919
args=(v, -1, 1, v),
2020
rounds=NUM_ROUNDS,
21-
iterations=NUM_ITERATIONS
21+
iterations=NUM_ITERATIONS,
2222
)
2323

2424

@@ -27,7 +27,7 @@ def test_naive_cython_clip_vector(benchmark: Any) -> None:
2727
fastvector.naive_cython_clip_vector,
2828
args=(v, -1, 1, v),
2929
rounds=NUM_ROUNDS,
30-
iterations=NUM_ITERATIONS
30+
iterations=NUM_ITERATIONS,
3131
)
3232

3333

@@ -36,7 +36,7 @@ def test_cython_clip_vector(benchmark: Any) -> None:
3636
fastvector.cython_clip_vector,
3737
args=(v, -1, 1, v),
3838
rounds=NUM_ROUNDS,
39-
iterations=NUM_ITERATIONS
39+
iterations=NUM_ITERATIONS,
4040
)
4141

4242

@@ -45,5 +45,5 @@ def test_np_clip(benchmark: Any) -> None:
4545
np.clip,
4646
args=(a, -1, 1, a),
4747
rounds=NUM_ROUNDS,
48-
iterations=NUM_ITERATIONS
48+
iterations=NUM_ITERATIONS,
4949
)

‎fastvector/__init__.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@
22
from .version import __version__
33

44

5-
__all__ = [
6-
'Vector2D'
7-
'__version__'
8-
]
5+
__all__ = ["Vector2D", "__version__"]

‎fastvector/computations.py

-37
This file was deleted.

‎fastvector/cython_computations.pyx

-36
This file was deleted.

‎fastvector/dtypes.py

-16
This file was deleted.

‎fastvector/vector.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ def __init__(self, x: SupportsFloat = 0.0, y: SupportsFloat = 0.0) -> None:
2323
self.x = x
2424
self.y = y
2525
else:
26-
raise TypeError('You must pass in int/float value for x and y!')
26+
raise TypeError("You must pass in int/float value for x and y!")
2727

2828
def __repr__(self) -> str:
2929
"""Return the vector representation.
3030
3131
Returns:
3232
The representation of the vector.
3333
"""
34-
return f'vector.Vector2D({self.x}, {self.y})'
34+
return f"vector.Vector2D({self.x}, {self.y})"
3535

3636
def __str__(self) -> str:
3737
"""The vector as a string.
3838
3939
Returns:
4040
The vector as a string.
4141
"""
42-
return f'({self.x}, {self.y})'
42+
return f"({self.x}, {self.y})"
4343

4444
def __abs__(self) -> float:
4545
"""Return the length (magnitude) of the vector.
@@ -74,7 +74,7 @@ def __lt__(self, other_vector: Vector2D) -> bool:
7474
False, else.
7575
"""
7676
if not isinstance(other_vector, Vector2D):
77-
raise TypeError('You must pass in a Vector2D instance!')
77+
raise TypeError("You must pass in a Vector2D instance!")
7878
return abs(self) < abs(other_vector)
7979

8080
def __add__(self, other_vector: Vector2D) -> Vector2D:
@@ -87,7 +87,7 @@ def __add__(self, other_vector: Vector2D) -> Vector2D:
8787
The addition vector of the self and the other vector.
8888
"""
8989
if not isinstance(other_vector, Vector2D):
90-
raise TypeError('You must pass in a Vector2D instance!')
90+
raise TypeError("You must pass in a Vector2D instance!")
9191
x = self.x + other_vector.x
9292
y = self.y + other_vector.y
9393
return Vector2D(x, y)
@@ -102,7 +102,7 @@ def __sub__(self, other_vector: Vector2D) -> Vector2D:
102102
The subtraction vector of the self and the other vector.
103103
"""
104104
if not isinstance(other_vector, Vector2D):
105-
raise TypeError('You must pass in a Vector2D instance!')
105+
raise TypeError("You must pass in a Vector2D instance!")
106106
x = self.x - other_vector.x
107107
y = self.y - other_vector.y
108108
return Vector2D(x, y)
@@ -125,7 +125,7 @@ def __mul__(
125125
result: SupportsFloat = self.x * other.x + self.y * other.y
126126
return result
127127
if not isinstance(other, numbers.Real):
128-
raise TypeError('You must pass in an int/float!')
128+
raise TypeError("You must pass in an int/float!")
129129
return Vector2D(self.x * other, self.y * other)
130130

131131
def __truediv__(self, other: SupportsFloat) -> Vector2D:
@@ -142,5 +142,5 @@ def __truediv__(self, other: SupportsFloat) -> Vector2D:
142142
The multiplication of self and the other vector/number.
143143
"""
144144
if not isinstance(other, numbers.Real):
145-
raise TypeError('You must pass in an int/float!')
145+
raise TypeError("You must pass in an int/float!")
146146
return Vector2D(self.x / other, self.y / other)

‎fastvector/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '3.0.0'
1+
__version__ = "4.0.0"

‎setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
[metadata]
33
name = fastvector
4-
version = 3.0.0
4+
version = 4.0.0
55
description = "This is a simple vector python package."
66
long_description = file: README.md
77
long_description_content_type = text/markdown

‎setup.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ def main() -> None:
1010
with open("requirements.txt") as fp:
1111
install_requires = fp.read().strip().split("\n")
1212

13-
metadata = dict(
14-
install_requires=install_requires
15-
)
13+
metadata = dict(install_requires=install_requires)
1614
setup(**metadata)
1715

1816

‎tests/test_vector.py

+29-28
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,28 @@
1515
### INIT ###
1616
####################
1717

18+
1819
@pytest.mark.parametrize(
19-
('x', 'y'),
20+
("x", "y"),
2021
(
2122
(-1, None),
2223
(1, None),
2324
(None, 1),
2425
(None, -1),
25-
)
26+
),
2627
)
2728
def test_init_raises(x: SupportsFloat, y: SupportsFloat) -> None:
2829
with pytest.raises(TypeError):
2930
_ = Vector2D(x, y)
3031

3132

3233
@pytest.mark.parametrize(
33-
('x', 'y', 'exp'),
34+
("x", "y", "exp"),
3435
(
3536
(-1, 1, Vector2D(-1, 1)),
3637
(1, -1, Vector2D(1, -1)),
3738
(1, 1, Vector2D(1, 1)),
38-
)
39+
),
3940
)
4041
def test_from_values(x: SupportsFloat, y: SupportsFloat, exp: Vector2D) -> None:
4142
assert exp == Vector2D(x, y)
@@ -45,6 +46,7 @@ def test_from_values(x: SupportsFloat, y: SupportsFloat, exp: Vector2D) -> None:
4546
### STRINGS ###
4647
####################
4748

49+
4850
def test_repr(capture_stdout: dict) -> None:
4951
print(repr(Vector2D(1.0, 2.0)))
5052
assert capture_stdout["stdout"] == "vector.Vector2D(1.0, 2.0)\n"
@@ -59,95 +61,93 @@ def test_str(capture_stdout: dict) -> None:
5961
### COMPUTATIONS ###
6062
####################
6163

64+
6265
@pytest.mark.parametrize(
63-
('lhs', 'rhs', 'exp_res'),
66+
("lhs", "rhs", "exp_res"),
6467
(
6568
(V1, V2, Vector2D(-1, 1)),
6669
(V1, V3, Vector2D(2.5, -2.5)),
6770
(V3, V2, Vector2D(1.5, -1.5)),
68-
)
71+
),
6972
)
7073
def test_add(lhs: Vector2D, rhs: Vector2D, exp_res: Vector2D) -> None:
7174
assert lhs + rhs == exp_res
7275

7376

7477
@pytest.mark.parametrize(
75-
('lhs', 'rhs', 'exp_res'),
78+
("lhs", "rhs", "exp_res"),
7679
(
7780
(V1, V2, Vector2D(1, -1)),
7881
(V1, V3, Vector2D(-2.5, 2.5)),
7982
(V3, V2, Vector2D(3.5, -3.5)),
80-
)
83+
),
8184
)
8285
def test_sub(lhs: Vector2D, rhs: Vector2D, exp_res: Vector2D) -> None:
8386
assert lhs - rhs == exp_res
8487

8588

8689
@pytest.mark.parametrize(
87-
('lhs', 'rhs', 'exp_res'),
90+
("lhs", "rhs", "exp_res"),
8891
(
8992
(V1, V2, 0.0),
9093
(V1, V3, 0.0),
9194
(V3, V2, -5.0),
92-
)
95+
),
9396
)
9497
def test_mul_vec(lhs: Vector2D, rhs: Vector2D, exp_res: float) -> None:
9598
assert lhs * rhs == exp_res
9699

97100

98101
@pytest.mark.parametrize(
99-
('lhs', 'rhs', 'exp_res'),
102+
("lhs", "rhs", "exp_res"),
100103
(
101104
(V1, 2.0, Vector2D(0.0, 0.0)),
102105
(V2, 2.0, Vector2D(-2.0, 2.0)),
103106
(V3, 2.0, Vector2D(5.0, -5.0)),
104-
)
107+
),
105108
)
106109
def test_mul_float(lhs: Vector2D, rhs: float, exp_res: Vector2D) -> None:
107110
assert lhs * rhs == exp_res
108111

109112

110113
@pytest.mark.parametrize(
111-
('rhs', 'lhs'),
114+
("rhs", "lhs"),
112115
(
113116
(Vector2D(1, 1), None),
114117
(Vector2D(1, 1), "1"),
115-
)
118+
),
116119
)
117120
def test_mul_raises(rhs: Vector2D, lhs: Any) -> None:
118121
with pytest.raises(TypeError):
119122
rhs * lhs
120123

121124

122125
@pytest.mark.parametrize(
123-
('lhs', 'rhs', 'exp_res'),
126+
("lhs", "rhs", "exp_res"),
124127
(
125128
(V1, 2.0, Vector2D(0.0, 0.0)),
126129
(V2, 2.0, Vector2D(-0.5, 0.5)),
127130
(V3, 2.0, Vector2D(1.25, -1.25)),
128-
)
131+
),
129132
)
130133
def test_div(lhs: Vector2D, rhs: float, exp_res: Vector2D) -> None:
131134
assert lhs / rhs == exp_res
132135

133136

134137
@pytest.mark.parametrize(
135-
('lhs', 'rhs'),
136-
(
137-
(Vector2D(0.0, 0.0), Vector2D(0.0, 0.0)),
138-
)
138+
("lhs", "rhs"), ((Vector2D(0.0, 0.0), Vector2D(0.0, 0.0)),)
139139
)
140140
def test_div_raises(lhs: Vector2D, rhs: float) -> None:
141141
with pytest.raises(TypeError):
142142
lhs / rhs
143143

144144

145145
@pytest.mark.parametrize(
146-
('rhs', 'lhs'),
146+
("rhs", "lhs"),
147147
(
148148
(Vector2D(1, 1), (0, 1)),
149149
(Vector2D(1, 1), [1, 0]),
150-
)
150+
),
151151
)
152152
def test_operators_raises(rhs: Vector2D, lhs: Vector2D) -> None:
153153
with pytest.raises(TypeError):
@@ -159,12 +159,12 @@ def test_operators_raises(rhs: Vector2D, lhs: Vector2D) -> None:
159159

160160

161161
@pytest.mark.parametrize(
162-
('rhs', 'lhs'),
162+
("rhs", "lhs"),
163163
(
164164
(Vector2D(0, 0), 0),
165165
(Vector2D(0, 1), 1),
166166
(Vector2D(1, 0), 1),
167-
)
167+
),
168168
)
169169
def test_abs(rhs: Vector2D, lhs: SupportsFloat) -> None:
170170
assert abs(rhs) == lhs
@@ -174,23 +174,24 @@ def test_abs(rhs: Vector2D, lhs: SupportsFloat) -> None:
174174
### COMPARISONS ###
175175
####################
176176

177+
177178
@pytest.mark.parametrize(
178-
('lhs', 'rhs'),
179+
("lhs", "rhs"),
179180
(
180181
(Vector2D(1, 1), (1, 1)),
181182
(Vector2D(1, 1), [1, 1]),
182-
)
183+
),
183184
)
184185
def test_equality_other_class(lhs: Vector2D, rhs: object) -> None:
185186
assert not (lhs == rhs)
186187

187188

188189
@pytest.mark.parametrize(
189-
('lhs', 'rhs'),
190+
("lhs", "rhs"),
190191
(
191192
(Vector2D(1, 1), Vector2D(0, 1)),
192193
(Vector2D(1, 1), Vector2D(1, 0)),
193-
)
194+
),
194195
)
195196
def test_less_than(lhs: Vector2D, rhs: Vector2D) -> None:
196197
assert rhs < lhs

0 commit comments

Comments
 (0)
Please sign in to comment.