diff --git a/src/utils.py b/src/utils.py index faae9e3..063958b 100644 --- a/src/utils.py +++ b/src/utils.py @@ -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 @@ -43,6 +43,7 @@ def divide(a: float, b: float) -> float: ''' return a / b + def modulo(a: int, b: int): ''' ... @@ -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)