if (FALSE) {
# Data
nx <- 100
ny <- 150
x <- matrix(runif(nx * 3), nrow = nx, ncol = 3) # arbitrary R matrix representing
# 100 data points in R^3
y <- matrix(runif(ny * 3), nrow = ny, ncol = 3) # arbitrary R matrix representing
# 150 data points in R^3
s <- 0.1 # scale parameter
# Turn our Tensors into KeOps symbolic variables:
x_i <- LazyTensor(x, "i") # symbolic object representing an arbitrary row of x,
# indexed by the letter "i"
y_j <- LazyTensor(y, "j") # symbolic object representing an arbitrary row of y,
# indexed by the letter "j"
# Perform large-scale computations, without memory overflows:
D_ij <- sum((x_i - y_j)^2) # symbolic matrix of pairwise squared distances,
# with 100 rows and 150 columns
K_ij <- exp(- D_ij / s^2) # symbolic matrix, 100 rows and 150 columns
res <- sum(K_ij, index = "i") # actual R matrix (in fact a row vector of
# length 150 here)
# containing the column sums of K_ij
# (i.e. the sums over the "i" index, for each
# "j" index)
# Example : create ComplexLazyTensor:
z <- matrix(1i^ (-6:5), nrow = 4) # create a complex 4x3 matrix
z_i <- LazyTensor(z, index = 'i', is_complex = TRUE) # create a ComplexLazyTensor,
# indexed by 'i'
}
Run the code above in your browser using DataLab