Skip to main content

blocksets

Python 3.11 PyPI - Version Read the Docs Codecov

A python package for performing set operations on layouts 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 takes a layout and resolves it to a disjoint set of Blocks in a consistent fashion, regardless of how the layout was composed.

Why?

You might choose to use a BlockSet instead of a set of tuples because the resolution/granularity is sufficiently high to warrant it.

Or in other words, the number of pixels/points being modelled pushes the limits of the available computing power due to the expanse of the space they take up.

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

blocksets is available on pypi.org and can be installed using pip (there are no dependent packages).

pip install blocksets

Usage

Visit readthedocs

Review and run the example_use.py module via python -m blocksets.example_use for a few examples, one of which follows here.

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. See readthedocs for code snippet to generate this

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

Metadata

Release files for blocksets 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for blocksets 0.3.1
File Size Uploaded
blocksets-0.3.1.tar.gz 24.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for blocksets 0.3.1
File Interpreter ABI Platform
blocksets-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 39.9 kB

Release files / blocksets-0.3.1.tar.gz

Download URL blocksets-0.3.1.tar.gz
Size 24.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0f6ccc3a7d52aaa27c68eebc98523b19fbbd83d8a7e454e57bc5e4c646e2625e
BLAKE2b-256 checksum
How to use checksums
edb754c998406fdf79390c1ccf2acb3004bb3134d39c8aa1c24b8d7e8a2be3cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / blocksets-0.3.1-py3-none-any.whl

Download URL blocksets-0.3.1-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d3f6235b2e26f750e62f716db91270c26998e1eeae1ce2a9a4fac09d2dd2fe0
BLAKE2b-256 checksum
How to use checksums
12a3a7fa5f38a375815a379873d433440a02f8d0f48ffc7e3868bf06eada3ea1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.13

2 release files

0.1.12

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page