Skip to content

Concatenate - #131

Merged
JohanMabille merged 5 commits into
xtensor-stack:masterfrom
wolfv:concatenate
Feb 12, 2017
Merged

JohanMabille merged 5 commits into
xtensor-stack:masterfrom
wolfv:concatenate

Conversation

@wolfv

@wolfv wolfv commented Feb 9, 2017

Copy link
Copy Markdown
Member

This adds the concatenate function. I have also left vstack and hstack, but vstack is a bit limited in functionality as it's currently not possible to vstack two 1D vectors.

In another PR I'll implement the stack functionality.

Happy about feedback for concatenate in it's current state!

@SylvainCorlay

SylvainCorlay commented Feb 9, 2017 •

Copy link
Copy Markdown
Member

I am not sure at all about adding hstack and vstack.

Even in numpy:

This function continues to be supported for backward compatibility, but you should prefer np.concatenate or np.stack.

@wolfv

wolfv commented Feb 9, 2017

Copy link
Copy Markdown
Member Author

okay, then let's scrap vstack and hstack.

I'll add the promote_shape mechanism tomorrow.

any other suggestions for concatenate? would making it variadic be useful?

otherwise i'll attempt to create stack in the same fashion.

@JohanMabille

Copy link
Copy Markdown
Member

I thing making it variadic is a good idea.

@SylvainCorlay

Copy link
Copy Markdown
Member

👍 it takes multiple arguments in numpy.

@wolfv

wolfv commented Feb 10, 2017

Copy link
Copy Markdown
Member Author

What I just pushed can concatenate over a tuple like this:

const xt::xarray<double> nn = {{4,3,2,1,2}, {1,2,3,4,5}};
xt::xarray cc = xt::concatenate(xtuple(nn, nn, nn));

for stack it doesn't work yet.

I am interested in feedback — do you think this is a good solution or should it be handled differently? I wasn't sure if adding variadic args to concatenate works, as the axis argument would be gone (if I am not mistaken).

Cheers!

@SylvainCorlay

SylvainCorlay commented Feb 10, 2017 •

Copy link
Copy Markdown
Member

Notes from in-person discussions:

  1. Issues with the variadic approach.

    • We could require the specification of the axis so that the last argument is always the axis. If we are homogeneous between stack and concatenate, this means that

      stack(3, 2, 1, 0) is [3, 2, 1] which is probably confusing...

    • Starting with the axis is a bit too different from numpy.

  2. Issues with the tuple approach.

    • users must write xtuple

@wolfv

wolfv commented Feb 10, 2017

Copy link
Copy Markdown
Member Author

In my opinion, it's not too hard to write xtuple (or something along those lines) and the interface would be nice and homogenous.

And then we wait for named arguments in C++ ;)

@wolfv

wolfv commented Feb 10, 2017

Copy link
Copy Markdown
Member Author

Btw. was there a third point coming up?

Would you keep the recursive approach for concatenate, or use a tuple-approach with apply as in stack?

@JohanMabille

JohanMabille commented Feb 10, 2017 •

Copy link
Copy Markdown
Member

We agree with the xtuple approach, it was just a discussion on whether we could avoid it and if it would be a good thing. It appears that even if we can, the solution will be inelegant and incompatible with a clean solution for the stack function, and it's always good to keep track of such discussions to avoid reproducing them in the future (you know, like the never ending wrong good ideas :))

@JohanMabille

Copy link
Copy Markdown
Member

I think a non recursive approach would be better since it would avoid many potential heap allocations.

@wolfv

wolfv commented Feb 10, 2017

Copy link
Copy Markdown
Member Author

Ok! Since I've found out about apply, I think I can do it :)

@wolfv

wolfv commented Feb 10, 2017

Copy link
Copy Markdown
Member Author

I'll add some working tests tomorrow.

@wolfv

wolfv commented Feb 11, 2017

Copy link
Copy Markdown
Member Author

From my side this is fairly complete.
One thing that could be done is shape checking for concatenate and stack.

For stack, all shapes have to be the same.
For concatenate all shapes have to be the same along the concatenation axis.

We could also use the check_policy approach. Let me know.

@wolfv

wolfv commented Feb 11, 2017

Copy link
Copy Markdown
Member Author

Also note the fix for operator== which didn't work if the shape_types where not equal.

@JohanMabille

JohanMabille commented Feb 11, 2017 •

Copy link
Copy Markdown
Member

Ok, that looks good at first sight, I'll go into details later however I think we can defer the implementation of the shape checking. This way we can merge quickly your PR and make a v0.4.2. This will help improving xtensor-python which is getting more and more attention.

@SylvainCorlay

SylvainCorlay commented Feb 11, 2017 •

Copy link
Copy Markdown
Member

Btw. was there a third point coming up?

I don't remember 😕 - must have been very important :)

@JohanMabille
JohanMabille merged commit 8f75fe4 into xtensor-stack:master Feb 12, 2017
@SylvainCorlay

Copy link
Copy Markdown
Member

Oh yeah I remember the third point:

@SylvainCorlay

Copy link
Copy Markdown
Member

So xtuple is a sort of forward_as_tuple, but for closure types. I was wondering if this could be a source of inspiration on how to name closure types etc...

@wolfv

wolfv commented Feb 12, 2017

Copy link
Copy Markdown
Member Author

I was wondering if it makes sense to have xtuple and xctuple or something along those lines for closures vs. const closures ...

happy that it's been merged! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants