# What happened to TMatrixTRow?

**URL:** <https://root-forum.cern.ch/t/what-happened-to-tmatrixtrow/43726>\
**Category:** ROOT\
**Tags:** math\
**Created:** [February 26, 2021, 10:44pm UTC](https://root-forum.cern.ch/t/what-happened-to-tmatrixtrow/43726 "2021-02-26T22:44:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eddy\_Offermann](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eddy_offermann/32/25079_2.png) [@Eddy\_Offermann](https://root-forum.cern.ch/u/Eddy_Offermann)\
**Post date:** [February 26, 2021, 10:44pm UTC](https://root-forum.cern.ch/t/what-happened-to-tmatrixtrow/43726/1 "2021-02-26T22:44:02Z")

</div>

execution of the script

```auto
{
   double am[] = {0.0,1.0,2.0,3.0};
   TMatrixD m; m.Use(2,2,am);
   auto colval = 4.;
   auto rowval = 5.;
   TMatrixDColumn(m,1) = colval;
   TMatrixDRow(m,1) = rowval;
   m.Print();
}

```

results in

```auto
**row.C:8:21:**  **error:**  **no viable overloaded '='**

TMatrixDRow(m,1) = rowval;
** ~~~~~~~~~~~~~~~~^~~ **

```

This is because since 6.10 the operator= has been removed from TMatrixTRow but  
not from TMatrixTColumn (for backward compatibility 😀) .

The implementation is now through a std::initializer\_list, so one must use in order to  
replicate the old behavior:

```auto
TMatrixDRow(m,1) = {rowval,rowval};

```

(and yes can also do

```auto
TMatrixDRow(m,1) = {rowval,rowval,rowval};

```

because the size is not checked)

This hack raises many issues/questions:

1. What is the purpose of TMatrixTRow now, because the operator= does  
not change the whole row. It has now the flavor of  
TMatrixT::&operator()(Int\_t rown,Int\_t coln);
2. This change broke m[irow][icol], it will give a compilation error, m(irow,icol) still works.
3. This implementation is now in contradiction with operator+= and operator\*=  
because there only one value is given which operates on the whole row.
4. Last and probably shows the lack of C++ knowledge by this practitioner, how will I fill this initializer\_list with a vector because the size of the matrix will fluctuate in my code.

-Eddy

\_ROOT Version: 6.22  
_Platform:_ Not Provided  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [February 27, 2021, 11:33am UTC](https://root-forum.cern.ch/t/what-happened-to-tmatrixtrow/43726/2 "2021-02-27T11:33:10Z")

</div>

Hi Eddy! I’m sure @moneta will take care of this.

Cheers, Bertrand.

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [March 2, 2021, 1:44pm UTC](https://root-forum.cern.ch/t/what-happened-to-tmatrixtrow/43726/3 "2021-03-02T13:44:58Z")

</div>

Hi Eddy,  
If I remember well the reason for removing it was that the operator= was dangerous, because, was allowing to do something like:

```auto
TMatrixD m(2,2); 
m[0,1] = 2

```

And this changes the all row instead of a single element, as a native user my expect. This in my opinion is very confusing.  
The changed happen in [this commit](https://github.com/root-project/root/commit/a941b9957e3146a19b02b93b2190fa9f18c52460#diff-908e6804dc63c3c7a6950318e05c6bdb1df1ae726626aaf884eb618de095bca4).  
The removel was done for both TMatrixTRow and TMatrixTColumn.  
Concerning your points:

1. If you want to change a whole matrix row there is now TMatrixTRow::Assign. Do

```auto
TMatrixDRow(m,1).Assign(rowval); 

```

1. m[irow][icol] should still work
2. Yes , this is true, but I think it is not a contradiction, but some missing consistency, but it is in my opinion acceptable if we document it
3. ?? (not clear your point to me). For the other point about initializing with a different size, you are right, we should check that the size of the iniitializer list matches the matrix row size.

Best

Lorenzo

---

<div class="post-metadata">

**Author:** ![Eddy\_Offermann](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eddy_offermann/32/25079_2.png) [@Eddy\_Offermann](https://root-forum.cern.ch/u/Eddy_Offermann)\
**Post date:** [March 2, 2021, 10:50pm UTC](https://root-forum.cern.ch/t/what-happened-to-tmatrixtrow/43726/4 "2021-03-02T22:50:08Z")

</div>

Hi Lorenzo,  
Still getting some skiing done despite the Covid pandemic 😀 ?

Currently there are two documented ways to access the elements of matrix m at row i and column j:  
`m(i,j) = 2;` and  
`m[i][j] = 2`

There is a nice discussion of the implementation of `operator()` versus `operator[]` [here](https://isocpp.org/wiki/faq/operator-overloading#matrix-subscript-op) where the last one is referred to as array-of-array solution.

Now apparently somebody became adventurous and confused by the fact that `m[1,2]=2`  
sets the complete row 2 to the value instead of just the element at row=1,  
column=2 . Let’s confuse this person a bit more 😜

`m[1][1,2]=2` or `m((2,1),2)=2`

all the same and just the [comma-operator](https://en.wikipedia.org/wiki/Comma_operator) doing its job,  
`m[1,2]=2` is the same as `m[2]=2`.

Maybe confusion sets easier in with the `operator[]` than with `operator()` because of its implementation (currently the `operator[]` only allows one argument).

The better way to ends this confusion is introducing statements like:

`inline Element &operator[](Int_t rown) = delete;`  
` inline Element operator[](Int_t rown) const = delete;`

Thereby keeping the `TMatrixTRow` interface like all the other Matrix classes.

-Eddy

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [March 16, 2021, 10:50pm UTC](https://root-forum.cern.ch/t/what-happened-to-tmatrixtrow/43726/5 "2021-03-16T22:50:26Z")

</div>

Closed on March 16, 2021, 10:50pm UTC

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