spagestic commited on
Commit
79e637a
·
1 Parent(s): 288b0ef

modularized

Browse files
maths/vectors/vector_add.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Add two vectors of the same dimension using NumPy.
3
+ """
4
+ import numpy as np
5
+ from typing import List, Union
6
+
7
+ Vector = Union[List[float], np.ndarray]
8
+
9
+ def vector_add(vector1: Vector, vector2: Vector) -> np.ndarray:
10
+ v1 = np.array(vector1)
11
+ v2 = np.array(vector2)
12
+ if v1.shape != v2.shape:
13
+ raise ValueError("Vectors must have the same dimensions for addition.")
14
+ return np.add(v1, v2)
maths/vectors/{vectors.py → vector_cross_product.py} RENAMED
@@ -1,32 +1,11 @@
1
  """
2
- Vector operations for university level, using NumPy.
3
  """
4
  import numpy as np
5
  from typing import List, Union
6
 
7
  Vector = Union[List[float], np.ndarray]
8
 
9
- def vector_add(vector1: Vector, vector2: Vector) -> np.ndarray:
10
- v1 = np.array(vector1)
11
- v2 = np.array(vector2)
12
- if v1.shape != v2.shape:
13
- raise ValueError("Vectors must have the same dimensions for addition.")
14
- return np.add(v1, v2)
15
-
16
- def vector_subtract(vector1: Vector, vector2: Vector) -> np.ndarray:
17
- v1 = np.array(vector1)
18
- v2 = np.array(vector2)
19
- if v1.shape != v2.shape:
20
- raise ValueError("Vectors must have the same dimensions for subtraction.")
21
- return np.subtract(v1, v2)
22
-
23
- def vector_dot_product(vector1: Vector, vector2: Vector) -> float:
24
- v1 = np.array(vector1)
25
- v2 = np.array(vector2)
26
- if v1.shape != v2.shape:
27
- raise ValueError("Vectors must have the same dimensions for dot product.")
28
- return np.dot(v1, v2)
29
-
30
  def vector_cross_product(vector1: Vector, vector2: Vector) -> np.ndarray:
31
  v1 = np.array(vector1)
32
  v2 = np.array(vector2)
 
1
  """
2
+ Compute the cross product of two 3-dimensional vectors using NumPy.
3
  """
4
  import numpy as np
5
  from typing import List, Union
6
 
7
  Vector = Union[List[float], np.ndarray]
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  def vector_cross_product(vector1: Vector, vector2: Vector) -> np.ndarray:
10
  v1 = np.array(vector1)
11
  v2 = np.array(vector2)
maths/vectors/vector_dot_product.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Compute the dot product of two vectors of the same dimension using NumPy.
3
+ """
4
+ import numpy as np
5
+ from typing import List, Union
6
+
7
+ Vector = Union[List[float], np.ndarray]
8
+
9
+ def vector_dot_product(vector1: Vector, vector2: Vector) -> float:
10
+ v1 = np.array(vector1)
11
+ v2 = np.array(vector2)
12
+ if v1.shape != v2.shape:
13
+ raise ValueError("Vectors must have the same dimensions for dot product.")
14
+ return np.dot(v1, v2)
maths/vectors/vector_subtract.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Subtract one vector from another of the same dimension using NumPy.
3
+ """
4
+ import numpy as np
5
+ from typing import List, Union
6
+
7
+ Vector = Union[List[float], np.ndarray]
8
+
9
+ def vector_subtract(vector1: Vector, vector2: Vector) -> np.ndarray:
10
+ v1 = np.array(vector1)
11
+ v2 = np.array(vector2)
12
+ if v1.shape != v2.shape:
13
+ raise ValueError("Vectors must have the same dimensions for subtraction.")
14
+ return np.subtract(v1, v2)
maths/vectors/vectors_interface.py CHANGED
@@ -5,9 +5,10 @@ import gradio as gr
5
  import numpy as np
6
  import json
7
  from typing import Union
8
- from maths.vectors.vectors import (
9
- vector_add, vector_subtract, vector_dot_product, vector_cross_product
10
- )
 
11
 
12
  def parse_vector(vector_str: str) -> np.ndarray:
13
  try:
 
5
  import numpy as np
6
  import json
7
  from typing import Union
8
+ from maths.vectors.vector_add import vector_add
9
+ from maths.vectors.vector_subtract import vector_subtract
10
+ from maths.vectors.vector_dot_product import vector_dot_product
11
+ from maths.vectors.vector_cross_product import vector_cross_product
12
 
13
  def parse_vector(vector_str: str) -> np.ndarray:
14
  try: