{"id":26748385,"url":"https://github.com/trungnt13/bigarray","last_synced_at":"2025-04-14T22:14:45.415Z","repository":{"id":57414954,"uuid":"213598899","full_name":"trungnt13/bigarray","owner":"trungnt13","description":"Fast and scalable numpy array using Memory-mapped I/O","archived":false,"fork":false,"pushed_at":"2019-10-16T11:38:33.000Z","size":32,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T22:14:41.435Z","etag":null,"topics":["big-data","machine-learning","parrallel-computing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trungnt13.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-08T09:16:30.000Z","updated_at":"2020-04-27T16:16:01.000Z","dependencies_parsed_at":"2022-08-30T07:00:35.636Z","dependency_job_id":null,"html_url":"https://github.com/trungnt13/bigarray","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trungnt13%2Fbigarray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trungnt13%2Fbigarray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trungnt13%2Fbigarray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trungnt13%2Fbigarray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trungnt13","download_url":"https://codeload.github.com/trungnt13/bigarray/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248968917,"owners_count":21191162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["big-data","machine-learning","parrallel-computing"],"created_at":"2025-03-28T10:17:39.877Z","updated_at":"2025-04-14T22:14:45.394Z","avatar_url":"https://github.com/trungnt13.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bigarray\nFast and scalable numpy array using Memory-mapped I/O\n\nStable build:\n\u003e pip install bigarray\n\nNightly build from github:\n\u003e pip install git+https://github.com/trungnt13/bigarray@master\n\n---\n## The three principles\n\n* **Transparency**: everything is `numpy.array`, metadata and support for extra features (e.g. multiprocessing, indexing, etc) are subtly implemented in the _background_.\n* **Pragmatism**: fast but easy, simplified A.P.I for common use cases\n* **Focus**: _\"Do one thing and do it well\"_\n\n## The benchmarks\n\nAbout **535 times faster** than HDF5 data (using `h5py`) and **223 times faster** than normal `numpy.array`\n[The detail benchmark code](https://github.com/trungnt13/bigarray/blob/master/benchmarks/mmap_vs_hdf5.py)\n```\nArray size: 1220.70 (MB)\n\nCreate HDF5   in: 0.0005580571014434099 s\nCreate Memmap in: 0.000615391880273819 s\n\nNumpy save in: 0.5713834380730987 s\nWriting data to HDF5  : 0.5530977640300989 s\nWriting data to Memmap: 0.7038380969315767 s\n\nNumpy saved size: 1220.70 (MB)\nHDF5 saved size: 1220.71 (MB)\nMmap saved size: 1220.70 (MB)\n\nLoad Numpy array: 0.3723734531085938 s\nLoad HDF5 data  : 0.00041177100501954556 s\nLoad Memmap data: 0.00017150305211544037 s\n\nTest correctness of stored data\nNumpy : True\nHDF5  : True\nMemmap: True\n\nIterate Numpy data   : 0.00020254682749509811 s\nIterate HDF5 data    : 0.8945782391820103 s\nIterate Memmap data  : 0.0014937107916921377 s\nIterate Memmap (2nd) : 0.0011746759992092848 s\n\nNumpy total time (open+iter): 0.3725759999360889 s\nH5py  total time (open+iter): 0.8949900101870298 s\n**Mmap  total time (open+iter): 0.001665213843807578 s**\n```\n\n## Example\n\n```python\nfrom multiprocessing import Pool\n\nimport numpy as np\n\nfrom bigarray import PointerArray, PointerArrayWriter\n\nn = 80 * 10  # total number of samples\njobs = [(i, i + 10) for i in range(0, n // 10, 10)]\npath = '/tmp/array'\n\n# ====== Multiprocessing writing ====== #\nwriter = PointerArrayWriter(path, shape=(n,), dtype='int32', remove_exist=True)\n\n\ndef fn_write(job):\n  start, end = job\n  # it is crucial to write at different position for different process\n  writer.write(\n      {\"name%i\" % i: np.arange(i * 10, i * 10 + 10) for i in range(start, end)},\n      start_position=start * 10)\n\n\n# using 2 processes to generate and write data\nwith Pool(2) as p:\n  p.map(fn_write, jobs)\nwriter.flush()\nwriter.close()\n\n# ====== Multiprocessing reading ====== #\nx = PointerArray(path)\nprint(x['name0'])\nprint(x['name66'])\nprint(x['name78'])\n\n# normal indexing\nfor name, (s, e) in x.indices.items():\n  data = x[s:e]\n# fast indexing\nfor name in x.indices:\n  data = x[name]\n\n\n# multiprocess indexing\ndef fn_read(job):\n  start, end = job\n  total = 0\n  for i in range(start, end):\n    total += np.sum(x['name%d' % i])\n  return total\n\n# use multiprocessing to calculate the sum of all arrays\nwith Pool(2) as p:\n  total_sum = sum(p.map(fn_read, jobs))\nprint(np.sum(x), total_sum)\n```\n\nOutput:\n```\n[0 1 2 3 4 5 6 7 8 9]\n[660 661 662 663 664 665 666 667 668 669]\n[780 781 782 783 784 785 786 787 788 789]\n319600 319600\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrungnt13%2Fbigarray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrungnt13%2Fbigarray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrungnt13%2Fbigarray/lists"}