Skip to content
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

Alternative to np.concatenate given iterator of arrays, dtype, and final shape #93

Open
flexatone opened this issue Feb 16, 2023 · 0 comments

Comments

@flexatone
Copy link
Contributor

In all of SF's usage of np.concatenate, the following pattern is used

        array = np.empty((rows, columns), dtype=dtype)
        np.concatenate(blocks_norm, axis=1, out=array)
        array.flags.writeable = False

As np.concatenate does not support generators, and has additional overhead for more general cases, an optimized version might be implemented in ArrayKit.

NumPy's PyArray_AssignArray seems to be pretty close to what is needed:

https://github.com/numpy/numpy/blob/891ab8ee00755a539bd118b1bbe4e0a237a2d844/numpy/core/src/multiarray/array_assign_array.c#L295

But given that the destination is guaranteed to be a newly created, contiguous array, there might be a more efficient route.

We might be able to use this lower level interface directly:

https://github.com/numpy/numpy/blob/891ab8ee00755a539bd118b1bbe4e0a237a2d844/numpy/core/src/multiarray/array_assign_array.c#L80

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

No branches or pull requests

1 participant