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_stride = (30, 30) # Contiguous patch stride, set a smaller value than `patch_stride` for overlapping patches.
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.
extra_padding = (0, 0) # Optionally apply extra padding, this is applied after initial padding calculation.
patch_num_offset = (0, 0) # Optionally provide an offset to extract patches after.
patch = patcher.get_patch(
data_fpath, nc_index, patch_shape, patch_stride, patch_num, extra_padding, patch_num_offset
)
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};
std::vector<size_t> patch_stride{30, 30};
size_t patch_num = 2;
std::vector<size_t> extra_padding = {0, 0};
std::vector<size_t> patch_num_offset = {0, 0};
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_stride, patch_num, extra_padding, patch_num_offset
);
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.3.0.tar.gz
(13.3 kB
view hashes)
Built Distributions
Close
Hashes for npy_patcher-1.3.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a405f48208710c8becca54036518452258d242929ef0824e0588ca1b7e8febaa |
|
MD5 | e061e526765b910662c92e0bf85ef880 |
|
BLAKE2b-256 | 88f759b3c91d9884c119424f08a28af28d12f7e4e5738666ac428f566697a5e9 |
Close
Hashes for npy_patcher-1.3.0-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1561b924f81093c7467776bd894cc1b1756028e3c8a0883b4775d00db858198c |
|
MD5 | 29a49afd638bdf228468d17a55d21a28 |
|
BLAKE2b-256 | eccd687f994bc00a5f7b0539b363c6cf18add4f94f35f0f25902271203a073f2 |
Close
Hashes for npy_patcher-1.3.0-pp39-pypy39_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21cba939201848ffeaa4bbd70d57ab9d83cbfc7bb9e29b0715e4685e9a0abf4c |
|
MD5 | 2a4a43997d203ad87c88511d690ce2fa |
|
BLAKE2b-256 | 07c6e8e76dc17e835bcd0e91e8df81c21f12b80f7ee786af6e31430d7c3f23b2 |
Close
Hashes for npy_patcher-1.3.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1dcb2d87a035653d56b1e5fd0bb17e5c8da50f0e19c0a38a999d3c1527b95e3f |
|
MD5 | be0dbec68817ac5470c5f192577c4293 |
|
BLAKE2b-256 | cfc167cd88fa6b286e0bf8b811ffc1d5bb561c39ec9e303c6cd363c72d6db85c |
Close
Hashes for npy_patcher-1.3.0-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69aefc9970c18cfa2b88d5692b8a8f6378db22626700c0c0e586c2c922f775b6 |
|
MD5 | 6d56a6d55a96c054978c8c75f34c58a3 |
|
BLAKE2b-256 | 0abc8e4f34ea4b2f118e7a244055dddfb7c37898fc358d265f58ffdbea367bc7 |
Close
Hashes for npy_patcher-1.3.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c06a6db83733eaca969d3ef7d92c2d0e2f3bbc65be25dc95f87eebdd30550b76 |
|
MD5 | 04a0f848cfa2de2bbd2e7e73a2275830 |
|
BLAKE2b-256 | 18fb57b660c2b3fd6bbf0c11850488a67a292d939118a27ec4a39b4e107e8b9d |
Close
Hashes for npy_patcher-1.3.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28ba28de3dc34cb8340d15d821db9c6e1fef70ec690ee2dbb18b6b5f39d99894 |
|
MD5 | 0251e510b028421f3503277b732b24e4 |
|
BLAKE2b-256 | ca4ff142e26e562019772899cf75a3a0862c41352ccafc15c36c4219e771d929 |
Close
Hashes for npy_patcher-1.3.0-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac5c8758e80eac36f6909edc80876965054dd6f5e4732b697238db7da7bf202e |
|
MD5 | 24a189782bf4b2eb871552607d4d41bd |
|
BLAKE2b-256 | a9f958cb66bcbfcfb5f7e8a00145e67e325a77ec0e711f86bee4bc48b1cdf49a |
Close
Hashes for npy_patcher-1.3.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b12fedefb439e658b3d39b1854db60747dd7a043bd0730da270db7e56f59634 |
|
MD5 | 61ebac6a13ca89e25d99f2ca655ac1fa |
|
BLAKE2b-256 | cc6a80f36a7e7045454f7e1f1ee45048d5f1d6571dab4cd41e7a0b5d2068e92f |
Close
Hashes for npy_patcher-1.3.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0e1030a5555036f54d3cf83657948c743c8cd502892327d450c6460510f25e2 |
|
MD5 | f9420262e16c645c3bdb0dc866851fb2 |
|
BLAKE2b-256 | 0678831df882d349545ab01e61b482f0271413e724eca356a02e0676eaa3f4e1 |
Close
Hashes for npy_patcher-1.3.0-cp310-cp310-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4532bce58a3247c96d99726d26b6d0b26a04d9f361323889c0c7704abb8c04b |
|
MD5 | eef3d022ed097504e7e3efd15427c469 |
|
BLAKE2b-256 | a5fc52b917ec35157795e098ddfba3d783c8f7c603aa1ef19ecd9805cb4c94ab |
Close
Hashes for npy_patcher-1.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 746857be67255df3845095a374aea1cd3b38ad5f1dab53986a32fbf59c57da85 |
|
MD5 | 68fecff9f65401f615e050d241da9d15 |
|
BLAKE2b-256 | 5666972417001fd0ef54442dbfa41b81fe8fe0c26eae4403fea9b3f3faa378f2 |
Close
Hashes for npy_patcher-1.3.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae5503442f173e208c2bd665a95ef0b3d6203628ea615bd668b7c5f1dfae48e9 |
|
MD5 | 01dcc46680d8e2db9d631bb658eba45d |
|
BLAKE2b-256 | 764fdcc22b4343ef4b54bfaf5998e2962c495d836f7b3ad7ae40642a454ebe54 |
Close
Hashes for npy_patcher-1.3.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a9812d89d2206efdec3472af2c381ef51d7549d28b5f57e7da5307f25cde13f |
|
MD5 | dd3a98b870e3ba1295f5e4acf7823046 |
|
BLAKE2b-256 | 9c5ba72ddc61a634ad2d771b2d877e620f3bc04f9e2857fc1c22349c515a9a1c |
Close
Hashes for npy_patcher-1.3.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f3671c67fda9b175035ea6c52c05f83617890349bf44a1088793c01bceefabe |
|
MD5 | 37e41acab066a5e6f5d840c024e0881c |
|
BLAKE2b-256 | cd7534fb4bf1df1c94745517f4a943e38d825a52756bf29b23f674abad7d6a46 |
Close
Hashes for npy_patcher-1.3.0-cp39-cp39-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f4b8df6e1be1a0fe58ffb60298b6e258a39855f069bfee8cdb9147ea8c71cd1 |
|
MD5 | f686d9e63d7daecea82b5f30e3d421fb |
|
BLAKE2b-256 | 0201fd6202489d2333fe2f91e2536c2a36006f0d8867fbff692dc47135ebf5b3 |
Close
Hashes for npy_patcher-1.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cb5ab437ea73404ea3e71a85353611bbec7d789d2617cc3486e2f97b2d9f6e7 |
|
MD5 | ce23cbb406602f7effbf28095f2eec5c |
|
BLAKE2b-256 | 6b894500042412f269e646784c6d1219d534593eeca6ccf88a9ba0c2c7df4b99 |
Close
Hashes for npy_patcher-1.3.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | afd019030931bb098bef42240b730d45b8ede6cf4761641dae5f1284ea0ef681 |
|
MD5 | 48adb93eab8a40ceab9db04a32dd1101 |
|
BLAKE2b-256 | edf624b3bdf9f42b5de6b17f069eb551b4bf662845480817ebfb3cf522241636 |
Close
Hashes for npy_patcher-1.3.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c13d9dd073bacb7bbdb32b6cc99c987863f7a7205ca2b6efdc51b7ce36b833ed |
|
MD5 | 7a5c82ed56662e5ccb097685fa82e263 |
|
BLAKE2b-256 | 5315b214919ec361565355d919dd1558abe406d761c425f17ba140fc66fcb164 |
Close
Hashes for npy_patcher-1.3.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 207c87b1d85ad35b05b898077cc5b1c27f9a26dad6e787329e8d6594b78e3e78 |
|
MD5 | f04dfa4da71e278b804a084c88d41a99 |
|
BLAKE2b-256 | 44522e2b8db8622f6b409e52d901ea132a14b10c38797835327d7a3baf964da4 |
Close
Hashes for npy_patcher-1.3.0-cp38-cp38-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 199e0903ff35e9d24d4828aebeefdfb7ef5cd92e27afdc82a01ff7c9ec002f89 |
|
MD5 | 3fa02a403eb7f3aad9b598b2beea14ec |
|
BLAKE2b-256 | 95c284ecf18bdd1a7f723f4f2ee7ba7a8b3a82ca2cf0f16ae1613c2e2e4bd3ab |
Close
Hashes for npy_patcher-1.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10291ffb56447ef4aff79354f1b730f9e1865bfc456cdb905989c27c0a577c40 |
|
MD5 | 75cd23b089f9f42f1feb7dd955ec1ccf |
|
BLAKE2b-256 | 335c25b54f15247ed8a819e995ad33a87ec3487439500a72c4f4ee25d20631fc |
Close
Hashes for npy_patcher-1.3.0-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc10980ea247ac058bb5362bb6ea0e4fbe295642791409a85d6475e4391f100f |
|
MD5 | 7bed87866badf88f3baf4761b20f014f |
|
BLAKE2b-256 | f6da0c8f209830fbcb48df7e14040ba8a13d2f5fd7f18467750c56744e28de69 |
Close
Hashes for npy_patcher-1.3.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 593e70bfb32ff3ce76a7e0d61e2ff85aba9c200839352e6897dd9336e36cc90b |
|
MD5 | 6b4c2ebebd127d8e66911aa918acecc5 |
|
BLAKE2b-256 | 87809c59f408cd65aebcacfa53adc31baee2665de43561ce8a6e4c54b6121e64 |
Close
Hashes for npy_patcher-1.3.0-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 399db9a913623980151f14c6844e6fcec2a8fd629e72b44c25d8fa839f3b3db0 |
|
MD5 | f58bc747d9066998bba7143c6cd051a1 |
|
BLAKE2b-256 | 03ce0e10e06f6a39efb8eac3cfe4e92bea02617fc067338a42ff3512c1a5202b |
Close
Hashes for npy_patcher-1.3.0-cp37-cp37m-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76c82af3c84ab3c288d91ae0652a5f777d7ae9c1b59930a7b0db2b4fb08a9c46 |
|
MD5 | bf90192f19b609ec86b4b034064e950c |
|
BLAKE2b-256 | 3d7fedf128d28e96dfed413dc982d3c6eff8e34ae058eca83971d29e8e8814de |
Close
Hashes for npy_patcher-1.3.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d116d8d1cab485e6295703c618855990689b5d81ae122f252e3b4f10f27128b7 |
|
MD5 | a8f7748cd3ecd8306e8df29437c0ac6d |
|
BLAKE2b-256 | f2f9a35f9ff2d1977b61b23a7e0261c4c443294cab320f00224b62d02fefb6bb |
Close
Hashes for npy_patcher-1.3.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6c625326781a4ad6eecc4c29836fda48ef981d09da94a8ac2fef7d7c27bde2f |
|
MD5 | b485f7c4ff137978e320425d51f7ada1 |
|
BLAKE2b-256 | c546a263e94a79464347db46a7f29fbc6cc6b3ab66a44a5ef178f4f03be5ea9b |
Close
Hashes for npy_patcher-1.3.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 306cd04945439202baebf179f339573a41bee409129557047d8e1fddc1cb152f |
|
MD5 | 20fb383ed1ab901be5cfeede64ee89a1 |
|
BLAKE2b-256 | cc51d5e2ce7fa107c5f9909ea3d48be23e33a1d5b761d87aa7615449d823ca6f |
Close
Hashes for npy_patcher-1.3.0-cp36-cp36m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 452b4690b3fb038802b6eb032a1b13ba6f3394bd258ec705223d441d66d825a1 |
|
MD5 | 6bf457156914a26b1194d78f5ea7f201 |
|
BLAKE2b-256 | cce5ca4d053961611553fd7e20d42d1be641d9a8841a2eb00b9fb667f1981f0d |
Close
Hashes for npy_patcher-1.3.0-cp36-cp36m-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 786928d43307e8d38476deb31e91035ab0980a2de235018cd98de47b17c47f1e |
|
MD5 | 0886ef57e355418f26d34185db230475 |
|
BLAKE2b-256 | 9b87360a919986f769f3063e7a01a846a7c4e9872fe9ceb06db6000bd040196e |
Close
Hashes for npy_patcher-1.3.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05e52509b2060f6b7b8f316a91d7123a94d075266ce2a74d12d108b121cd5b01 |
|
MD5 | 5bb03f68f39e7bf10f195b8d1db8438b |
|
BLAKE2b-256 | e6cc82bfcbc696a55f0788b3d31774847e6b5d4c261e416c89dde773e2429c17 |
Close
Hashes for npy_patcher-1.3.0-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46db7641b1fb6f93785382d6f0cfe9e40b24402058b31160ce1a0ee8c4f25088 |
|
MD5 | 784990374448873d6f4a36458ce97b9e |
|
BLAKE2b-256 | 798f9b58ebe406ac7af06eb995f49ae8d07448d54bbaa712bf771a92d7b388cd |
Close
Hashes for npy_patcher-1.3.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cddbc4058a9b474f1271bbc11dde13aeae87a1896c3d21dd6f0359a7174b35dc |
|
MD5 | c586e6aab899c900627d96b62fa3bcd1 |
|
BLAKE2b-256 | c54fa9f40cabbfc897b671cb045e8e7d866fde6c2ad105abd8025a5ff4d51a92 |