C++ based NumPy N-Dimesional patch extraction.
Project description
npy-cpp-patches
Read N-Dimensional patches from .npy
files. This module is built using C++
and has Python3
bindings.
Data Specifications
- Arrays must be saved in
C-contiguous
format, i.e. NOTFortran-contiguous
. - First dimension is indexed using in a non-contiguous manner. For example, this can be used to extract specific channels within a natural image.
- Next dimensions are specified by a patch shape
C++
vector orPython
tuple. To extract patches of lower dimensionality than that of the data, set the corresponding dimensions to1
.
Python Usage
Install
pip install npy-patcher
Usage
from npy_patcher import PatcherDouble, PatcherFloat, PatcherInt, PatcherLong
# In this example lets say our data has shape (10, 90, 90), and is therefore 3D.
data_fpath = '/my/numpy/file.npy'
patcher = PatcherFloat() # Use PatcherFloat for np.float32 datatype
nc_index = [0, 1, 3, 5, 7] # Non-contiguous index
patch_shape = (30, 30) # Contiguous patch shape.
patch_num = 2
# The patch number indexes the patches (starting from 0). So in our example the index 2 would be equivalent to data[nc_index, 0:30, 60:90]. The variable indexes the patches in C-contiguous manner, i.e. the last dimension has the smallest stride.
patch = patcher.get_patch(data_fpath, nc_index, patch_shape, patch_num)
patch = patch.reshape((5, 30, 30)) # PatcherFloat returns a list, therefore we need to reshape.
C++ Usage
Below is an example written in C++
, equivalent to the Python
usage above.
// test.cpp
#include "src/patcher.hpp"
#include <vector>
#include <string>
int main() {
std::string fpath = "data.npy";
std::vector<size_t> nc_index {0, 1, 3, 5, 7};
std::vector<size_t> patch_shape {30, 30};
size_t patch_num = 2;
Patcher<float> patcher;
// Here the patch object is a contiguous 1D vector
std::vector<float> patch = patcher.get_patch(fpath, nc_index, patch_shape, patch_num);
return 0;
}
You can then build the package, for example using g++
:
$ cd npy-cpp-patches/
$ g++ -std=c++17 -I ./ -g test.cpp src/npy_header.cpp src/pyparse.cpp -o test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
npy-patcher-1.0.4.tar.gz
(7.0 kB
view hashes)
Built Distributions
Close
Hashes for npy_patcher-1.0.4-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 036fe1442206e38e785dda33db867857e03fe2cabb57fc9a82b8463a820b801f |
|
MD5 | eae068bad4583967fa4e4781b975e579 |
|
BLAKE2b-256 | 873bd74df3f01f311ad9e739588af2fababfa13db47bc4a9d7808918c429428f |
Close
Hashes for npy_patcher-1.0.4-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2c6f23bde94d3c64f24ad1cca8bb23d0d96ccf639d12934e315ba0cf6847bbf |
|
MD5 | fe165bbeb06ee24d993b4ef328b64bc3 |
|
BLAKE2b-256 | bfad83e39a03fc77ad30b746a69fa008637da6fc7f9ec7929b9e5b6186d0d9ee |
Close
Hashes for npy_patcher-1.0.4-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b62d606c8d8208601a0f92c3030f6fcd2e3c422822cc601c61cf12f16ad6585 |
|
MD5 | 3c2759f9a9630d1b6cd8d53758de94f9 |
|
BLAKE2b-256 | 5604f9400e795cb82a40d1e915bac83ae0755d8cdad432c71a8cbb0448ba87e6 |
Close
Hashes for npy_patcher-1.0.4-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cea3ec7015a926b29ee6f21f624e08b817359b2da9f2eee4aa92414b5d9bd42d |
|
MD5 | 322242b2aa14e8ebd3d43b4f38b05774 |
|
BLAKE2b-256 | 113d7f2252d6ece44ad0cbf39c2dc74e79c54ff15a537de80bd555eae0bed10b |
Close
Hashes for npy_patcher-1.0.4-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb8e348ef16f2ed2613f27d09ef66453bdbb9272ece522a8d1130104bbc167ec |
|
MD5 | 72f4dd33b10df5dc9bbc7b36623735df |
|
BLAKE2b-256 | 7c5db896216dc695d1d11289b9f42c2de10773d04bcc18095ac3bf7dd34bd7e2 |
Close
Hashes for npy_patcher-1.0.4-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64c5188e269c83b48f2f0b90d93941511d91f6e20320acec4fb2a373050cb370 |
|
MD5 | 29916c1a1783028947ce2ef029dc4c67 |
|
BLAKE2b-256 | 60449b36829d397a60aa52e88170d0b02512dda44f5269b471d2325a690e7188 |
Close
Hashes for npy_patcher-1.0.4-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | edee6590c2ce2b475fec34b0e456c156b23c2dece7d9029211b7c5c3ceebf04a |
|
MD5 | 90f51811b1e370103e1d6affbf21b0ad |
|
BLAKE2b-256 | f23b25004f8f3eb8c232f9ad5b5dfec59389253216c629d1079e11a9787be01e |
Close
Hashes for npy_patcher-1.0.4-cp310-cp310-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5003996bac1d80ccf485825933d8ec5c18e1a49adf9267010ffb7c53daff9699 |
|
MD5 | 486efbf4d14642a7be0d4bf867f17c4d |
|
BLAKE2b-256 | c9b3e485c81604d9a2b093f6a9fadd9bda8d4a93b356d161bffb7ecc96df3e63 |
Close
Hashes for npy_patcher-1.0.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a091c03699eb03e07edc952ce75c1847bde532a37876306ef559937c73b4cf6 |
|
MD5 | 370e36d2471387f4a818eb118ab7d882 |
|
BLAKE2b-256 | 4dd7d65da9754a9ba354b9235144b1edc45d2fb8bf55f8ed19d725c85bb46d3e |
Close
Hashes for npy_patcher-1.0.4-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47428f4bd9b34e6a0d03ae5c6c73a42593e8680d80c6ef73da979123aecfb30a |
|
MD5 | bdb828944c46991ef6db4d18aedc74c7 |
|
BLAKE2b-256 | 0e4452332f58762278f1f30c4a95215101e61987583ce15a7e04bb4126aefdf8 |
Close
Hashes for npy_patcher-1.0.4-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bd7aa52f23427aa6b2db8751b0b795ba187bc06b9d29817a25cafda7d5a1ee5 |
|
MD5 | f60bd885a19c2180c6c8a8128f9f6d87 |
|
BLAKE2b-256 | 2fe89e9f4771997cfcf4f725f5b4a2813465f8ae41bbfbccdea805b455d09744 |
Close
Hashes for npy_patcher-1.0.4-cp39-cp39-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65d359231cd1003c6c1032f18b5b57963823da35475fde03494fd3b20cb7a4b1 |
|
MD5 | da172bb7dc501669159f9cd8c9f19a7b |
|
BLAKE2b-256 | 9bcb3646566507c42d1eedb4f75e61b548612b75f535b2f56b71fc5ce3264285 |
Close
Hashes for npy_patcher-1.0.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf80f4585a0205cb6c1168444c72ee3636215cd23f03a09c2cf34ff64bef4a23 |
|
MD5 | 151300c0cb97b6b40c854e44109a5246 |
|
BLAKE2b-256 | eca6b5815b147ece3f3d0c952513d6c4311edf17c126d1ec761645d84443297b |
Close
Hashes for npy_patcher-1.0.4-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e07c1e18ddfbcebc833c49328451fa2700ad7376f00f17c9a77b595143d47a64 |
|
MD5 | 3b053d715472a7050408afe64b1920ac |
|
BLAKE2b-256 | 10752c70aaf170a13266f9536cb59e83a8a9221cb291a0f103455a5c1db6f0e1 |
Close
Hashes for npy_patcher-1.0.4-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5a6b7dd87eb39423322262e6ce37f84d1117ce2efe2e42c8b3ffbe7935ad2c9 |
|
MD5 | 3562eaa180bfc7364e59a8bb39aa4891 |
|
BLAKE2b-256 | f73ff23d389bfc8feea02896528926e1544b4f929f45df2deb58698cd1c40836 |
Close
Hashes for npy_patcher-1.0.4-cp38-cp38-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e13d552e48a40400b5f226aa901d4afe1222b181fb1e198c44143d2fbe1b073 |
|
MD5 | 731f62ab0a2e49dfc065d84c7070bfdc |
|
BLAKE2b-256 | 9cd28b5ab6af2d0b69a8fe47812c111a92c49f2d075bbcbdb3a2f00789bba9b2 |
Close
Hashes for npy_patcher-1.0.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bdbbe2362f7a114f28b9786f8d164084dfbd3b39b4a36fa46a2e6fed5b040df |
|
MD5 | cc72b76651a33c226641c9840e4c31d3 |
|
BLAKE2b-256 | af4423c2bfd535fbd5cfba63bab4a6158cfe4579552cba4034c0f259b37b1065 |
Close
Hashes for npy_patcher-1.0.4-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4cdfa62a23ce6c4114c0a81f989c12691a939f0c034e349148ea34df243b6b1 |
|
MD5 | 0e2dd18e5ea833985aebaa66ec010ceb |
|
BLAKE2b-256 | efc31c6507a4d518b3de9f167155338a6bccae7bd9bd6af00891bc19d9c20635 |
Close
Hashes for npy_patcher-1.0.4-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05aa510cff89fa15a00b6feb64013b2fbcab92894d77414898f018aa9110095f |
|
MD5 | deba82acd22a32c18160268d39621d18 |
|
BLAKE2b-256 | 1b47ef1332ff687b5077fd3ebbfabab4fb786919c728eb2df4f5fea24fdd23bc |
Close
Hashes for npy_patcher-1.0.4-cp37-cp37m-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18ca8001cb4f9a177d4aff8e630446e5be611ef911a93c248a599baf0adea0b9 |
|
MD5 | b0d8488ffffa3a29d7c271de4d16f906 |
|
BLAKE2b-256 | 15dee70ca1bafc6d630f12a5e1dd334d1639680c4b891e76ad0f4873cfb90ea3 |
Close
Hashes for npy_patcher-1.0.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 113e1bf7caee91563014a63e30ca83a7df3577c50c9429643883f73b48c6c604 |
|
MD5 | ee89c15a8067860c3f7990d61aa9277c |
|
BLAKE2b-256 | 8dec2d609ef0da80e24913e220c05fdccd760cf39678b1341223300a547dda9d |
Close
Hashes for npy_patcher-1.0.4-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcfbee5c5205c41c5609fb20c127f4bd5286379924de254dcb2b1dbad426c63e |
|
MD5 | 3dbda5f9ae4b7f609a69b9878711d225 |
|
BLAKE2b-256 | d87af9874a383ee6c6f85842f7ccf20abb907dd706b7cc9727387704fa8832db |
Close
Hashes for npy_patcher-1.0.4-cp36-cp36m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7eb8dd6ffee4d5db7346486035ee719116afdb8df6c90add16e3b64e6a1cf97e |
|
MD5 | 55a7b3930cc2b42ad59f6183f61edd08 |
|
BLAKE2b-256 | 90fe36d40a390f6a1cdbec5f4b432a97a97d1ceb5668cf940118eaa8fc34e388 |
Close
Hashes for npy_patcher-1.0.4-cp36-cp36m-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c463b8f454e3a77fcabe7e533afbf7f3f2457d4f8bfb9d9c7fc7c3e9ff19f95 |
|
MD5 | 706c885bea4475aa3f38ef793944cd6a |
|
BLAKE2b-256 | 31564d66c3fcb402a26cf0f53740dc1c953431cb9220a1649560a0396096834d |
Close
Hashes for npy_patcher-1.0.4-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c425bf05db838b70f3e62ec7955393b4a618ae65f1ca4abda0eb6c8d37fc43df |
|
MD5 | 3955349a45f38d2712655cd168507f50 |
|
BLAKE2b-256 | 7c39a158a634b1c3876c3608f2525abb64fbe939941442dcd1ac8dc60d26572b |
Close
Hashes for npy_patcher-1.0.4-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78f40b97f89d13fd4c6a12b072e08df4aba9096b4333ba1e9ddb153062878431 |
|
MD5 | 518613c7bb1fc1e02d305f41eb00204a |
|
BLAKE2b-256 | 84f5d816bf2f157de0fe5b96bfc65b9663b921426ee7b5c686d3fa0dc8bb69bb |