Skip to main content

Python package for performing set type operations on any layout of discrete space in any dimension.

Project description

blocksets

Python 3.11 PyPI - Version Read the Docs Codecov

Python package for performing set type operations on any layout of discrete space in any dimension.

  • Block is an orthogonal clump of units/pixels (i.e. a line segment, rectangle, cuboid, hyper... you get the idea)

  • BlockSet is a set of blocks that resolves any make-up of blocks to a disjoint set in a consistent fashion

Why?

You might choose to use a BlockSet instead of a regular python set of points/pixels because the resolution/granularity is sufficiently high, meaning the number of pixels/points being modelled due to the expanse of the space pushes the limits of the available computing power.

How?

  • Create any layout (as a blockset) using a stacked list of block operations which add remove or toggle blocks over the current blockset state.
  • Perform the usual set arithmetic union intersection difference etc. on blockset objects.
  • Compare 2 blockset objects using the standard set comparison methods and operators == <= >=.
  • Results are always consistent regardless of how they were constructed.

Installation

Requires python 3.11 or higher, there are no dependencies.

pip install blocksets

Usage

Full documentation is available (work in progress) at readthedocs

It's worth reviewing and running the example_use.py module via python -m blocksets.example_use

TL;DR

from blocksets import Block, BlockSet

# A block is defined by the co-ordinates of the opposite corners
big_rubik = Block((0, 0, 0), (99999, 99999, 99999)) 
assert big_rubik.measure == 999970000299999

# A single argument is a unit block
centre_cube = Block((49999, 49999, 49999))
assert centre_cube.measure == 1

# Create a large 3 dimensional cube with the centre missing
bs = BlockSet(3)  
bs.add(big_rubik)
bs.remove(centre_cube)

assert bs.measure == 999970000299998
assert len(bs) == 6

sorted_blocks = sorted(bs, key=lambda x: x.norm)

for blk in sorted_blocks:
    print(f"{blk:50} {blk.measure}")

The resulting space is modelled using 6 objects (effectively tuples) instead of 999970000299998

(0, 0, 0)..(49999, 99999, 99999)                   499980000249999
(49999, 0, 0)..(50000, 49999, 99999)               4999850001
(49999, 49999, 0)..(50000, 50000, 49999)           49999
(49999, 49999, 50000)..(50000, 50000, 99999)       49999
(49999, 50000, 0)..(50000, 99999, 99999)           4999850001
(50000, 0, 0)..(99999, 99999, 99999)               499980000249999    

Visualisation

An example of 2D set operations on some randomly generated block sets A, B and drawn using matplotlib.

2D - All Set Operations Example

Contribution

At the moment it is early days so whilst the foundations are forming I am only inviting comments which can be given via github issues

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

blocksets-0.2.0.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

blocksets-0.2.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file blocksets-0.2.0.tar.gz.

File metadata

  • Download URL: blocksets-0.2.0.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for blocksets-0.2.0.tar.gz
Algorithm Hash digest
SHA256 228364204eee6110f6ad08952522df22521e853d867f60439fd5f8dc7c0e2ac0
MD5 5259aac10a8a32cf6041629aff9a4851
BLAKE2b-256 dd3fe21fd84660302e2a678bbad7ab0c8a4ca7c5e92b2c2fc79c6b0654d1adcd

See more details on using hashes here.

File details

Details for the file blocksets-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: blocksets-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for blocksets-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 639369623b62deac0feb17afc2b13a921caf3bef44d1cfcff7e063a35c87c21d
MD5 56a614562501f08768fa5b0bcc258a31
BLAKE2b-256 ba63eb3e54b5eaafb8086eea6ef8be5b0c74213424d958851f684801e6d73e83

See more details on using hashes here.

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