Skip to main content

Dynamically sized slice views which avoid storing their own data.

Project description

sliceit

Dynamically sized slice views which avoid storing their own data.

The builtin list, tuple, str, etc., create copies when sliced. This is to allow all of the unnecessary memory to be freed if it is no longer needed. In some cases, the opposite problem occurs, where none of the memory needs to be freed anyways, meaning slices simply take up more space than necessary.

Some data structures provide slicing views already, such as:

  • numpy
  • pandas
  • tensorflow
  • and many other data science packages

If these packages already fit your needs, consider using them instead.

What's different?

sliceit provides sliceable views any Sequence (or MutableSequence), meaning it works for lists, tuples, strings, etc., and can also be used as an easy way to implement slicing for custom classes.

Furthermore, sliceit uses lazily evaluated slices. This means the underlying data is free to change size as much as it wants. The catch is that some objects may raise runtime errors if you try iterating over them at the same time.

Unlike some, sliceit is also recursively sliceable and supports mutations, although modifying slices may in some cases be unintuitive.

Install

Unix/macOS:

python3 -m pip install sliceit

Windows:

py -m pip install sliceit

Examples

from sliceit import sliceit

print("Create a slice view of some data.")
L = list(range(10))
S = sliceit(L)[::-1]
print(f"L = {L}")
print(f"list(S) = {list(S)}")

print()

print("Slices act as a view over the data.")
print(f"list(S) = {list(S)}")
L[0] = -10
print(f"L[0] := -10")
print(f"list(S) = {list(S)}")
L[0] = 0
print(f"L[0] := 0")
print(f"list(S) = {list(S)}")

print()

print("They can be looped over or indexed as you would expect.")
print(f"[x for x in S] = {[x for x in S]}")
print(f"S[0] = {S[0]}")

print()

print("If the data is mutable, the slice is mutable.")
S[0] = 0
print("S[0] := 0")
print(f"L[-1] = {L[-1]}")
S[0] = 9
print("S[0] := 9")
print(f"L[-1] = {L[-1]}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sliceit-0.0.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

sliceit-0.0.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file sliceit-0.0.1.tar.gz.

File metadata

  • Download URL: sliceit-0.0.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

File hashes

Hashes for sliceit-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6fc557f17f306e0ce40be269c5ad2a9e4686006508bb8115f7cd99b12856eabd
MD5 ed93b2f851f5c7fb49e93897357a750b
BLAKE2b-256 3b46b2f4c7145c5de91731389a1d6242647a3868e7c63cfb5adeb34f6e3b04b9

See more details on using hashes here.

Provenance

File details

Details for the file sliceit-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: sliceit-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

File hashes

Hashes for sliceit-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f1e768496d4b2bdc2a804c876a422997c2b7c14ec928c1f7ad2986de8ab6be89
MD5 5afd292a95fff46c813ff555a25ae094
BLAKE2b-256 e86f642d090d55171bc76acbf248ef4cb630b71b395e202c3452223edbb2e4ba

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page