Skip to content

Conversation

@N9sha18
Copy link

@N9sha18 N9sha18 commented Jan 19, 2026

Added modern type hints (np.ndarray | list | tuple) to the softmax function to improve code readability and compliance with current Python standards. Verified with doctest (4 passed)

@poyea poyea force-pushed the type-hint-cleanup branch from 3207df5 to f76d44d Compare January 25, 2026 14:02
@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Jan 25, 2026
@poyea poyea requested a review from Copilot January 25, 2026 14:02
@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label Jan 25, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds modern Python type hints to maths/softmax.py to improve readability and align the function signature with current typing style.

Changes:

  • Annotated softmax() input and return types using PEP 604 unions.
  • Cleaned up docstring formatting and doctest inputs for consistency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.



def softmax(vector):
def softmax(vector: np.ndarray | list | tuple) -> np.ndarray:
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new annotation vector: np.ndarray | list | tuple is very broad and loses element-type information. Consider using a typed protocol/ABC (e.g., Sequence[float] from collections.abc) for list/tuple inputs and/or specifying element types (e.g., list[float] | tuple[float, ...]) to make the type hint more informative and consistent with other modules (e.g., maths/polynomial_evaluation.py).

Suggested change
def softmax(vector: np.ndarray | list | tuple) -> np.ndarray:
def softmax(vector: np.ndarray | list[float] | tuple[float, ...]) -> np.ndarray:

Copilot uses AI. Check for mistakes.
Comment on lines +21 to +25
vector (np.array | list | tuple): A numpy array of shape (1,n)
consisting of real values or a similar list, tuple
Returns:
softmax_vec (np.array): The input numpy array after applying
softmax.
np.array: The input numpy array after applying softmax.
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring uses np.array as a type name in Parameters/Returns, but the function returns an np.ndarray and np.array is the constructor function. Updating the docstring to np.ndarray (and adjusting the described shape to match the 1-D examples) would avoid confusion and keep documentation consistent with the new type hints.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants