This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
-
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.
* docs(function.py): update docstrings * refactor(check_vector): add n_min and n_max parameters * feat: add create_coordinates2d * docs: show only visualization module in API * refactor: rename Config to VizConfig * refactor: import structure and visualization separately * feat: add create_line_plot * test: rename ax to actual * style: remove bracket * docs(create_coordinates3d): change type * feat: add create_discrete_cmap * feat: add FunctionPlotter * style: change VizConfig docstring * refactor: remove config.py * refactor: fBench-functions.ipynb * feat: example.ipynb * refactor: rename visualization module to viz * style: use capital letter BREAKING CHANGE: New function signature for check_vector and rename visualization module to viz
- Loading branch information
1 parent
6461d1f
commit 4c4aa5e
Showing
16 changed files
with
1,342 additions
and
451 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
:hidden: | ||
fBench-functions.ipynb | ||
example.ipynb | ||
changelog.md | ||
contributing.md | ||
developers.md | ||
|
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,43 +1,43 @@ | ||
import numpy as np | ||
|
||
from fbench import exception | ||
|
||
__all__ = ("check_vector",) | ||
|
||
|
||
def check_vector(x, /, *, min_elements): | ||
"""Validate an n-dimensional vector. | ||
def check_vector(x, /, *, n_min=1, n_max=np.inf): | ||
"""Validate :math:`n`-vector. | ||
Parameters | ||
---------- | ||
x : array_like | ||
Input data with :math:`n` elements that can be converted to an array. | ||
min_elements : int | ||
Specify the minimum number of elements ``x`` must have. | ||
The input object to be validated to represent an :math:`n`-vector. | ||
n_min : int, default=1 | ||
Specify the minimum number of :math:`n`. | ||
n_max : int, default=inf | ||
Specify the maximum number of :math:`n`. | ||
Returns | ||
------- | ||
np.ndarray | ||
The :math:`n`-dimensional vector. | ||
The :math:`n`-vector. | ||
Raises | ||
------ | ||
NotAVectorError | ||
If ``x`` is not vector-like. | ||
IncorrectNumberOfElements | ||
If ``x`` does not satisfy the ``min_elements`` condition. | ||
TypeError | ||
- If ``x`` is not vector-like. | ||
- If ``n`` is not between ``n_min`` and ``n_max``. | ||
Examples | ||
-------- | ||
>>> import fbench | ||
>>> fbench.check_vector([0, 0]) | ||
array([0, 0]) | ||
""" | ||
x = np.asarray(x) | ||
x = np.atleast_1d(x) | ||
|
||
if len(x.shape) != 1: | ||
raise exception.NotAVectorError( | ||
f"input must be vector-like object - it has shape={x.shape}" | ||
) | ||
|
||
if not len(x) >= min_elements: | ||
raise exception.IncorrectNumberOfElements( | ||
f"number of elements must be at least {min_elements} " | ||
f"- it has {x.shape[0]}" | ||
) | ||
raise TypeError(f"input must be a vector-like object - it has shape={x.shape}") | ||
|
||
if not (n_min <= len(x) <= n_max): | ||
raise TypeError(f"n={len(x)} is not between n_min={n_min} and n_max={n_max}") | ||
|
||
return x |
Oops, something went wrong.