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.6.tar.gz (63.4 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.6-cp311-cp311-win_amd64.whl (120.7 kB view details)

Uploaded CPython 3.11Windows x86-64

combin-0.1.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (159.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

combin-0.1.6-cp311-cp311-macosx_11_0_arm64.whl (116.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

combin-0.1.6-cp311-cp311-macosx_10_9_x86_64.whl (122.3 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

combin-0.1.6-cp310-cp310-win_amd64.whl (118.4 kB view details)

Uploaded CPython 3.10Windows x86-64

combin-0.1.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (157.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

combin-0.1.6-cp310-cp310-macosx_11_0_arm64.whl (115.2 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

combin-0.1.6-cp310-cp310-macosx_10_9_x86_64.whl (120.8 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

combin-0.1.6-cp39-cp39-win_amd64.whl (118.4 kB view details)

Uploaded CPython 3.9Windows x86-64

combin-0.1.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (159.7 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

combin-0.1.6-cp39-cp39-macosx_11_0_arm64.whl (115.3 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

combin-0.1.6-cp39-cp39-macosx_10_9_x86_64.whl (120.8 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

combin-0.1.6-cp38-cp38-win_amd64.whl (118.3 kB view details)

Uploaded CPython 3.8Windows x86-64

combin-0.1.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (158.9 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

combin-0.1.6-cp38-cp38-macosx_11_0_arm64.whl (115.2 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

combin-0.1.6-cp38-cp38-macosx_10_9_x86_64.whl (120.8 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

File details

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

File metadata

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

File hashes

Hashes for combin-0.1.6.tar.gz
Algorithm Hash digest
SHA256 0cce0e05dada5f7a5146e0b84b70e26c4e30f342cd814c89c476f89c7dd01008
MD5 afe4bd354d9be68399d2622adafc9cc3
BLAKE2b-256 bec44c7ae77bd07b94e72e8292c6b5acc673eb403f99974d1cbb595ee7addd44

See more details on using hashes here.

File details

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

File metadata

  • Download URL: combin-0.1.6-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 120.7 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for combin-0.1.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6f92a3d81aecb54c29640b96257747ea83aeeb697bb370cb7505b75296d4498b
MD5 98df22bc128d81974ac110eb318f089c
BLAKE2b-256 fd3a060ce1af7970672316061b0159353a647d50ee4c347ab7db10b83e486292

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for combin-0.1.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 703e2d2abd659cc12b7eb64680a51435fa4eee722afc72b8d9467e2e9b289329
MD5 145d68488d53e655a486440c6fae6c34
BLAKE2b-256 80383b9fd7864d5f3080f1ca00086e7cf90fbea869e749ddd9f76a72426c168a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for combin-0.1.6-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bfb7826703d6ceb7b502b889e8aa1741cf63e9f57741a538ad4fe51e9016762f
MD5 ebcdad43805d4ed6a734e3cc436e5e90
BLAKE2b-256 c15e108b65a8d86f139e4ff7770f0a9aec851d29f0dabd5afa0abc51d08fecd7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for combin-0.1.6-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cc8321b5fc6e9623f3efcedb3b36b623688cee90fbad675a039f7505c8048554
MD5 4b2df9950fbd902c234cc4199412e3c7
BLAKE2b-256 02762d27a95e92bb7285f6352b28bc991d6e86546b6fe0667d9fd70562c41f70

See more details on using hashes here.

File details

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

File metadata

  • Download URL: combin-0.1.6-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 118.4 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for combin-0.1.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 5ca414e4d21a4a970c2e823d3c5a35f10a27abf5ae7979c5d4b6f28082f631c1
MD5 0d44aa45271785936dbcdcd95250c7fb
BLAKE2b-256 7d4a8b205b2f28aa62a98943f6d25890176700566688f5d0c6941740add84ec2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for combin-0.1.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bfd04c5322567c512a2e1021f34a6888fd0f9ba947f8cec593424b8dac5c1244
MD5 f26448a832fa44464d8003acf56462a5
BLAKE2b-256 ee069fb45a9ba6b26adb10a0ba61945e4b6c9f2471c37679cc5d3e2a47e95f53

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for combin-0.1.6-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c3584839223789838cba8b38828d4338daaf6ec3ebdb1ff2f877ff298d6abb6f
MD5 ff8cbec5cc3c957772cd849d35cb9627
BLAKE2b-256 5212ae6b08150789b6d428ce419bba683be456abad03017e26b3bd88529af386

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for combin-0.1.6-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e7ad6055b1ef2cb14a9dcbb15a7ef4bbd798877257033241daa0c5f65841bb39
MD5 a32f9c813e3257a3d487bcb652956fbf
BLAKE2b-256 257c191e177982a992cfa76675d9c6ff0749530a047339c9a8788e8c4cda925c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: combin-0.1.6-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 118.4 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for combin-0.1.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 935957963a800b221cf3f38fd7551d39ddc8f436e740fa17b255d55d7fe8b42f
MD5 f5a5cf7a967e8029e8926132d045fdd3
BLAKE2b-256 1c569725103ac7a12330b6ad8e55b0aa00e11b6b555be9aa8391c60b95d83869

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for combin-0.1.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 15c18557c696354c2a6daaea3afcf7465f343a65459794cadfe183520c04fa38
MD5 98d4f178a0df580c82d6c0689dc1b3e2
BLAKE2b-256 28d9aad3b12e420af64233831cc1df00b41d9178a6638929bf71dd6eda4c0bfb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for combin-0.1.6-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7e32565f52889f28784286c76e757888e6bfeb242a2fc33303d29eab15cde604
MD5 25f48ebde6ae914bc584b2b5f91c4d61
BLAKE2b-256 15778cf0c3a28bc886e8c4fec27684b7886ec9397954d7c465b08280fdac3ead

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for combin-0.1.6-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 351811e8c8d529e28f4dff3909eee4c71e6f65d6a381bf5d0a24c971c330a67a
MD5 d69ff6b8a7226e639382c66c701c6d9b
BLAKE2b-256 8fbb0310aabe4113b8d29acc82571600a19f85ca48bd326f9c5e17b925926df3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: combin-0.1.6-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 118.3 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for combin-0.1.6-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 e8420598c9fe47e2fb3804d2ff96350f9ac23bb4b7f6dce399cef7ec4da85cf9
MD5 d0afaa4db1219a8ee198e0ee82a28660
BLAKE2b-256 bb1b20c26a068b938d57c4383c36558041d3862e624a2b1f45e7dbbb6554fb40

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for combin-0.1.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f884a8a6ecb8602d26abe458045256c53a91c77f216cc6c55cd92fde5293f80b
MD5 dfda84db17ad4457f8008f3ad66dbb78
BLAKE2b-256 8181e05e065afb1cf35f6fec2d46560a121faef9f43e5a8c859e016beafa4f1a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for combin-0.1.6-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b23f7e57dedff4b9b93c6bf24f39429b2706c472557162baafb8e726fae04d02
MD5 95cf245eecf175913c5c23818b718fd3
BLAKE2b-256 329824a938b04ac364704bb7515a925ef6ff1c0cd1bbeb35a22f0993640d217e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for combin-0.1.6-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 08a59748772b0e53b50b027c2f953a00c680777a0200adc668ebb11f36105b09
MD5 69ca032322aa7b55ba764d62073676ae
BLAKE2b-256 cc826ea3d3620f89002883dd2929393d3097a974cca49085b71c12bab3159167

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