Is there a built in method to perform vector - matrix multiplication?

Hi all,

I was wondering if there is a built in function to carry out multiplication of an encrypted m dimensional vector with a plain m times n matrix in OpenFHE? If that is not the case, is there an algorithm I can implement myself?
I am using the CKKS scheme by the way, and a lot of implementations I found were about quadratic matrices, which is not what I need.

Thanks in advance!

Currently, there is no supported homomorphic matrix-vector multiplication in OpenFHE that is exposed to the end user. We are planning to release a library for homomorphic matrix arithmetic (including matrix-vector multiplication) in the near future.

If you want to implement this functionality yourself, check out this paper, in particular, Section 4.3 on “Matrix-Vector Multiplication”. For a visual illustration of this algorithm check out Figure 6 in this paper.

Related to this, an OpenFHE user released an implementation of vector-matrix multiplication in OpenFHE in this post which could be useful to you. Note that we did not use this implementation and it is not part of OpenFHE, use it at your own discretion.

1 Like

Thanks a lot, that was really helpful!

We are planning to release a library for homomorphic matrix arithmetic (including matrix-vector multiplication) in the near future.

Hello @Caesar are there any updates in this direction?

Hi @bazzilic,

Unfortunately, OpenFHE still does not support vector-matrix multiplication as an out-of-the-box API. However, you can achieve that by performing element-wise operations on vectors and matrices. OpenFHE includes functions for some common vector operations such as:

  1. EvalInnerProduct
  2. EvalSum
  3. EvalSumCols
  4. EvalSumRows

These can be helpful to implement your vector-matrix multiplication.
P.S. The code for the above functions can be found here.

1 Like

Hello @Caesar , I would like to know if there has been any further updates on the topic of matrix-vector multiplication in OpenFHE as of 2025. The method that you suggested in your last comment appears to not be the state-of-the-art. For example, looks like there are works https://eprint.iacr.org/2024/1730.pdf that provide further optimizations.

Given the importance of this operation for ML applications, I think it should be clarified what is the current best approach for matrix-vector multiplication using OpenFHE’s CKKS implementation, for example.

Thank you!

In general, there are several different methods. Which one is best really depends on the dimensions and the context of the problem. For instance, there are approaches based on cloning/replication and there also approaches based on linear transforms (with various baby-step-giant-step/hoisting optimizations) - both are used in practice. We will release soon open-numpy that will provide some of these methods using a simple-to-use python interface.

Thank you for your answer Yuriy, looking forward to the new release.

Could you provide some references regarding the methods you mentioned and maybe some criteria as per when one should be used over another, please?