Using TMatrix in PyROOT

Hi

I’ve been trying to use TMatrix in python code but it is crashing… Here is a dummy example: i try to allocate an element with (i,j) it told me to use [i,j] and if i do so

########################
## Welcome to Python !##
########################

>>> from ROOT import TMatrix
>>> dim=4; aij=TMatrix(dim,dim); aij.Print()

4x4 matrix is as follows

     |      0    |      1    |      2    |      3    |
---------------------------------------------------------
   0 |          0           0           0           0 
   1 |          0           0           0           0 
   2 |          0           0           0           0 
   3 |          0           0           0           0 

>>> aij(0,2)=4
Are you trying to assign a value to a reference return, for example to the
result of a call to "double& SMatrix<>::operator()(int,int)"? If so, then
please use operator[] instead, as in e.g. "mymatrix[i,j] = somevalue".
  File "<stdin>", line 1
SyntaxError: can't assign to function call
>>> aij[0,2]=4

 *** Break *** segmentation violation
 Generating stack trace...
 0x00007f971c2325bc in PyROOT::TMethodHolder<PyROOT::TScopeAdapter, PyROOT::TMemberAdapter>::Execute(void*) + 0x7c from /usr/root/lib/libPyROOT.so
 0x00007f971c230f9b in PyROOT::TMethodHolder<PyROOT::TScopeAdapter, PyROOT::TMemberAdapter>::operator()(PyROOT::ObjectProxy*, _object*, _object*, long) + 0x12b from /usr/root/lib/libPyROOT.so
 0x00007f971c235706 in <unknown> from /usr/root/lib/libPyROOT.so
 0x000000000041d42a in PyObject_Call + 0x3a from python
 0x0000000000482773 in <unknown> from python
 0x0000000000482e82 in <unknown> from python
 0x00000000004ba569 in PyEval_EvalFrameEx + 0x12d9 from python
 0x00000000004bfccd in PyEval_EvalCodeEx + 0x13d from python
 0x00000000004c07a2 in PyEval_EvalCode + 0x32 from python
 0x00000000004dfa02 in <unknown> from python
 0x00000000004e1415 in PyRun_InteractiveOneFlags + 0x155 from python
 0x00000000004e15c8 in PyRun_InteractiveLoopFlags + 0xa8 from python
 0x00000000004e186f in PyRun_AnyFileExFlags + 0x4f from python
 0x00000000004f10ed in Py_Main + 0x4fd from python
 0x00007f971cc95ead in __libc_start_main + 0xfd from /lib/x86_64-linux-gnu/libc.so.6
 0x000000000041f269 in <unknown> from python
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: problem in C++; program state has been reset

any idea ?

thanks
jb

hi again

I tried to use TVectorD and it worked well, so i’ve tried another way of allocating an element that has worked as shown here

########################
## Welcome to Python !##
########################

>>> from ROOT import TMatrix
>>> dim=4; aij=TMatrix(dim,dim); aij.Print()

4x4 matrix is as follows

     |      0    |      1    |      2    |      3    |
---------------------------------------------------------
   0 |          0           0           0           0 
   1 |          0           0           0           0 
   2 |          0           0           0           0 
   3 |          0           0           0           0 

>>> aij[0][2]=4; aij.Print()

4x4 matrix is as follows

     |      0    |      1    |      2    |      3    |
---------------------------------------------------------
   0 |          0           0           4           0 
   1 |          0           0           0           0 
   2 |          0           0           0           0 
   3 |          0           0           0           0 

Maybe the sentence

should then be changed ?

Thanks anyway
jb

Hi,

thanks! I fixed the error message.

Cheers,
Wim