-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extensions facilitating flexible usage #984
Comments
Just quick answers:
Thanks for all your feedback so far! Looking forward to be working with you. |
I forgot one point: ConstructorWhat confuses me a lot is the constructor. I get that it is really great and what NumPy does. But still... What is allowed is std::vector<size_t> shape = { 3, 2, 4 };
xt::xarray<double> a(shape); Now since xt::xarray<double> a({ 3, 2, 4 }); But that is really not the same thing! It confuses me as I would think that the xt::xarray<double> a = { 3, 2, 4 }; This could be dealt with in the documentation. Still, being able to allocate in only one line would help. But I guess this is: xt::xarray<double> a = xt::empty<double>({ 3, 2, 4 }); This is one of the first things a user deals with, it would be great to have on the cheat sheet. Personally I would have used the following syntax // allocate an 'empty' array of shape [3,2,4]
xt::xarray<double> a({ 3, 2, 4 });
// initialize a 'list' [3.0, 2.0, 4.0]
xt::xarray<double> a = xt::array({ 3, 2, 4 });
// or of course
xt::xarray<double> a = {3, 2., 4.}; which, in my opinion, would be equally close the NumPy's syntax. |
Great to hear your feedback so far. To answer the only part that needs answering:
|
I've started continuing the work from #867
The PR needs a bit more love though (it will totally fail all tests right now), just wanted to give you a quick update. |
I am planning to stop the development of multi-dimensional arrays in my own library cppmat and transfer to
xtensor
. (I am continuing the vector/tensor functionality, but now as an extension toxtensor
: this could partly solve issue #561)As an 'advanced’ user who has had to develop his own class I do have ideas that xtensor would benefit from. We could iterate here on these ideas, and potentially merge some of the features cppmat into xtensor.
Negative (periodic) indices
I have enabled negative indices in cppmat, in fact even periodic indexing, which is really nice in the quick-development phase. The way to (potentially) do this is to:
where
n
should in this case beshape[0]
.As I understand that this is a 'costly' operation that could be avoided I have overloaded
operator()
forint
s, where it does the conversion, and forsize_t
for ordinary use where you avoid the conversion. See cppmat, lines 514-822.Negative axes references
In addition to the previous point it would be nice to be able to for example do
to average over the last axis. This should be simple, and (almost) never mess with efficiency. But it does make the end code more readable: it focusses on the details that are important in that context. Also, it allows to easily make end code flexible.
Quick shape access
A common operation is this:
while it would be simpler to do:
This can be achieved with a simple overload of the
shape
function:See cppmat, lines 351-393. Here you can see that I have two more overloads:
(1) For
int
axis, allowinga.shape(-1)
. (See previous point.)(2) A templated overload, which is quite nice. It allows:
Which is again quite useful if one works with periodicity.
One could take this even further and have an overload:
Overloading based on rank/size
It is often quite handy and efficient to have overloads based on rank. For example, for a tensor contraction:
More cleaver overloads (allowing for example partially unrolling of loops) could also be based on fixed size or not.
Missing functions
What I missed at first sight is:
xt::average(...)
: to do weighted average, see numpy.average and cppmat, lines 3044-3081: here you see that it can simply usesum
.xt::argsort(...)
: to return the indices that would sort the array, see numpy.argsort.size_t a.rank()
: get the rank of the array.Sparse matrices
This is something that is often needed in scientific computing. This is often paired with the need to either diagonalise a matrix or solve a linear system. In my opinion, this would really close the circle.
One could provide interfaces to existing libraries here, potentially with extension modules that library writes or users could provide.
Symmetric and diagonal matrices
In cppmat I have symmetric and diagonal square matrices. This offers great speed-ups in tensor algebra, as you feed the program with quite some knowledge. But at the same time, the library maintenance burden becomes much more significant.
Single include
It would be much easier to
to get most of the functionality.
Documentation
Although there is already quite a bit of documentation there are a couple of things that could be improved:
A quick-start guide with small full-working examples complete with explicit compiler instruction and
CMakeLists.txt
files. This will get a potential user of the first bump, and increases significantly the chance of him/her staying committed.A cheat sheet. From numpy to xtensor is really great! But somehow it took me a long time to find. But in addition a small cheat sheet just for C++ a-la Eigen would help you get an overview. This is currently still quite a challenge.
One of the most frequent things you do is allocate an array. Currently this is not very broadly documented. It would help to have some description to do
zeros
,empty
, ... and how to get those things for fixed sized arrays. (Could go on the cheat sheet.)At a quick glance I don't understand casting between fixed size, fixed rank, and dynamic arrays. (Could go on the cheat sheet.)
Currently some of the examples on the site don't work. In fact even the very first doesn't compile after downloading xtensor from conda.
Side remarks / wishes
For those cases that efficiency is not important and you don't want to think too much a
bool array<T>::inBounds(i,j,...)
function could be nice, that allows you to try if an index is out-of-bounds.I would by default allocate shape, strides, ... on the stack by hard-coding a maximum number of dimensions (6-10 or so). This would avoid naive users to by default use the least efficient array.
The text was updated successfully, but these errors were encountered: