generated from aequitas-aod/template-python-project-poetry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(doc): add some documentation and redispose code
- Loading branch information
Showing
4 changed files
with
40 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,25 @@ | ||
import logging | ||
import types | ||
import typing | ||
import numpy | ||
|
||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
logger = logging.getLogger('aequitas') | ||
|
||
Scalar = typing.Union[int, float, bool, complex, str, numpy.generic] | ||
|
||
# keep this line at the top of this file | ||
__all__ = ["logger", "isinstance"] | ||
|
||
EPSILON: float = 1e-9 | ||
|
||
|
||
def is_zero(x: Scalar) -> bool: | ||
return abs(x) < EPSILON | ||
logging.basicConfig(level=logging.DEBUG) | ||
logger = logging.getLogger('aequitas') | ||
"""General logger to be used in all `aequitas*` modules""" | ||
|
||
|
||
__py_isinstance = isinstance | ||
|
||
|
||
def isinstance(obj, cls): | ||
"""A version of `isinstance` that takes type unions into account""" | ||
|
||
if hasattr(cls, '__args__') and __py_isinstance(cls.__args__, tuple): | ||
return any(__py_isinstance(obj, t) for t in cls.__args__) | ||
return __py_isinstance(obj, cls) | ||
|
||
|
||
# let this be the last line of this file | ||
# keep this line at the bottom of this file | ||
logger.debug("Module %s correctly loaded", __name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,32 @@ | ||
import aequitas | ||
import typing | ||
import numpy | ||
|
||
# let this be the last line of this file | ||
|
||
# keep this line at the top of this file | ||
__all__ = ['Scalar', 'DEFAULT_EPSILON', 'is_zero'] | ||
|
||
|
||
Scalar = typing.Union[int, float, bool, complex, str, numpy.generic] | ||
"""General type for scalars (numbers, strings, or NumPy scalars) | ||
Also see: https://numpy.org/doc/stable/reference/arrays.scalars.html | ||
""" | ||
|
||
|
||
DEFAULT_EPSILON: float = 1e-9 | ||
"""Default threshold for floating-point comparisons""" | ||
|
||
|
||
def is_zero(x: Scalar, epsilon: float = DEFAULT_EPSILON) -> bool: | ||
"""Checks whether `x` is zero, up to a given threshold | ||
:param x: the scalar to check | ||
:param epsilon: the threshold for the comparison (defaults to `DEFAULT_EPSILON`) | ||
""" | ||
|
||
return abs(x) < epsilon | ||
|
||
|
||
# keep this line at the bottom of this file | ||
aequitas.logger.debug("Module %s correctly loaded", __name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
scikit-learn==1.3.0 | ||
numpy ==1.25.2 | ||
numpy==1.25.2 |