I am wondering if it is possible to do general NxN matrix mutltiplication in either Concrete-Numpy or Concrete-ML .

I have seen the documentation of concrete-numpy, and it was clear from the documentation that concrete-numpy that it only apparently supports matrix multiplication of 2x2 matrices and atmost one has to be encrypted. On the other hand, it seems from Quantization of Neural Networks for Fully Homomorphic Encryption that Concrete-ML might support some large matrix multiplication for at least integer based matrices.

To be very clear, I need very elementary matrix multiplication of say about matrices less than 50x50 in dimension.

Concrete is an excellent tool and attending Benoitâ€™s talk at PPML '22 in Copenhagen last week was a very educating experience.

I am going to answer for CN team since they are in vacation.

Yes, M * N matrix multiplication is supported in Concrete-Numpy (and linear layers are supported in Concrete-ML). Just use np.matmul. When we say â€śOnly 2D matrix multiplication is supported for nowâ€ť, 2D means â€śtwo dimensionsâ€ť, ie M * N, by opposition to larger cases like M * N * Nâ€™ (numpy.matmul â€” NumPy v1.23 Manual).

(And thanks for the words about the PPML presentation, quotes like that make us very proud)

Thank you for your response. Indeed, I was confused by the equivocation of the word dimension.

Also one more question in this context, I wish to square an encrypted matrix but since we necessarily compelled to have one matrix in the product as unencrypted, I cannot see how may I do that.

So, if you really mean squaring M, ie compute M * M, it is not possible currently, and I guess it will not be possible for some time, since it implies multiplying cipher texts together, which is not available in below Concrete library at the moment. On the opposite, if you mean applying the square function on all the elements of the matrix, it is doable with a PBS (but I imagine youâ€™re speaking about M * M).

It will be sufficient to know that for my application, I do need to be able to compute powers of a matrix, and any arbitrary although they will be always less than N-1, N is are the dimensions of the square matrix N x N.

I am myself thinking about some mathematical tricks by which I can compute A^2 , but have not reached anywhere as of yet.

In the next release this summer, you will be able to do M ** 2.

For the time being, you can manually create a LookupTable like this one table = hnp.LookupTable([i ** 2 for i in range(max_expected_value_of_m)]) and use it like so table[M].

I have an encrypted tensor `x` of shape (M, M) and an encrypted tensor `y` of shape (M, M), can I do element-wise multiplication of `x` and `y` (i.e., `x * y` in numpy)?

Then, the answer is you cannot for the time being.
Umut

Thank you for your exhaustive response, and apologies for my belated reaction. It is indeed true that I meant np.matmul(x, y)). I am also not sure what you mean by M **2. Is this suppose to mean squaring the entries in the matrix in place?

It therefore seems that that matrix multiplication , which is the linear algebraic matrix multiplication, in a homomorphic fashion, is not very much supported in Zama. It is understandable as perhaps concrete-numpy is in its initial stages and has already made a large way to incorporate functions which might be rather more useful for ML algorithms, though many ML algorithms also require matrix mutliplication.

Thank you for your time and response, I will seek your help if there is anything else that I would need.

Yes, it was for squaring the entries in the matrix, I thought thatâ€™s what you wanted to do when I saw M * M.

The main blocker for encrypted matrix multiplication is the multiplication of two encrypted scalars. Weâ€™re working on bringing support for it but I cannot provide an estimate on when itâ€™ll be available.

Youâ€™re welcome, donâ€™t hesitate to ask anything