TMatrix left-handside multiplication


I am playing with complex matrices and vectors and I couldn’t find that much documentation about matrices-vector operations. I would like to make the operation: B = (V*)A(V), where A,B are TMatrix type and V is TVectorT vector.

I first define TMatrix/TVector conjugate as following

TVectorC Conjugate(const TVectorC &v)
    TVectorC v_c(v.GetNoElements());

    for(int i = 0, N = v.GetNoElements(); i < N; i++) {
        v_c(i) = TComplex::Conjugate(v(i));

    return v_c;

TMatrixC Conjugate(const TMatrixC &m)
    TMatrixC m_c(m.GetNrows(), m.GetNcols());

    for(int i = 0, I = m.GetNrows(); i < I; i++) {
        for(int j = 0, J = m.GetNcols(); j < J; j++) {

            m_c(i,j) = TComplex::Conjugate(m(i,j));

    return m_c;

And then after that I was hoping to make the simple operation:

      using TMatrixC = TMatrixT<TComplex>;
      using TVectorC = TVectorT<TComplex>;
      TMatrixC A = /*[...]*/;
      TVectorC V = /*[...]*/;

      TMatrixC B = Conjugate(V)*A*V;

This throw me an error because of the left handside multiplication.

error: invalid operands to binary expression ('TVectorC' (aka 'TVectorT<TComplex>') and 'TMatrixC' (aka 'TMatrixT<TComplex>'))
    return TMath::Sqrt(Conjugate(this->Z) * this->P * this->Z);
                       ~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~

This seems obvious… How should I modify my code here ?

This is not what I want to do, because my vectors are differents.
But for the records… this might be useful for someone else. Naming doesn’t sound obvious.

Element 	Similarity (const TVectorT< Element > &v) const
 	Calculate scalar v * (*this) * v^T.

NB: It seems complex algebra might not be supported yet. Fail to compile TMatrixT<TComplex> @moneta Were there some progress in this regards ?


We are not supporting TMatrix or TMatruxstd::complex. You probably need to use another matrix package for performing operations on complex matrices


Any plan for implementing that ? Or some arguments against it maybe ?

If you search for “matrix complex” you will see that there has been some interest for complex matrix algebra over the last 2 decades, but … implementing this feature in all elements of the linear package is a big task:

installing it

  • in all the decomposition classes
  • in the eigen value classes
  • sparse methods
  • ROOT dictionary etc.
1 Like

your algebra syntax is not correct ! An expression is always interpreted from left to right unless parentheses are placed. V * A * V will result first in calculating V * A.

We could have implemented to interpret this as V^T * A . Just to keep the syntax
clean and simple that is left out and the preferred way is, V * (A * V) which
will result in a dot product of two vectors.

As far as the naming of “Similarity” goes. The code contains also the well-known matrix similarity operations and this one is with a vector.

Pretty sure it doesn’t takes two decades to implement complex matrices… but I definitely need a robust/mature solution.

I definitely didn’t found any vector transpose function, so I assumed that multiplying a vector-matrix from the left was implicit. Additionally, I only know matrix similarities not vector-matrix.
Many thanks for the clarifications !

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.