-
-
Notifications
You must be signed in to change notification settings - Fork 50k
refactor: add type hints to maths/softmax.py #14153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
3207df5 to
f76d44d
Compare
There was a problem hiding this 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: |
Copilot
AI
Jan 25, 2026
There was a problem hiding this comment.
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).
| def softmax(vector: np.ndarray | list | tuple) -> np.ndarray: | |
| def softmax(vector: np.ndarray | list[float] | tuple[float, ...]) -> np.ndarray: |
| 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. |
Copilot
AI
Jan 25, 2026
There was a problem hiding this comment.
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.
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)