Skip to contents

Defines a repeated-space mapper that sums the contributions for each copy. The ibm_n() method returns ibm_n(mapper) * n_rep, and ibm_values() returns seq_len(ibm_n(mapper)).

Usage

bm_repeat(mapper, n_rep, interleaved = FALSE)

bru_mapper_repeat(...)

Arguments

mapper

The mapper to be repeated.

n_rep

The number of times to repeat the mapper. If a vector, the non-interleaved repeats are combined into a single repeat mapping, and combined with interleaved repeats via a bm_sum() of mappers.

interleaved

logical; if TRUE, the repeated mapping columns are interleaved; (x1[1], x2[1], ..., x1[2], x2[2], ...). If FALSE (default), the repeated mapping columns are contiguous, (x1[1], x1[2], ..., x2[1], x2[2], ...), and the Jacobian is a cbind() of the Jacobians of the repeated mappers.

If n_rep is a vector, interleaved should either be a single logical, or a vector of the same length. Each element applies to the corresponding n_rep repetition specification.

...

Arguments passed on to bm_scale()

Value

A bm_repeat or bm_sum object, or the original input mapper.

Examples

(m0 <- bm_index(3))
#> index
(m <- bm_repeat(m0, 5))
#> repeat(5 x index)
ibm_n(m)
#> [1] 15
ibm_values(m)
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
ibm_jacobian(m, 1:3)
#> 3 x 15 sparse Matrix of class "dgCMatrix"
#>                                   
#> [1,] 1 . . 1 . . 1 . . 1 . . 1 . .
#> [2,] . 1 . . 1 . . 1 . . 1 . . 1 .
#> [3,] . . 1 . . 1 . . 1 . . 1 . . 1
ibm_eval(m, 1:3, seq_len(ibm_n(m)))
#> [1] 35 40 45

# Interleaving and grouping
(m <- bm_repeat(m0, c(2, 1, 2), c(TRUE, FALSE, FALSE)))
#> sum(1 = repeat(2 x index, interleaved), 2 = repeat(3 x index))
ibm_n(m)
#> [1] 15
ibm_values(m)
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
ibm_jacobian(m, 1:3)
#> 3 x 15 sparse Matrix of class "dgCMatrix"
#>                                   
#> [1,] 1 1 . . . . 1 . . 1 . . 1 . .
#> [2,] . . 1 1 . . . 1 . . 1 . . 1 .
#> [3,] . . . . 1 1 . . 1 . . 1 . . 1
ibm_eval(m, 1:3, seq_len(ibm_n(m)))
#> [1] 33 40 47