Skip to main content

No project description provided

Project description

combin

coverage_badge macos workflow status windows workflow status linux workflow status

Lightweight implementation of various combinatorics routines (Under construction!).

Current routines offered:

  • Combinatorial number system ranking/unranking (rank_to_comb and comb_to_rank)
  • Binomial coefficient inversion (inverse_choose)

Installation

combin is on PyPI and can be installed with the usual command:

python -m pip install combin

If this fails for your system, please file an issue.

Usage

combin supports fast bijections to the combinatorial number system.

from combin import comb_to_rank, rank_to_comb

## Fix k-combinations of an n-set
n = 10 # universe size 
k = 3  # size of each combination

## Ranks each 3-tuple into its index in the combinatorial number system  
C = combinations(range(n), k) # from itertools 
R = comb_to_rank(C, order='lex', n = n)
print(R)
# [0, 1, 2, ..., 119]

## If a generator is given, the default return type is a list
assert R == list(range(120))
# True

## Alternatively, combin has native support for NumPy arrays
C = np.fromiter(combinations(range(n), k), dtype=(np.int16, k))
assert np.all(comb_to_rank(C, order='lex', n=n) == np.arange(comb(n,k)))
# True

## An alternative bijection can also be chosen, such as the colexicographical order
## Note the colex order doesn't require the universe size (n)
print(comb_to_rank(C, order='colex'))
# [0, 1, 4, ..., 119]

## Unranking is just as easy: just supply n, k, and the order
R = np.arange(comb(n,k))
C_lex = rank_to_comb(R, k=k, n=n, order='lex')
print(f"Equal? {np.all(C_lex == C)}, combs: {C_lex}")
# Equal? True, combs: [[0, 1, 2], [0, 1, 3], [0, 1, 4], ..., [6, 8, 9], [7, 8, 9]]

## Uniformly sampling from k-combinations becomes trivial
ind = np.random.choice(range(comb(n,k)), size=10, replace=False)
random_combs = rank_to_comb(ind, k=k, order='colex')
# [[2, 7, 8], [1, 4, 6], ...]

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

