cythoncartesian


Namecythoncartesian JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/cythoncartesian
SummaryCartesian Product - 6x faster than itertools.product - 10x less memory
upload_time2023-12-03 12:06:41
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords cython cartesian product itertools
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Cartesian Product - 6x faster than itertools.product - 10x less memory

## pip install cythoncartesian

### Tested against Windows / Python 3.11 / Anaconda


## Cython (and a C/C++ compiler) must be installed



```python
Generate the Cartesian product of input iterables.

Parameters:
-----------
*args : list of iterable
	Input iterables for which the Cartesian product will be computed.
outputdtype (optional) :
	dtype of output array
Returns:
--------
numpy.ndarray
	2D array containing the Cartesian product of the input iterables.

Notes:
------
This function efficiently computes the Cartesian product of the input iterables
using Cython implementation. It outperforms the equivalent functionality provided
by itertools.product, and returns a NumPy array (not a list of tuples like itertools.product).

Examples:
---------
	from cythoncartesian import cartesian_product

	# Mem usage 2 GB
	# Out[4]:
	# array([[0, 0, 0, ..., 0, 0, 0],
	#        [1, 0, 0, ..., 0, 0, 0],
	#        [2, 0, 0, ..., 0, 0, 0],
	#        ...,
	#        [5, 7, 7, ..., 7, 7, 7],
	#        [6, 7, 7, ..., 7, 7, 7],
	#        [7, 7, 7, ..., 7, 7, 7]], dtype=uint8)
	# %timeit dataresults=cartesian_product(*args2)
	# 2.65 s ± 163 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
	# dataresults.shape
	# Out[6]: (134217728, 9)
	

	# itertools.product
	# Mem usage 16 GB

	# import itertools
	# %timeit (list(itertools.product(*args2)))
	# 11.5 s ± 203 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)


	# --------------------------------------------------------------------------
	# Mem usage 1.2 GB
	# args = [[411, 231.33, 4342, 12341, 1.142, 1.33, 13],
	#         [34, 231.33, 4132, 1231],
	#          [14, 44, 23454.1, .1, 23, 1],
	#          [9, 12, 1, 3, 32, 23, 21, 31],
	#          [1114, 44, 23454.1, .1, 23, 1],
	#         ]+[list(range(6)),list(range(3)),list(range(3)),list(range(3))
	#     ,list(range(3))]+[list(range(6))]
	# %timeit dataresults=cartesian_product(*args)
	# 621 ms ± 46.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)


	# Mem usage 4 GB
	# import itertools
	# %timeit (list(itertools.product(*args)))
	# 2.13 s ± 26.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/cythoncartesian",
    "name": "cythoncartesian",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "cython,cartesian,product,itertools",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/78/42/782d5e070bfda0f794119cea8a38acfd958159492c9e6e55581ab8474054/cythoncartesian-0.10.tar.gz",
    "platform": null,
    "description": "\r\n# Cartesian Product - 6x faster than itertools.product - 10x less memory\r\n\r\n## pip install cythoncartesian\r\n\r\n### Tested against Windows / Python 3.11 / Anaconda\r\n\r\n\r\n## Cython (and a C/C++ compiler) must be installed\r\n\r\n\r\n\r\n```python\r\nGenerate the Cartesian product of input iterables.\r\n\r\nParameters:\r\n-----------\r\n*args : list of iterable\r\n\tInput iterables for which the Cartesian product will be computed.\r\noutputdtype (optional) :\r\n\tdtype of output array\r\nReturns:\r\n--------\r\nnumpy.ndarray\r\n\t2D array containing the Cartesian product of the input iterables.\r\n\r\nNotes:\r\n------\r\nThis function efficiently computes the Cartesian product of the input iterables\r\nusing Cython implementation. It outperforms the equivalent functionality provided\r\nby itertools.product, and returns a NumPy array (not a list of tuples like itertools.product).\r\n\r\nExamples:\r\n---------\r\n\tfrom cythoncartesian import cartesian_product\r\n\r\n\t# Mem usage 2 GB\r\n\t# Out[4]:\r\n\t# array([[0, 0, 0, ..., 0, 0, 0],\r\n\t#        [1, 0, 0, ..., 0, 0, 0],\r\n\t#        [2, 0, 0, ..., 0, 0, 0],\r\n\t#        ...,\r\n\t#        [5, 7, 7, ..., 7, 7, 7],\r\n\t#        [6, 7, 7, ..., 7, 7, 7],\r\n\t#        [7, 7, 7, ..., 7, 7, 7]], dtype=uint8)\r\n\t# %timeit dataresults=cartesian_product(*args2)\r\n\t# 2.65 s \u00b1 163 ms per loop (mean \u00b1 std. dev. of 7 runs, 1 loop each)\r\n\t# dataresults.shape\r\n\t# Out[6]: (134217728, 9)\r\n\t\r\n\r\n\t# itertools.product\r\n\t# Mem usage 16 GB\r\n\r\n\t# import itertools\r\n\t# %timeit (list(itertools.product(*args2)))\r\n\t# 11.5 s \u00b1 203 ms per loop (mean \u00b1 std. dev. of 7 runs, 1 loop each)\r\n\r\n\r\n\t# --------------------------------------------------------------------------\r\n\t# Mem usage 1.2 GB\r\n\t# args = [[411, 231.33, 4342, 12341, 1.142, 1.33, 13],\r\n\t#         [34, 231.33, 4132, 1231],\r\n\t#          [14, 44, 23454.1, .1, 23, 1],\r\n\t#          [9, 12, 1, 3, 32, 23, 21, 31],\r\n\t#          [1114, 44, 23454.1, .1, 23, 1],\r\n\t#         ]+[list(range(6)),list(range(3)),list(range(3)),list(range(3))\r\n\t#     ,list(range(3))]+[list(range(6))]\r\n\t# %timeit dataresults=cartesian_product(*args)\r\n\t# 621 ms \u00b1 46.9 ms per loop (mean \u00b1 std. dev. of 7 runs, 1 loop each)\r\n\r\n\r\n\t# Mem usage 4 GB\r\n\t# import itertools\r\n\t# %timeit (list(itertools.product(*args)))\r\n\t# 2.13 s \u00b1 26.4 ms per loop (mean \u00b1 std. dev. of 7 runs, 1 loop each)\r\n\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Cartesian Product - 6x faster than itertools.product - 10x less memory",
    "version": "0.10",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/cythoncartesian"
    },
    "split_keywords": [
        "cython",
        "cartesian",
        "product",
        "itertools"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "558aed3cd7ea10f730ef12c399a06d16030efd5a2edfed248b1875f05ecb29cc",
                "md5": "38d43fa124e36dedbb389f201c3a1e75",
                "sha256": "ccd52023cadcb2e6bfcaa189ba7a5275c9626acdcd6a372718178736c51f4e9a"
            },
            "downloads": -1,
            "filename": "cythoncartesian-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "38d43fa124e36dedbb389f201c3a1e75",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 23867,
            "upload_time": "2023-12-03T12:06:39",
            "upload_time_iso_8601": "2023-12-03T12:06:39.564882Z",
            "url": "https://files.pythonhosted.org/packages/55/8a/ed3cd7ea10f730ef12c399a06d16030efd5a2edfed248b1875f05ecb29cc/cythoncartesian-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7842782d5e070bfda0f794119cea8a38acfd958159492c9e6e55581ab8474054",
                "md5": "7f8c4bbf02db72688452cdb5c2f301fd",
                "sha256": "6cf181dcad42059ca13b615762c9981a1ed3a4cc6eebe25263bd92e4402430d0"
            },
            "downloads": -1,
            "filename": "cythoncartesian-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "7f8c4bbf02db72688452cdb5c2f301fd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 23487,
            "upload_time": "2023-12-03T12:06:41",
            "upload_time_iso_8601": "2023-12-03T12:06:41.643463Z",
            "url": "https://files.pythonhosted.org/packages/78/42/782d5e070bfda0f794119cea8a38acfd958159492c9e6e55581ab8474054/cythoncartesian-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-03 12:06:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "cythoncartesian",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "cythoncartesian"
}
        
Elapsed time: 0.15343s