-
Notifications
You must be signed in to change notification settings - Fork 53
/
out-vectorisation.qmd
16 lines (13 loc) · 1.01 KB
/
out-vectorisation.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Vectorisation {#sec-out-vectorisation}
```{r}
#| include = FALSE
source("common.R")
```
Vectorisation has two meanings: it can refer to either the interface of a function, or its implementation.
We can make a precise statement about what a vectorised interface is.
A function, `f`, is vectorised over a vector argument, `x`, iff `f(x)[[i]]` equals `f(x[[i]])`, i.e. we can exchange the order of subsetting and function application.
This generalises naturally to more arguments: we say `f` is vectorised over `x` and `y` if `f(x[[i]], y[[i]])` equals `f(x, y)[[i]]`.
A function can have some arguments that are vectorised and some that are not, `f(x, ...)[[i]]` equals `f(x[[i]], ...)`.
It is harder to define vectorised implementation.
It's necessary for a function with a vectorised implementation to have a vectorised interface, but it also must possess the property of computational efficiency.
It's hard to make this precise, but generally it means that if there is an explicit loop, that loop is written in C or C++, not in a R.