Hello, I am getting an error when trying to fill a TMatrixDSym in a .Define() in RDataFrames in PyRoot. The error is just the following two lines over and over:
Error in <operator=>: matrices not compatible
Error in <TMatrixTRow_const(const TMatrixTSym &,Int_t)>: row index out of bounds
However, the program finishes running after the errors print.
Here is a reproducer for the error:
I defined mystring separately so that it’s syntax is more clear because I think that is probably where the problem is. I can’t find anything that would cause an index to be out of bounds, though. Does anyone have any ideas?
Hi @bthornbe ,
ah this is tricky, here’s what I think is happening.
When you do return s, RDF tries to assign s to a variable that stores the result of your computation for that entry. Initially, that variable will be a default-constructed TMatrixDSym.
Unfortunately, however, it is not possible to assign a TMatrixDSym with a certain shape to a TMatrixDSym with another shape!
So basically this happens:
~ root -l
root [0] TMatrixDSym rdf_var; // this is the internal RDF variable, default-constructed
root [1] TMatrixDSym s(3, 4); // this is your `s`
root [2] rdf_var = s // does not work!
Error in <operator=>: matrices not compatible
So you can’t just return s. Maybe @moneta can suggest what to use instead.
It’s what you get if you call TMatrixDSym m; – it constructs an empty matrix (zero rows and zero columns). The problem is that assigning another non-empty TMatrixDSym to an empty matrix is an error, so I am not sure TMatrixDSym can be used as the result of a Define.
eguiraud was right about the cause of the problem, and I’m going to post my workaround in case anyone else finds this thread while searching for a solution to a similar problem. The reason I wanted SphericityTensor in the form of a TMatrixDSym was that I wanted to use TMatrixDSymEigen to find its eigenvalues. For that reason, the reproducer below has different output in order to show how the workaround works.
Instead of returning a TMatrixDSym in the definition of SphericityTensor, I am returning a 2-d c++ vector, and then I make a TMatrixDSym out of that vector within the definition of EigenVals. TVectorD appears to have the same type of issue with the default constructor, so I also have a loop in that definition that takes the output of TMatrixDSymEigen.GetEigenValues() from a TVectorD and puts it in a c++ vector.
Hi,
Given the fact you can early build a TMatrix or a TVector from a simple C array or std::vector, I would use them to return your data values, and then build the TMatric,TVector from those