Insert a given value, vector of values or matrix of values (stored in a
LazyTensor
) in a symbolic vector or matrix of zeros.
Arguments
- x
a
LazyTensor
or aComplexLazyTensor
.- m
an
integer
corresponding to the starting index (starting from 0) where the elements fromx
will be inserted.- d
an
integer
corresponding to the output inner dimension.
Details
If x
is a LazyTensor
encoding a vector (resp. a matrix),
extractT(x, m, d)
encodes, symbolically, a d
-inner-dimensional
vector (resp. matrix) of zeros in which is inserted x
,
at starting position m+1
.
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 1: x
can also encode a single value, in which case the
operation works the same way as in the case of a vector of values.
Note 2: See the examples for a more concrete explanation regarding the
use of extractT()
.
Examples
if (FALSE) {
# I - Three very rudimentary examples
# -----------------------------------
# 1) Let's say that you have a matrix `g` looking like this:
# [,1] [,2]
# [1,] 1 4
# [2,] 2 5
# [3,] 3 6
# Convert it to LazyTensor:
g_i <- LazyTensor(g, index = 'i') # indexed by 'i' (for example)
# Then insert it in a matrix of inner dimension equal to 5,
# starting at index 1:
extT_g <- extractT(g_i, 1, 5)
# In this case, `extT_g` is a LazyTensor encoding, symbolically,
# the following matrix:
# [,1] [,2] [,3] [,4] [,5]
# [1,] 0 1 4 0 0
# [2,] 0 2 5 0 0
# [3,] 0 3 6 0 0
# 2) Same principle with a LazyTensor encoding a vector:
v <- c(1, 2, 3, 1, 5)
Pm_v <- LazyTensor(v)
extT_Pm_v <- extract(Pm_v, 2, 3)
# In this case, `extT_Pm_v` is a LazyTensor encoding, symbolically,
# the following vector:
# [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
# [1,] 0 1 2 3 1 5 0 0
# 3) Same again with a scalar value:
scal <- 3.14
Pm_scal <- Pm(scal) # `Pm(x)` is an aliases for `LazyTensor(x, index = NA)`
extT_Pm_scal <- extractT(Pm_scal, 2, 4)
# In this case, `extT_Pm_scal` is a LazyTensor encoding, symbolically,
# the following vector:
# [,1] [,2] [,3] [,4]
# [1,] 0 0 3.14 0
# II - A more general example
# ---------------------------
x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns
x_i <- LazyTensor(x, index = 'i') # LazyTensor from matrix x, 'i' indexed
m <- 2
d <- 7
extractT_x <- extractT(x_i, m, d) # symbolic matrix
}