ENN Ragged Buffer
This Python package implements an efficient RaggedBuffer datatype that is similar to
a 3D numpy array, but which allows for variable sequence length in the second
dimension. It was created primarily for use in enn-trainer
and currently only supports a small selection of the numpy array methods.
User Guide
Install the package with pip install ragged-buffer.
The package currently supports three RaggedBuffer variants, RaggedBufferF32, RaggedBufferI64, and RaggedBufferBool.
Creating a RaggedBuffer
There are three ways to create a RaggedBuffer:
RaggedBufferF32(features: int)creates an emptyRaggedBufferwith the specified number of features.RaggedBufferF32.from_flattened(flattened: np.ndarray, lenghts: np.ndarray)creates aRaggedBufferfrom a flattened 2D numpy array and a 1D numpy array of lengths.RaggedBufferF32.from_arraycreates aRaggedBuffer(with equal sequence lenghts) from a 3D numpy array.
Creating an empty buffer and pushing each row:
import numpy as np
from ragged_buffer import RaggedBufferF32
# Create an empty RaggedBuffer with a feature size of 3
buffer = RaggedBufferF32(3)
# Push sequences with 3, 5, 0, and 1 elements
buffer.push(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=np.float32))
buffer.push(np.array([[10, 11, 12], [13, 14, 15], [16, 17, 18], [19, 20, 21], [22, 23, 24]], dtype=np.float32))
buffer.push(np.array([], dtype=np.float32)) # Alternative: `buffer.push_empty()`
buffer.push(np.array([[25, 25, 27]], dtype=np.float32))
Creating a RaggedBuffer from a flat 2D numpy array which combines the first and second dimension, and an array of sequence lengths:
import numpy as np
from ragged_buffer import RaggedBufferF32
buffer = RaggedBufferF32.from_flattened(
np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18], [19, 20, 21], [22, 23, 24], [25, 25, 27]], dtype=np.float32),
np.array([3, 5, 0, 1], dtype=np.int64))
)
Creating a RaggedBuffer from a 3D numpy array (all sequences have the same length):
import numpy as np
from ragged_buffer import RaggedBufferF32
buffer = RaggedBufferF32.from_array(np.zeros((4, 5, 3), dtype=np.float32))
Get size
The size0, size1, and size2 methods return the number of sequences, the number of elements in a sequence, and the number of features respectively.
import numpy as np
from ragged_buffer import RaggedBufferF32
buffer = RaggedBufferF32.from_flattened(
np.zeros((9, 64), dtype=np.float32),
np.array([3, 5, 0, 1], dtype=np.int64))
)
# Get size of the first/batch dimension.
assert buffer.size0() == 10
# Get size of individual sequences.
assert buffer.size1(1) == 5
assert buffer.size1(2) == 0
# Get size of the last/feature dimension.
assert buffer.size2() == 64
Convert to numpy array
as_aray converts a RaggedBuffer to a flat 2D numpy array that combines the first and second dimension.
import numpy as np
from ragged_buffer import RaggedBufferI64
buffer = RaggedBufferI64(1)
buffer.push(np.array([[1], [1], [1]], dtype=np.int64))
buffer.push(np.array([[2], [2]], dtype=np.int64))
assert np.all(buffer.as_array(), np.array([[1], [1], [1], [2], [2]], dtype=np.int64))
Indexing
You can index a RaggedBuffer with a single integer (returning a RaggedBuffer with a single sequence), or with a numpy array of integers selecting/permuting multiple sequences.
import numpy as np
from ragged_buffer import RaggedBufferF32
# Create a new `RaggedBufferF32`
buffer = RaggedBufferF32.from_flattened(
np.arange(0, 40, dtype=np.float32).reshape(10, 4),
np.array([3, 5, 0, 1], dtype=np.int64)
)
# Retrieve the first sequence.
assert np.all(
buffer[0].as_array() ==
np.array([[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]], dtype=np.float32)
)
# Get a RaggedBatch with 2 randomly selected sequences.
buffer[np.random.permutation(4)[:2]]
Addition
You can add two RaggedBuffers with the + operator if they have the same number of sequences, sequence lengths, and features. You can also add a RaggedBuffer where all sequences have a length of 1 to a RaggedBuffer with variable length sequences, broadcasting along each sequence.
import numpy as np
from ragged_buffer import RaggedBufferF32
# Create ragged buffer with dimensions (3, [1, 3, 2], 1)
rb3 = RaggedBufferI64(1)
rb3.push(np.array([[0]], dtype=np.int64))
rb3.push(np.array([[0], [1], [2]], dtype=np.int64))
rb3.push(np.array([[0], [5]], dtype=np.int64))
# Create ragged buffer with dimensions (3, [1, 1, 1], 1)
rb4 = RaggedBufferI64.from_array(np.array([0, 3, 10], dtype=np.int64).reshape(3, 1, 1))
# Add rb3 and rb4, broadcasting along the sequence dimension.
rb5 = rb3 + rb4
assert np.all(
rb5.as_array() == np.array([[0], [3], [4], [5], [10], [15]], dtype=np.int64)
)
Concatenation
The extend method can be used to mutate a RaggedBuffer by appending another RaggedBuffer to it.
import numpy as np
from ragged_buffer import RaggedBufferF32
rb1 = RaggedBufferF32.from_array(np.zeros((4, 5, 3), dtype=np.float32))
rb2 = RaggedBufferF32.from_array(np.zeros((2, 5, 3), dtype=np.float32))
rb1.extend(r2)
assert rb1.size0() == 6
Clear
The clear method removes all elements from a RaggedBuffer without deallocating the underlying memory.
import numpy as np
from ragged_buffer import RaggedBufferF32
rb = RaggedBufferF32.from_array(np.zeros((4, 5, 3), dtype=np.float32))
rb.clear()
assert rb.size0() == 0
License
ENN Ragged Buffer dual-licensed under Apache-2.0 and MIT.
Metadata
Release files for ragged-buffer 0.4.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ragged_buffer-0.4.8.tar.gz | 26.1 kB | Without provenance | Details for ragged_buffer-0.4.8.tar.gz |
Built distributions (wheels)
Total release size: 5.9 MB
Release files / ragged_buffer-0.4.8.tar.gz
| Download URL | ragged_buffer-0.4.8.tar.gz |
|---|---|
| Size | 26.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
210e1d853a2d7de5d2eea49c79236ee80edbae3fd015c88067cf46885656abde
|
|
BLAKE2b-256 checksum How to use checksums |
728f38ebc4f35320f3ed2b7e328a5c5355c36d2db00125e4fecc57a3cfde34d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.17
|
Release files / ragged_buffer-0.4.8-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | ragged_buffer-0.4.8-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 348.2 kB |
| Tags | Linux glibc 2.17+ x86-64 PyPy 3.9 PyPy 3.9 7.3 |
|
SHA-256 checksum How to use checksums |
6cf37b7346dbd1be45e9f7214ac235eaf9140ceb5c4207ea0ad92e80f05d20e4
|
|
BLAKE2b-256 checksum How to use checksums |
5106895843e6c6b01e171ddf81c417e94607b6167d6f8734d73f940264d64dee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.17
|
Release files / ragged_buffer-0.4.8-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | ragged_buffer-0.4.8-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 348.1 kB |
| Tags | Linux glibc 2.17+ x86-64 PyPy 3.8 PyPy 3.8 7.3 |
|
SHA-256 checksum How to use checksums |
03637dfc82b1ae3c24e4af218b9b01ec1f65132f80eab3529ced470e336c8fa3
|
|
BLAKE2b-256 checksum How to use checksums |
e251767442b1787322e994a3ccc2579cd64e8dc8ceac722fcf495d9528f06b8f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.17
|
Release files / ragged_buffer-0.4.8-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | ragged_buffer-0.4.8-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 350.3 kB |
| Tags | Linux glibc 2.17+ x86-64 PyPy 3.7 PyPy 3.7 7.3 |
|
SHA-256 checksum How to use checksums |
1f7bdc6ce525ba16b8d536fb9d54ca91f340371f4ce0912c584cd9c92c9b9717
|
|
BLAKE2b-256 checksum How to use checksums |
874e6a11770d7c27bf08dea7c6b535b0c4f8c7379bf44f19f4508d797864362e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.17
|
Release files / ragged_buffer-0.4.8-cp311-none-win_amd64.whl
| Download URL | ragged_buffer-0.4.8-cp311-none-win_amd64.whl |
|---|---|
| Size | 277.3 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
a471a3a3852da9d36ee996044976bb4ee92857810c21635140f5abe0299892f1
|
|
BLAKE2b-256 checksum How to use checksums |
42688cd1d209a1f7895dcb874c5eae6773b11b74d7bf38c31b47236d183f226d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.17
|
Release files / ragged_buffer-0.4.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | ragged_buffer-0.4.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 348.2 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
845ae5961c4798ee9a5905b1f8e7dd300a5855666263b7e91e2ecd9fd4a77357
|
|
BLAKE2b-256 checksum How to use checksums |
4a46b5c26b7d64901e2396e1dbf3ca2741cc559d301128496d8ac4d5a1197c8b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.17
|
Release files / ragged_buffer-0.4.8-cp311-cp311-macosx_10_7_x86_64.whl
| Download URL | ragged_buffer-0.4.8-cp311-cp311-macosx_10_7_x86_64.whl |
|---|---|
| Size | 335.0 kB |
| Tags | CPython 3.11 macOS 10.7+ x86-64 |
|
SHA-256 checksum How to use checksums |
abc246ba0d95c951bd4d6563b19bc937c9da8f682d609c0eed6ec77a0da748a0
|
|
BLAKE2b-256 checksum How to use checksums |
55e5d9d71ef1509dcbc3dfd080094be68604b6f9f778e5f547b4f26391b8fcc8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.17
|
Release files / ragged_buffer-0.4.8-cp310-none-win_amd64.whl
| Download URL | ragged_buffer-0.4.8-cp310-none-win_amd64.whl |
|---|---|
| Size | 277.3 kB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
5d4cf1b5d20dd883cc23dc9e888ec270fca674aa3339981dfea07ff1cd99cd4d
|
|
BLAKE2b-256 checksum How to use checksums |
1504d36d8d3c4f8d784ace022a0c37b246aee8abc41de08730a161da66362f41
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.17
|
Release files / ragged_buffer-0.4.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | ragged_buffer-0.4.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 348.2 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
2c73b91d7051703a9f6b41748f8df41ad20098054266a8a09273bf0fcc50f685
|
|
BLAKE2b-256 checksum How to use checksums |
cb099a685dbbf8c8a054760293bdb087e70e1c5f59a76e6544d7441cdf28175e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.17
|
Release files / ragged_buffer-0.4.8-cp310-cp310-macosx_10_7_x86_64.whl
| Download URL | ragged_buffer-0.4.8-cp310-cp310-macosx_10_7_x86_64.whl |
|---|---|
| Size | 335.0 kB |
| Tags | CPython 3.10 macOS 10.7+ x86-64 |
|
SHA-256 checksum How to use checksums |
a93b17ffb074cf27b759224bb24f04ed0708f3f484e945b2d080be10a2411a44
|
|
BLAKE2b-256 checksum How to use checksums |
a0bf0028e2b832356fc713aa0c5ea504d2b627173ce6a1820d0b595d7e40c004
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.17
|
Release files / ragged_buffer-0.4.8-cp39-none-win_amd64.whl
| Download URL | ragged_buffer-0.4.8-cp39-none-win_amd64.whl |
|---|---|
| Size | 277.3 kB |
| Tags | CPython 3.9 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
ce5caecce4bb8d4ba2b5197b9726c8987818eb731a522814519acd3e743c5dbd
|
|
BLAKE2b-256 checksum How to use checksums |
8c752fda0af15d26e5424c8c3c741a55578a9beadae20cc25cab1e47e5ec494d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.17
|
Release files / ragged_buffer-0.4.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | ragged_buffer-0.4.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 348.5 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
36184151040a2c1b8d9d03eb9c916e7c34eee6f9d6927f199fe96200a7061fd6
|
|
BLAKE2b-256 checksum How to use checksums |
28ad1b74e66f11e4d18c799ca7b6bd1c1bd5cbef8334dd3159f68f414e1416cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.17
|
Release files / ragged_buffer-0.4.8-cp39-cp39-macosx_10_7_x86_64.whl
| Download URL | ragged_buffer-0.4.8-cp39-cp39-macosx_10_7_x86_64.whl |
|---|---|
| Size | 335.2 kB |
| Tags | CPython 3.9 macOS 10.7+ x86-64 |
|
SHA-256 checksum How to use checksums |
7359d8e148737963aefd40e8cfc500e067b5619b2931e3ace511d658cc29c994
|
|
BLAKE2b-256 checksum How to use checksums |
b2ebf968570cf6f9a477c1bf8142688e8c7854a35c5d6a7db76f2571060af4cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.17
|
Release files / ragged_buffer-0.4.8-cp38-none-win_amd64.whl
| Download URL | ragged_buffer-0.4.8-cp38-none-win_amd64.whl |
|---|---|
| Size | 277.1 kB |
| Tags | CPython 3.8 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
f09da81eea400659eae3bf44e0e7715a0c8f56b2e5c097de565a06ff2c564944
|
|
BLAKE2b-256 checksum How to use checksums |
b382e6b33adf5d7fb5285f3f081dfeec1fe75cbab76608ac5d42d3c93f48f538
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.17
|
Release files / ragged_buffer-0.4.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | ragged_buffer-0.4.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 349.1 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
c7e36f5ea7ee2daa89565556c3794c51a0a8eb37b7139b00a3b93519b5a2e83c
|
|
BLAKE2b-256 checksum How to use checksums |
15cee8831e7666bbb5c721df6a26ecec3905470c5fa2e82e77e166d5c62d01a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.17
|
Release files / ragged_buffer-0.4.8-cp38-cp38-macosx_10_7_x86_64.whl
| Download URL | ragged_buffer-0.4.8-cp38-cp38-macosx_10_7_x86_64.whl |
|---|---|
| Size | 335.7 kB |
| Tags | CPython 3.8 macOS 10.7+ x86-64 |
|
SHA-256 checksum How to use checksums |
0bc21f55c09075e39225e7100daafab8e07c449f71578b53c86086ccd8cd209c
|
|
BLAKE2b-256 checksum How to use checksums |
e47f68f8fccb647e3c5d8468bb3b0aee31a646a616eb4f7380688ee97e8ea506
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.17
|
Release files / ragged_buffer-0.4.8-cp37-none-win_amd64.whl
| Download URL | ragged_buffer-0.4.8-cp37-none-win_amd64.whl |
|---|---|
| Size | 276.9 kB |
| Tags | CPython 3.7 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
07cf8f4c1ce9f42043252f73bbbd3ef539933744e54adac05101217e6744f642
|
|
BLAKE2b-256 checksum How to use checksums |
3db0d3549bd69efc17fe6e195f0a080df8de5c034b9d992ecf9e677b91aacae7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.17
|
Release files / ragged_buffer-0.4.8-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | ragged_buffer-0.4.8-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 349.0 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
d603a59e6c5693e9b685c194349bd9fd153779ec8c8c9413ab4eae69e4d91e98
|
|
BLAKE2b-256 checksum How to use checksums |
0f7f02875144e0e142d5940260f33a395007823d89b3abdfc5ff5084fbc319c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.17
|
Release files / ragged_buffer-0.4.8-cp37-cp37m-macosx_10_7_x86_64.whl
| Download URL | ragged_buffer-0.4.8-cp37-cp37m-macosx_10_7_x86_64.whl |
|---|---|
| Size | 335.7 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc macOS 10.7+ x86-64 |
|
SHA-256 checksum How to use checksums |
ad7c9ab852367efea72ddb16a1da839d6c60929a81c9d5a776a060fa3cad0c1d
|
|
BLAKE2b-256 checksum How to use checksums |
834589dd8e859c0eed0e2840c737ef29ebf83dfedf81ca2a1b67f815bab26c57
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.17
|
Security for ragged-buffer 0.4.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.