checkDimensions {pnd} | R Documentation |
Determine function dimensionality and vectorisation
Description
Determine function dimensionality and vectorisation
Usage
checkDimensions(
FUN,
x,
f0 = NULL,
func = NULL,
elementwise = NA,
vectorised = NA,
multivalued = NA,
deriv.order = 1,
acc.order = 2,
side = 0,
h = NULL,
zero.tol = sqrt(.Machine$double.eps),
cores = 1,
preschedule = TRUE,
cl = NULL,
...
)
## S3 method for class 'checkDimensions'
print(x, ...)
Arguments
FUN |
A function returning a numeric scalar or a vector whose derivatives are to be computed. If the function returns a vector, the output will be a Jacobian. |
x |
Numeric vector or scalar: the point(s) at which the derivative is estimated.
|
f0 |
Optional numeric: if provided, used to determine the vectorisation type to save time. If FUN(x) must be evaluated (e.g. second derivatives), saves one evaluation. |
func |
For compatibility with |
elementwise |
Logical: is the domain effectively 1D, i.e. is this a mapping
|
vectorised |
Logical: if |
multivalued |
Logical: if |
deriv.order |
Integer or vector of integers indicating the desired derivative order,
|
acc.order |
Integer or vector of integers specifying the desired accuracy order
for each element of |
side |
Integer scalar or vector indicating the type of finite difference:
|
h |
Numeric or character specifying the step size(s) for the numerical
difference or a method of automatic step determination ( |
zero.tol |
Small positive integer: if |
cores |
Integer specifying the number of CPU cores used for parallel computation. Recommended to be set to the number of physical cores on the machine minus one. |
preschedule |
Logical: if |
cl |
An optional user-supplied |
... |
Ignored. |
Details
The following combinations of parameters are allowed, suggesting specific input and output handling by other functions:
elementwise | !elementwise |
|
!multivalued , vectorised | FUN(xgrid) | (undefined) |
!multivalued , !vectorised | [mc]lapply(xgrid, FUN) | [mc]lapply gradient |
multivalued , vectorised | (undefined) | FUN(xgrid) Jacobian |
multivalued , !vectorised | (undefined) | [mc]lapply Jacobian |
Some combinations are impossible: multi-valued functions cannot be element-wise, and single-valued vectorised functions must element-wise.
In brief, testing the input and output length and vectorisation capabilities may result in five
cases, unlike 3 in numDeriv::grad()
that does not provide checks for Jacobians.
Value
A named logical vector indicating if a function is element-wise or not, vectorised or not, and multivalued or not.
Examples
checkDimensions(sin, x = 1:4, h = 1e-5) # Rn -> Rn vectorised
checkDimensions(function(x) integrate(sin, 0, x)$value, x = 1:4, h = 1e-5) # non vec
checkDimensions(function(x) sum(sin(x)), x = 1:4, h = 1e-5) # Rn -> R, gradient
checkDimensions(function(x) c(sin(x), cos(x)), x = 1, h = 1e-5) # R -> Rn, Jacobian
checkDimensions(function(x) c(sin(x), cos(x)), x = 1:4, h = 1e-5) # vec Jac
checkDimensions(function(x) c(integrate(sin, 0, x)$value, integrate(sin, -x, 0)$value),
x = 1:4, h = 1e-5) # non-vectorised Jacobian