matrix_multiply
GLEngine.matrix_multiply(x, y, matrix_multiplication_key)- Returns the ciphertext resulting from the matrix multiplication of two 3d matrices. Consumes a level.
- Input:
- x: 3D array of double or complex double, GLPlaintext, or GLCiphertext
- y: 3D array of double or complex double, GLPlaintext, or GLCiphertext
- One of the inputs must be a ciphertext.
- MatrixMultiplicationKey
- Output:
- GLCiphertext
Examples
Matrix multiplication of two ciphertexts
import numpy as np
from desilofhe import GLEngine
engine = GLEngine()
shape = engine.shape
secret_key = engine.create_secret_key()
matrix_multiplication_key = engine.create_matrix_multiplication_key(secret_key)
message1 = np.ones(shape, dtype=np.float64)
ciphertext1 = engine.encrypt(message1, secret_key)
message2 = np.ones(shape, dtype=np.float64) * 2
ciphertext2 = engine.encrypt(message2, secret_key)
multiplied = engine.matrix_multiply(
ciphertext1, ciphertext2, matrix_multiplication_key
)
Multiplication of a ciphertext and a 3d matrix
import numpy as np
from desilofhe import GLEngine
engine = GLEngine()
shape = engine.shape
secret_key = engine.create_secret_key()
matrix_multiplication_key = engine.create_matrix_multiplication_key(secret_key)
message1 = np.ones(shape, dtype=np.float64)
ciphertext1 = engine.encrypt(message1, secret_key)
message2 = np.ones(shape, dtype=np.float64) * 2
ciphertext2 = engine.encrypt(message2, secret_key)
multiplied1 = engine.matrix_multiply(
ciphertext1, message2, matrix_multiplication_key
)
multiplied2 = engine.matrix_multiply(
message1, ciphertext2, matrix_multiplication_key
)
Multiplication of a ciphertext and a plaintext
import numpy as np
from desilofhe import GLEngine
engine = GLEngine()
shape = engine.shape
secret_key = engine.create_secret_key()
matrix_multiplication_key = engine.create_matrix_multiplication_key(secret_key)
message1 = np.ones(shape, dtype=np.float64)
plaintext1 = engine.encode(message1)
ciphertext1 = engine.encrypt(plaintext1, secret_key)
message2 = np.ones(shape, dtype=np.float64) * 2
plaintext2 = engine.encode(message2)
ciphertext2 = engine.encrypt(plaintext2, secret_key)
multiplied1 = engine.matrix_multiply(
ciphertext1, plaintext2, matrix_multiplication_key
)
multiplied2 = engine.matrix_multiply(
plaintext1, ciphertext2, matrix_multiplication_key
)