From 6a7d0ca23ac97934e2f059bb50beccb6ed9a572c Mon Sep 17 00:00:00 2001 From: AdrianSosic Date: Fri, 20 Dec 2024 10:11:11 +0100 Subject: [PATCH] Add admonition mentioning decorator utility --- docs/userguide/simulation.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/userguide/simulation.md b/docs/userguide/simulation.md index dd2655b16..80ca9f6fb 100644 --- a/docs/userguide/simulation.md +++ b/docs/userguide/simulation.md @@ -55,6 +55,25 @@ def lookup(df: pd.DataFrame) -> pd.DataFrame: lookup(searchspace.continuous.sample_uniform(10)) ``` +````{admonition} Array-Based Callables +:class: tip +If you already have a lookup callable available in an array-based format (for instance, +if your lookup values are generated using third-party code that works with array inputs +and outputs), you can effortlessly convert this callable into the required +dataframe-based format by applying our +{func}`~baybe.utils.dataframe.arrays_to_dataframes` decorator. + +For example, the above lookup can be equivalently created as follows: +```python +@arrays_to_dataframes(["p1"], ["t1"]) +def lookup(array: np.ndarray) -> np.ndarray: + """The same lookup function in array logic.""" + return array ** 2 +``` + +```` + + ### Using a Dataframe When dealing with discrete search spaces, it is also possible to provide the lookup values in a tabular representation using a dataframe.