Encode an array as HEMatrix. Input data should be 1-dim or 2-dim. If the input is 1-dimensional, it will be repeated along axis = 0 and encoded. If the input is 2-dimensional, its number of rows should be smaller than or equal to unit_shape1.

encode(context, X, unit_shape)

Arguments

context:

(Context) - Context of HE.

array:

(array) - Input data.frame or matrix.

unit_shape:

(integer vector) - Unit encoding shape for matrix.

Value

HEMatrix: Encoded HEMatrix.

Examples

if (FALSE) {
params <- heaan_sdk.HEParameter("FGb")
context <- heaan_sdk.Context(
     params,
     key_dir_path = key_dir_path,
     load_keys = "all",
     generate_keys = TRUE)
library(caret)
data(iris)
set.seed(34)
trainIndex <- createDataPartition(iris$Species,
             times = 1, p = 0.8, list = FALSE)
X_train <- iris[trainIndex, 1:4]
X_test <- iris[-trainIndex, 1:4]
y_train <- as.integer(iris[trainIndex, 5]) - 1
y_test <- as.integer(iris[-trainIndex, 5])- 1
classes <- c(0, 1, 2)
num_feature <- ncol(X_train)
batch_size <- 128
unit_shape <- (as.integer(c(batch_size,
             floor(py_to_r(context$num_slots) / batch_size))))
encode(context, X_test, unit_shape)
}