Skip to content

implement block to stack arrays along multiple dimensions at once #455

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

Open
gdementen opened this issue Oct 2, 2017 · 2 comments
Open

Comments

@gdementen
Copy link
Contributor

gdementen commented Oct 2, 2017

The goal is to produce more easily arrays like this:

11122
11122
33344

I don't know what would be the best syntax for this. Generalize stack, concat, from_lists?

Assuming blocking along existing axes (ie "generalized concat"):

>>> arr1 = ndtest("a=a0,a1;b=b0..b2")
>>> arr2 = ndtest("a=a0,a1;b=b3,b4")
>>> arr3 = ndtest("a=a2;b=b0..b2")
>>> arr4 = ndtest("a=a2;b=b3,b4")
>>> block([[arr1, arr2],
...        [arr3, arr4]], axes=('a', 'b'))
a\b  b0  b1  b2  b3  b4
 a0   0   1   2   0   1
 a1   3   4   5   2   3
 a2   0   1   2   0   1
>>> # FWIW, in my concat branch, this is equivalent to :
>>> concat([concat([arr1, arr2], 'b'), 
...         concat([arr3, arr4], 'b')], 'a')

See
https://docs.scipy.org/doc/numpy/reference/generated/numpy.block.html#numpy.block

Notes:

  • I do not want to do any effort to support:

    AAAbb
    AAAbb
    cDDDD
    

    like np.block does, but if it comes naturally from the implementation (which is likely and I guess is
    probably the case for np.block), I do not think it is worth it to add an explicit check to disallow it.

  • I don't see any real value of providing both concat and block in the API, as concat could simply be a special case for block or vice-versa. There are edge cases with non-LArray types where it would not be equal, but I do not think they would justify having two functions instead of one.

  • It would be nifty if we could write:

    >>> block([[arr1, 0],
    ...        [0, arr4]], axes=('a', 'b'))
    a\b  b0  b1  b2  b3  b4
     a0   0   1   2   0   0
     a1   3   4   5   0   0
     a2   0   0   0   0   1

    But that would be a bit tricky to implement (even if theoretically possible).

@alixdamman alixdamman added this to the 0.29 milestone Jan 25, 2018
@alixdamman alixdamman modified the milestones: 0.29, 0.30 Mar 16, 2018
@gdementen gdementen self-assigned this Nov 26, 2018
@gdementen gdementen modified the milestones: 0.30, 0.31 Jan 29, 2019
@gdementen
Copy link
Contributor Author

I have a working generalized concat in one of my branches. It needs a bit of cleanup but the hardest question to answer is now about the API we want to offer: block, concat, or merge this into stack (ie, if the "stacking axes" already exist, do a concat, otherwise stack/create the axes)

@gdementen
Copy link
Contributor Author

gdementen commented Jul 17, 2019

In the discussion in #90, it seems like I was leaning for merging the two methods.

@gdementen gdementen removed this from the 0.31 milestone Aug 1, 2019
@alixdamman alixdamman added this to the 0.32 milestone Aug 13, 2019
@gdementen gdementen removed this from the 0.32 milestone Sep 24, 2019
@gdementen gdementen added this to the 0.35 milestone Sep 29, 2022
@gdementen gdementen modified the milestones: 0.35, 0.36 Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants