Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 32 additions & 18 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
# TODO: make all functions work with strings as well
# TODO: add a new cool calculator function

def sum(a: int, b: int) -> int:
def sum(a: float, b: float) -> float:
'''
This function returns the sum of two numbers
This function returns the sum of two floating-point numbers.

Args:
a: float the first number
b: float the second number
a (float): The first number.
b (float): The second number.

Returns:
float the sum of a and b
float: The sum of a and b.
'''
return a + b

Expand Down Expand Up @@ -43,6 +43,7 @@ def divide(a: float, b: float) -> float:
'''
return a / b


def modulo(a: int, b: int):
'''
...
Expand All @@ -56,36 +57,49 @@ def modulo(a: int, b: int):
'''

# I think this could be made more efficient?
result = a - (np.floor(a / b) * b)
result = a%b

return result

def element_wise_multiply(a: np.array, b: np.array) -> np.array:
'''
...

Performs element-wise multiplication of two numpy arrays.
Args:
a: np.array
b: np.array
a: np.array - first array
b: np.array - second array

Returns:
np.array
np.array - element-wise product of a and b

Raises:
ValueError: if arrays cannot be broadcast together
TypeError: if inputs are not numpy arrays
'''

# let's hope that both vectors have the same shape

return np.multiply(a, b)

try:
# Check if inputs are numpy arrays
if not isinstance(a, np.ndarray) or not isinstance(b, np.ndarray):
raise TypeError("Both inputs must be numpy arrays")

# Perform element-wise multiplication with automatic broadcasting
result = np.multiply(a, b)
return result

except ValueError as e:
raise ValueError(f"Arrays cannot be multiplied element-wise: {str(e)}")
except Exception as e:
raise Exception(f"Unexpected error during multiplication: {str(e)}")

def return_hexadecimal(a: int) -> float:
'''
...

Args:
a: float
b: float
a: float

Returns:
float
str
'''

return hex(a)
Expand Down