Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

setSize

set the size of a numeric variable in NIMBLE


Description

set the size of a numeric variable in NIMBLE. This works in R and NIMBLE, but in R it usually has no effect.

Usage

setSize(numObj, ..., copy = TRUE, fillZeros = TRUE)

Arguments

numObj

This is the object to be resized

...

sizes, provided as scalars, in order, or as a single vector

copy

logical indicating whether values should be preserved (in column-major order)

fillZeros

logical indicating whether newly allocated space should be initialized with zeros (in compiled code)

Details

Note that assigning the result of numeric, integer, logical, matrix, or array is often as good or better than using setSize. For example, 'x <- matrix(nrow = 5, ncol = 5)' is equivalent to 'setSize(x, 5, 5)' but the former allows more control over initialization.

This function is part of the NIMBLE language. Its purpose is to explicitly resize a multivariate object (vector, matrix or array), currently up to 4 dimensions. Explicit resizing is not needed when an entire object is assigned to. For example, in Y <- A %*% B, where A and B are matrices, Y will be resized automatically. Explicit resizing is necessary when assignment will be by indexed elements or blocks, if the object is not already an appropriate size for the assignment. E.g. prior to Y[5:10] <- A %*% B, one can use setSize to ensure that Y has a size (length) of at least 10.

This does work in uncompiled (R) and well as compiled execution, but in some cases it is only necessary for compiled execution. During uncompiled execution, it may not catch bugs due to resizing because some R objects will be dynamically resized during assignments anyway.

If preserving values in the resized object and/or initializing new values with 0 is not necessary, then setting these arguments to FALSE will yield slightly more efficient compiled code.

Author(s)

NIMBLE development team


nimble

MCMC, Particle Filtering, and Programmable Hierarchical Modeling

v0.11.0
BSD_3_clause + file LICENSE | GPL (>= 2)
Authors
Perry de Valpine [aut], Christopher Paciorek [aut, cre], Daniel Turek [aut], Nick Michaud [aut], Cliff Anderson-Bergman [aut], Fritz Obermeyer [aut], Claudia Wehrhahn Cortes [aut] (Bayesian nonparametrics system), Abel Rodrìguez [aut] (Bayesian nonparametrics system), Duncan Temple Lang [aut] (packaging configuration), Sally Paganin [aut] (reversible jump MCMC), Jagadish Babu [ctb] (code for the compilation system for an early version of NIMBLE), Lauren Ponisio [ctb] (contributions to the cross-validation code), Peter Sujan [ctb] (multivariate t distribution code)
Initial release
2021-04-16

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.