combin-0.1.5.tar.gz (63.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

combin-0.1.5-cp311-cp311-win_amd64.whl (120.4 kB view details)

Uploaded CPython 3.11Windows x86-64

combin-0.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (158.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

combin-0.1.5-cp311-cp311-macosx_11_0_arm64.whl (116.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

combin-0.1.5-cp311-cp311-macosx_10_9_x86_64.whl (121.9 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

combin-0.1.5-cp310-cp310-win_amd64.whl (118.1 kB view details)

Uploaded CPython 3.10Windows x86-64

combin-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (157.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

combin-0.1.5-cp310-cp310-macosx_11_0_arm64.whl (115.0 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

combin-0.1.5-cp310-cp310-macosx_10_9_x86_64.whl (120.3 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

combin-0.1.5-cp39-cp39-win_amd64.whl (118.1 kB view details)

Uploaded CPython 3.9Windows x86-64

combin-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (159.1 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

combin-0.1.5-cp39-cp39-macosx_11_0_arm64.whl (115.1 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

combin-0.1.5-cp39-cp39-macosx_10_9_x86_64.whl (120.3 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

combin-0.1.5-cp38-cp38-win_amd64.whl (117.9 kB view details)

Uploaded CPython 3.8Windows x86-64

combin-0.1.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (158.4 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

combin-0.1.5-cp38-cp38-macosx_11_0_arm64.whl (115.0 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

combin-0.1.5-cp38-cp38-macosx_10_9_x86_64.whl (120.3 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

File details

Details for the file combin-0.1.5.tar.gz.

File metadata

  • Download URL: combin-0.1.5.tar.gz
  • Upload date:
  • Size: 63.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for combin-0.1.5.tar.gz
Algorithm Hash digest
SHA256 d7ee77d5ab61fb9d90a3d6994d9f1098ce0d566bb0f6395967393df67f236237
MD5 7328359c54b27b7cebdf855f3267e3be
BLAKE2b-256 0be3598a76aea61c209bf63da3a4b348f39510819f13e1b546f35c793c4f4147

See more details on using hashes here.

File details

Details for the file combin-0.1.5-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: combin-0.1.5-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 120.4 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for combin-0.1.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 48681520bfa507dc21877e9bdc72aa5653cfcd8f21c1d3637e3cf56608ac9d75
MD5 2155f2f4fee35e7dfe6e28ecebab4411
BLAKE2b-256 cef8089e10c5d8bad7d3fc92b630cbe2c0fd490fcec96fac61c30fbdd53ed7c8

See more details on using hashes here.

File details

Details for the file combin-0.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for combin-0.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0ae88f0bcc2b644f884d5d3398faa6249fb7140a3dc79e41f24129ecdef28532
MD5 0112672782748eea805a5b4480bbc803
BLAKE2b-256 33602cd175c7eb755233d932321b884868fee223e8beb38daaf2e8ac72faf1f7

See more details on using hashes here.

File details

Details for the file combin-0.1.5-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for combin-0.1.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f480711d8c13665e4fa69128846a277438c0249dbf66706122213c2654c124b0
MD5 499b25474a3406a380d39c8887617249
BLAKE2b-256 a933fc8b7266f4e57fe58ae0f2940ca76f0ebefcc4b09d458699f2561468a9e1

See more details on using hashes here.

File details

Details for the file combin-0.1.5-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for combin-0.1.5-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4ee59eba56770d38ab886a19685b06fca0ac38c90038b34b4e24ed0169284919
MD5 08314d9382b5b7eb43e60110da013c7a
BLAKE2b-256 d5b553abec33eca5d2e49d6b3bd4012e5c555c22f162916043bc01c5741516bb

See more details on using hashes here.

File details

Details for the file combin-0.1.5-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: combin-0.1.5-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 118.1 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for combin-0.1.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 df922a5125fb784db8631e923be8f311939fb2eca3f1bb71be7dd7edc5a22995
MD5 d8607f87fa88258ad637e6ba567400d1
BLAKE2b-256 6403497959993edf00479f38e516d1dc7bc03da38da3ce271d0fd00784fe4e68

See more details on using hashes here.

File details

Details for the file combin-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for combin-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7a526177443035ea558fc250f07ba8ee399862c48b90418af0277759b7ba3da7
MD5 3976a7b113ae0bb93208ec3084ae2d74
BLAKE2b-256 527df2c4b21a025f90a99174ed65a7f84ea774ebd6949d1f9b4686ac09791414

See more details on using hashes here.

File details

Details for the file combin-0.1.5-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for combin-0.1.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9916ade7326ab5339afb4baccd29d6d04d37fbc5b34754871dbfeca470e095ae
MD5 8430e940c94765b6f18e7d87f1cca283
BLAKE2b-256 127123d325e0da84a72604e087c2961098a1a9e5eaeb41d4070ad9210816cdc8

See more details on using hashes here.

File details

Details for the file combin-0.1.5-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for combin-0.1.5-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 932c7e44caa4e464180624bdd5749cef4e7390a6eecec69472e00a793f4cbf7f
MD5 15e66f5c21f697cafa031f4f31f1295a
BLAKE2b-256 e18132c028e8222f9c9a51a2fef4299c793bc0084a29f4e3e194e22a8e1fc194

See more details on using hashes here.

File details

Details for the file combin-0.1.5-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: combin-0.1.5-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 118.1 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for combin-0.1.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 1ba8bf55f1e4c266e9c94353640002e694c9314da81d75a4c1d8853faba8f2fa
MD5 6d72e02bb2d40147ec43c894a7292549
BLAKE2b-256 3be2053562f893677b2f1bde41d01e17feaaaee7382ed55e05718e7a1fc8f4f7

See more details on using hashes here.

File details

Details for the file combin-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for combin-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 be44bf89bd059c4503876e6198cd8456a36971bf69c9175bb9a528a3b0635a5f
MD5 3278e818d0c9abad5a983278bcf669b9
BLAKE2b-256 d1e8539a249a7dddb7af787d4050692d1d0fc089111bf7d77f8062926fc207c6

See more details on using hashes here.

File details

Details for the file combin-0.1.5-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for combin-0.1.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 94381cd7a25158fb3dd589810153c7d61dd94b6d0a8b45837444b3f921fdf4fd
MD5 17d61bb721890b86d746484eae5e0cc0
BLAKE2b-256 6934e09133537a00e2d642c2299b8c3d450467addb7b0d529280c1b76f09ebb6

See more details on using hashes here.

File details

Details for the file combin-0.1.5-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for combin-0.1.5-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e7a7ef1b4808786cf55344182a31d1f16a5bfb94fbcfec1596b8a4cc0edca3ac
MD5 a61c458b03dfde230ce908d414404ad2
BLAKE2b-256 ebcc23a88fba9b5943a1fa048064ff399bd53a82d49e82c98fd34751fcc220ed

See more details on using hashes here.

File details

Details for the file combin-0.1.5-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: combin-0.1.5-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 117.9 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for combin-0.1.5-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 a547ab615a032d625160ceb5f979046bdd77dc77de347cbfd4c62820dd150815
MD5 031b9018e4f253c8ad2a66bbb448de11
BLAKE2b-256 1e798c199cff3eeaaedda8d91c3130a3617ea8fb292e968d784f7b92d2590e81

See more details on using hashes here.

File details

Details for the file combin-0.1.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for combin-0.1.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9a8cc79d48de9081eaf86e0c9d9acf01e6fc087db6e801a7bd172ae043cc6645
MD5 549b3d8b84bfcc785b9df373d91ac85c
BLAKE2b-256 394199e614dee43785fc517d8a765334394890aabd15f24100d94e6eaad2e238

See more details on using hashes here.

File details

Details for the file combin-0.1.5-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for combin-0.1.5-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 228569ac61cd32f7f889f76b6d9bcadb66cd364b49197637a10ff3c2aaf19ce9
MD5 a95e4ccb624121349d3c8d8009fb243e
BLAKE2b-256 ae4c8fef3367f0fc12862fe61396b7bf132b68438a504eca5cd6cb3069552962

See more details on using hashes here.

File details

Details for the file combin-0.1.5-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for combin-0.1.5-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a888feb2fc1818420cbcb0f431178a7c86b10ca7dae6c932c515ae55df99dac2
MD5 a49e349257ae8ace3a6b50569b97666d
BLAKE2b-256 71f1b1d20ded2323a3667d1f88762338b6a041fb85e32e4cfccbd3a01cd00b74

See more details on using hashes here.

Supported by

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