Symbolic extraction range of elements for LazyTensor
objects.
Arguments
- x
a
LazyTensor
or aComplexLazyTensor
.- m
an
integer
corresponding to the starting index (starting from 0) of the range of elements fromx
that will be extracted.- d
an
integer
corresponding to the output dimension, i.e. the number of consecutive elements fromx
that will be extracted.
Details
extract(x_i, m, d)
encodes, symbolically, the extraction
of a range of values x[m:m+d]
in the LazyTensor
x
; (m
is the
starting index, and d
is the dimension of the extracted sub-vector).
IMPORTANT: IN THIS CASE, INDICES START AT ZERO, therefore, m
should
be in [0, n)
, where n
is the inner dimension of x
. And d
should be
in [0, n-m]
.
Note: See the examples for a more concrete explanation regarding the
use of extract()
.
Examples
if (FALSE) {
# Two very rudimentary examples
# -----------------------------
# Let's say that you have a matrix `g` looking like this:
# [,1] [,2] [,3] [,4]
# [1,] 1 8 1 3
# [2,] 2 1 2 7
# [3,] 3 7 4 5
# [4,] 1 3 3 0
# [5,] 5 4 9 4
# Convert it to LazyTensor:
g_i <- LazyTensor(g, index = 'i')
# Then extract some elements:
ext_g <- extract(g_i, 1, 3)
# In this case, `ext_g` is a LazyTensor encoding, symbolically,
# the following part of g:
# [,1] [,2] [,3]
# [1,] 8 1 3
# [2,] 1 2 7
# [3,] 7 4 5
# [4,] 3 3 0
# [5,] 4 9 4
# Same principle with a LazyTensor encoding a vector:
v <- c(1, 2, 3, 1, 5)
Pm_v <- LazyTensor(v)
ext_Pm_v <- extract(Pm_v, 2, 3)
# In this case, `ext_Pm_v` is a LazyTensor encoding, symbolically,
# the following part of v:
# [,1] [,2] [,3]
# [1,] 3 1 5
# A more general example
# ----------------------
x <- matrix(runif(150 * 5), 150, 5) # arbitrary R matrix, 150 rows, 5 columns
x_i <- LazyTensor(x, index = 'i') # LazyTensor from matrix x, indexed by 'i'
m <- 2
d <- 2
extract_x <- extract(x_i, m, d) # symbolic matrix
}