You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Row and column shortcuts should be added for building views on 2-dimensional tensors. Typing row(e, 1) is more convenient and expressive than xt::view(e, 1, xt::all())
Here are the steps I would recommend if you are totally new to xtensor; if not, you can probably skip some of them:
read the Getting started section and start to play a bit with xtensor. If you're familiar with Numpy, the cheat sheet can be of great help
The quick ref about views will give you more insights about what views are and how they work.
row and column functions should be free functions in xview.hpp that simply call the view function with the right slices. You should start with row which is pretty straightforward, column would require a little more metaprogramming.
I assume this issue is still open and I like to contribute to it.
Just to clarify, what should happen if the row or col function is called on a tensor with more than 2 dimensions. I made a test with your starting point:
Typing row(e, 1) is more convenient and expressive than xt::view(e, 1, xt::all())
So the print of row0 and row1 seems to be right. Of course we could discuss what a row on a 3-dimensional tensor should be. But at least they access different values.
When I access the elements in the rows, something went wrong. I hadn't the time to check it in detail.
I like to use the TDD approach to get the function row and col and therefore I should know what the expected behavior of such code should be.
I checked the code and I see now why I have this behavior.
Obviously, xt::view(e, 1, xt::all()) will just return a xt::view to a tensor with one dimension less as the tensor has. Therefore, I have to use two indices for accessing the elements in the row of a tensor with 3 dimensions.
The question remains the same:
What should be the behavior of calling row or col on a tensor with more than 2 dimensions?
Should not be possible?
row is always first dimension, col is always second dimension?
row is always first dimension, col is always last dimension?
Indeed xt::view appends xt::all slices to its arguments list until it matches the number of dimensions of the underlying expression.
Regarding the behavior of row and col on a tensor with more than 2 dimensions, This has to be discussed, but I would be in favor of forbidding it for expressions with more than 2 dimensions.
Activity
[-]Add row and column[/-][+]Add row and column functions[/+]SylvainCorlay commentedon Oct 18, 2018
Well, since trailing
allscan be ommitted, row should be less necessary.JohanMabille commentedon Oct 18, 2018
I agree, that's for completness and also that would be weird to mix
viewandcolin the code instead of usingrowandcol.cha-ku commentedon May 17, 2019
Hi @JohanMabille , I'm here from https://twitter.com/JohanMabille/status/1052449785301614592
Would love to work on this. Any primers on how to get started on this?
JohanMabille commentedon May 17, 2019
Hi @cha-ku and welcome!
Here are the steps I would recommend if you are totally new to
xtensor; if not, you can probably skip some of them:rowandcolumnfunctions should be free functions inxview.hppthat simply call the view function with the right slices. You should start withrowwhich is pretty straightforward,columnwould require a little more metaprogramming.kolibri91 commentedon Dec 27, 2019
I assume this issue is still open and I like to contribute to it.
Just to clarify, what should happen if the
roworcolfunction is called on a tensor with more than 2 dimensions. I made a test with your starting point:and the behavior is quite weird:
So the print of
row0androw1seems to be right. Of course we could discuss what a row on a 3-dimensional tensor should be. But at least they access different values.When I access the elements in the rows, something went wrong. I hadn't the time to check it in detail.
I like to use the TDD approach to get the function
rowandcoland therefore I should know what the expected behavior of such code should be.kolibri91 commentedon Dec 27, 2019
I checked the code and I see now why I have this behavior.
Obviously,
xt::view(e, 1, xt::all())will just return axt::viewto a tensor with one dimension less as the tensor has. Therefore, I have to use two indices for accessing the elements in the row of a tensor with 3 dimensions.The question remains the same:
What should be the behavior of calling
roworcolon a tensor with more than 2 dimensions?rowis always first dimension,colis always second dimension?rowis always first dimension,colis always last dimension?JohanMabille commentedon Dec 28, 2019
Indeed
xt::viewappendsxt::allslices to its arguments list until it matches the number of dimensions of the underlying expression.Regarding the behavior of
rowandcolon a tensor with more than 2 dimensions, This has to be discussed, but I would be in favor of forbidding it for expressions with more than 2 dimensions.KappaDistributive commentedon Jul 4, 2020
It seems to me that this issue can be closed. Or am I missing something?
JohanMabille commentedon Jul 5, 2020
Indeed, good catch!