-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add single array transformations (#32)
- Loading branch information
Showing
21 changed files
with
515 additions
and
69 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
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
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 |
---|---|---|
|
@@ -18,9 +18,7 @@ classifiers = [ | |
"Programming Language :: Python :: 3.11", | ||
] | ||
description = "Fast implementations of common forecasting routines" | ||
authors = [ | ||
{name = "José Morales", email = "[email protected]"}, | ||
] | ||
authors = [{ name = "José Morales", email = "[email protected]" }] | ||
readme = "README.md" | ||
keywords = ["forecasting", "time-series"] | ||
|
||
|
@@ -39,15 +37,11 @@ logging.level = "INFO" | |
sdist.exclude = ["tests", "*.yml"] | ||
sdist.reproducible = true | ||
wheel.install-dir = "coreforecast" | ||
wheel.packages = ["coreforecast"] | ||
wheel.packages = ["python/coreforecast"] | ||
wheel.py-api = "py3" | ||
|
||
[tool.cibuildwheel] | ||
archs = "all" | ||
build-verbosity = 3 | ||
macos.before-build = [ | ||
"brew install libomp", | ||
"./scripts/switch_xcode", | ||
] | ||
test-requires = "pandas pytest window-ops" | ||
test-command = "pytest {project}/tests -k correct" | ||
macos.before-build = ["brew install libomp", "./scripts/switch_xcode"] | ||
test-command = 'python -c "import coreforecast._lib"' |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
__all__ = [ | ||
"expanding_mean", | ||
"expanding_std", | ||
"expanding_min", | ||
"expanding_max", | ||
"expanding_quantile", | ||
] | ||
|
||
import ctypes | ||
from typing import Callable | ||
|
||
import numpy as np | ||
|
||
from ._lib import _LIB | ||
from .utils import ( | ||
_data_as_void_ptr, | ||
_ensure_float, | ||
_float_arr_to_prefix, | ||
_pyfloat_to_np_c, | ||
) | ||
|
||
|
||
def _expanding_stat(x: np.ndarray, stat: str) -> np.ndarray: | ||
x = _ensure_float(x) | ||
prefix = _float_arr_to_prefix(x) | ||
out = np.empty_like(x) | ||
_LIB[f"{prefix}_Expanding{stat}Transform"]( | ||
_data_as_void_ptr(x), | ||
ctypes.c_int(x.size), | ||
_data_as_void_ptr(out), | ||
) | ||
return out | ||
|
||
|
||
def _expanding_docstring(*args, **kwargs) -> Callable: | ||
base_docstring = """Compute the {} of the input array. | ||
Args: | ||
x (np.ndarray): Input array. | ||
Returns: | ||
np.ndarray: Array with the expanding statistic | ||
""" | ||
|
||
def docstring_decorator(function: Callable): | ||
function.__doc__ = base_docstring.format(function.__name__) | ||
return function | ||
|
||
return docstring_decorator(*args, **kwargs) | ||
|
||
|
||
@_expanding_docstring | ||
def expanding_mean(x: np.ndarray) -> np.ndarray: | ||
return _expanding_stat(x, "Mean") | ||
|
||
|
||
@_expanding_docstring | ||
def expanding_std(x: np.ndarray) -> np.ndarray: | ||
return _expanding_stat(x, "Std") | ||
|
||
|
||
@_expanding_docstring | ||
def expanding_min(x: np.ndarray) -> np.ndarray: | ||
return _expanding_stat(x, "Min") | ||
|
||
|
||
@_expanding_docstring | ||
def expanding_max(x: np.ndarray) -> np.ndarray: | ||
return _expanding_stat(x, "Max") | ||
|
||
|
||
def expanding_quantile(x: np.ndarray, p: float) -> np.ndarray: | ||
"""Compute the expanding_quantile of the input array. | ||
Args: | ||
x (np.ndarray): Input array. | ||
p (float): Quantile to compute. | ||
Returns: | ||
np.ndarray: Array with the expanding statistic | ||
""" | ||
x = _ensure_float(x) | ||
prefix = _float_arr_to_prefix(x) | ||
out = np.empty_like(x) | ||
_LIB[f"{prefix}_ExpandingQuantileTransform"]( | ||
_data_as_void_ptr(x), | ||
ctypes.c_int(x.size), | ||
_pyfloat_to_np_c(p, x.dtype), | ||
_data_as_void_ptr(out), | ||
) | ||
return out |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
__all__ = ["exponentially_weighted_mean"] | ||
|
||
import ctypes | ||
|
||
import numpy as np | ||
|
||
from ._lib import _LIB | ||
from .utils import ( | ||
_ensure_float, | ||
_float_arr_to_prefix, | ||
_data_as_void_ptr, | ||
_pyfloat_to_np_c, | ||
) | ||
|
||
|
||
def exponentially_weighted_mean(x: np.ndarray, alpha: float) -> np.ndarray: | ||
"""Compute the exponentially weighted mean of the input array. | ||
Args: | ||
x (np.ndarray): Input array. | ||
alpha (float): Weight parameter. | ||
Returns: | ||
np.ndarray: Array with the exponentially weighted mean. | ||
""" | ||
x = _ensure_float(x) | ||
prefix = _float_arr_to_prefix(x) | ||
out = np.empty_like(x) | ||
_LIB[f"{prefix}_ExponentiallyWeightedMeanTransform"]( | ||
_data_as_void_ptr(x), | ||
ctypes.c_int(x.size), | ||
_pyfloat_to_np_c(alpha, x.dtype), | ||
_data_as_void_ptr(out), | ||
) | ||
return out |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.