Skip to content

Commit

Permalink
alias for unit processing functions (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoming0625 authored Nov 16, 2024
1 parent 27b84e4 commit ce03111
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 20 deletions.
10 changes: 5 additions & 5 deletions brainunit/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@
'Unit',
'Quantity',

# helpers
# errors
'DimensionMismatchError',
'UnitMismatchError',
'DIMENSIONLESS',
'UNITLESS',

# helpers
'is_dimensionless',
'is_unitless',
'get_dim',
Expand All @@ -48,10 +52,6 @@
'display_in_unit',
'maybe_decimal',

# helper classes
'DIMENSIONLESS',
'UNITLESS',

# functions for checking
'check_dims',
'check_units',
Expand Down
4 changes: 4 additions & 0 deletions brainunit/math/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

from ._activation import *
from ._activation import __all__ as _activation_all
from ._alias import *
from ._alias import __all__ as _alias_all
from ._einops import *
from ._einops import __all__ as _einops_all
from ._fun_accept_unitless import *
Expand All @@ -31,6 +33,7 @@
from ._misc import __all__ as _compat_misc_all

__all__ = (_compat_array_creation_all +
_alias_all +
_compat_funcs_change_unit_all +
_compat_funcs_keep_unit_all +
_compat_funcs_accept_unitless_all +
Expand All @@ -40,6 +43,7 @@
_activation_all)

del (_compat_array_creation_all,
_alias_all,
_compat_funcs_change_unit_all,
_compat_funcs_keep_unit_all,
_compat_funcs_accept_unitless_all,
Expand Down
41 changes: 41 additions & 0 deletions brainunit/math/_alias.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2024 BDP Ecosystem Limited. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================


from brainunit._base import (is_dimensionless, is_unitless, get_dim, get_unit, get_mantissa, get_magnitude,
display_in_unit, maybe_decimal, check_dims, check_units,
fail_for_dimension_mismatch, fail_for_unit_mismatch,
assert_quantity, get_or_create_dimension)

__all__ = [
'is_dimensionless',
'is_unitless',
'get_dim',
'get_unit',
'get_mantissa',
'get_magnitude',
'display_in_unit',
'maybe_decimal',

# functions for checking
'check_dims',
'check_units',
'fail_for_dimension_mismatch',
'fail_for_unit_mismatch',
'assert_quantity',

# advanced functions
'get_or_create_dimension',
]
21 changes: 6 additions & 15 deletions docs/apis/brainunit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@



Base Classes
------------
Data Structures
---------------

.. autosummary::
:toctree: generated/
Expand All @@ -16,26 +16,17 @@ Base Classes

Quantity
Unit
UnitMismatchError
Dimension
DimensionMismatchError


Helper Functions
----------------
Errors
------

.. autosummary::
:toctree: generated/
:nosignatures:
:template: classtemplate.rst

get_or_create_dimension
get_unit
get_dim
is_unitless
is_dimensionless
check_dims
check_units
fail_for_dimension_mismatch
fail_for_unit_mismatch
UnitMismatchError
DimensionMismatchError

1 change: 1 addition & 0 deletions docs/auto_generater.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ def main():
template=True)

module_and_name = [
('_alias', 'Unit Processing'),
('_einops', 'Einstein Operations'),
('_fun_accept_unitless', 'Functions that Accepting Unitless'),
('_fun_array_creation', 'Array Creation Functions'),
Expand Down

0 comments on commit ce03111

Please sign in to comment.