Skip to content

Commit

Permalink
Update vignettes to explain memoisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Grenié committed Mar 20, 2024
1 parent 5d902a9 commit 2535ec2
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 94 deletions.
4 changes: 3 additions & 1 deletion vignettes/_fundiversity_1-parallel.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ Note: This vignette presents some performance tests ran between non-parallel and

Within `fundiversity` the computation of most indices can be parallelized using the `future` package. The goal of this vignette is to explain how to toggle and use parallelization in `fundiversity`. The functions that currently support parallelization are summarized in the table below:

```{r child="man/rmdchunks/_fundiversity_functions.Rmd"}
```{r child="../man/rmdchunks/_fundiversity_functions.Rmd"}
```

Note that **memoization and parallelization cannot be used at the same time**. If the option `fundiversity.memoise` has been set to `TRUE` but the computation are parallelized, `fundiversity` will use unmemoised version of functions.

The `future` package provides a simple and general framework to allow asynchronous computation depending on the resources available for the user. The [first vignette of `future`](https://cran.r-project.org/package=future) gives a general overview of all its features. The main idea being that the user should write the code once and that it would run seamlessly sequentially, or in parallel on a single computer, or on a cluster, or distributed over several computers. `fundiversity` can thus run on all these different backends following the user's choice.

```{r setup}
Expand Down
2 changes: 1 addition & 1 deletion vignettes/fundiversity.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Each row gives the standardized FRic values of each site.

**Parallelization**. The computation of this function can be parallelized thanks to the `future` package. Refer to the [parallelization vignette](./fundiversity_1-parallel.html) to get more information about how to do so.

**Memoization**. By default, when loading `fundiversity`, the functions to compute convex hulls are [memoised](https://en.wikipedia.org/wiki/Memoization) through the `memoise` package if it is installed. It means that repeated calls to `fd_fric()` with similar arguments won't be recomputed each time but recovered from memory. To deactivate this behavior you can set the option `fundiversity.memoise` to `FALSE` by running the following line: `options(fundiversity.memoise = FALSE)`. If you use it interactively it will only affect your current session. Add it to your script(s) or `.Rprofile` file to avoid toggling it each time.
**Memoization**. By default, when loading `fundiversity`, the functions to compute convex hulls are [memoised](https://en.wikipedia.org/wiki/Memoization) through the `memoise` package if it is installed (their results are cached to avoid recomputing the same functional volume twice). To deactivate this behavior you can set the option `fundiversity.memoise` to `FALSE` by running the following line: `options(fundiversity.memoise = FALSE)`. If you use it interactively it will only affect your current session. Add it to your script(s) or `.Rprofile` file to avoid toggling it each time. By changing the option, the behavior will automatically change the next time you run the function. **Note**: memoisation is only available when the `memoise` package has been installed **and without parallelization**, otherwise `fundiversity` will use unmemoised versions of the functions.


# Functional volume intersect (FRic_intersect) - `fd_fric_intersect()`
Expand Down
Loading

0 comments on commit 2535ec2

Please sign in to comment.