Skip to content
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

[feat] Add new decorator handle_units for unit processing on input and output for a function that does not support unit operations #72

Closed
wants to merge 5 commits into from

Conversation

Routhleck
Copy link
Collaborator

This pull request introduces a new decorator handle_units to the brainunit module and includes corresponding tests for this new functionality. The most important changes include adding the decorator function, updating the list of functions, and creating comprehensive tests.

New functionality:

  • brainunit/_base.py: Added the handle_units decorator function to transform units of arguments passed to a function. This decorator ensures that arguments and return values conform to specified units, raising appropriate errors when mismatches occur.

Updates to existing components:

  • brainunit/_base.py: Included handle_units in the list of functions for checking units and dimensions.

Tests:

  • brainunit/_base_test.py: Added multiple tests for the handle_units decorator, including cases for correct units, incorrect units, boolean checks, and multiple return values. These tests ensure the decorator works as expected and handles various scenarios.

@Routhleck Routhleck changed the title [base] Add new decorator handle_units for unit processing on input and output for a function that does not support unit operations [feat] Add new decorator handle_units for unit processing on input and output for a function that does not support unit operations Dec 3, 2024
Copy link
Collaborator

@chaoming0625 chaoming0625 left a comment

Choose a reason for hiding this comment

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

It seems that assign_units is better, since original function does not have units. Now, we assign standard and explicit units on its inputs and outpus.

@Routhleck
Copy link
Collaborator Author

New pr: #73

@chaoming0625 chaoming0625 deleted the handle-units branch December 11, 2024 13:34
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