{"id":14989287,"url":"https://github.com/coady/spector","last_synced_at":"2025-04-12T00:32:01.644Z","repository":{"id":33745319,"uuid":"139777884","full_name":"coady/spector","owner":"coady","description":"Sparse vectors.","archived":false,"fork":false,"pushed_at":"2025-03-04T01:47:15.000Z","size":704,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T20:51:12.657Z","etag":null,"topics":["numpy-arrays","scipy","sparse-matrix","sparse-vectors"],"latest_commit_sha":null,"homepage":"https://coady.github.io/spector","language":"Cython","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coady.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-05T00:55:24.000Z","updated_at":"2025-03-04T01:46:27.000Z","dependencies_parsed_at":"2023-02-12T20:46:22.789Z","dependency_job_id":"a67ffeef-9894-4c5e-8faf-2165ce0dc783","html_url":"https://github.com/coady/spector","commit_stats":{"total_commits":158,"total_committers":2,"mean_commits":79.0,"dds":"0.22784810126582278","last_synced_commit":"0723f56fa8dfaa37ddbb562203575a8886416fb1"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coady%2Fspector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coady%2Fspector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coady%2Fspector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coady%2Fspector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coady","download_url":"https://codeload.github.com/coady/spector/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248501407,"owners_count":21114674,"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":["numpy-arrays","scipy","sparse-matrix","sparse-vectors"],"created_at":"2024-09-24T14:17:59.680Z","updated_at":"2025-04-12T00:32:01.375Z","avatar_url":"https://github.com/coady.png","language":"Cython","readme":"[![image](https://img.shields.io/pypi/v/spector.svg)](https://pypi.org/project/spector/)\n[![image](https://img.shields.io/pypi/pyversions/spector.svg)](https://python3statement.org)\n[![image](https://pepy.tech/badge/spector)](https://pepy.tech/project/spector)\n![image](https://img.shields.io/pypi/status/spector.svg)\n[![build](https://github.com/coady/spector/actions/workflows/build.yml/badge.svg)](https://github.com/coady/spector/actions/workflows/build.yml)\n[![image](https://codecov.io/gh/coady/spector/branch/main/graph/badge.svg)](https://codecov.io/gh/coady/spector/)\n[![CodeQL](https://github.com/coady/spector/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/coady/spector/actions/workflows/github-code-scanning/codeql)\n[![CodSpeed Badge](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/coady/spector)\n[![image](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![image](https://mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)\n\nSparse vectors optimized for memory and [NumPy](https://www.numpy.org) integrations.\n\n`numpy` handles densely populated n-dimemsional arrays. `scipy.sparse` handles sparsely populated 2-dimensional arrays, i.e., matrices. What's missing from the ecosystem is sparsely populated 1-dimensional arrays, i.e., vectors.\n\nNumPy | Python | Spector\n----- | ------ | -------\n1-dim bool `numpy.array` | `set[int]` | `spector.indices`\n1-dim float `numpy.array` | `dict[int, float]` | `spector.vector`\n`scipy.sparse.dok_matrix` | `dict[int, dict[int, float]]` | `spector.matrix`\n\nIndices and vectors are implemented in [Cython](https://cython.org) as hash sets and maps. All native operations are optimized and release the [GIL](https://docs.python.org/3/glossary.html#term-global-interpreter-lock).\n\n* conversion between sparse `numpy` arrays\n* conversion between dense `numpy` arrays\n* binary set operations\n* binary math operations\n* `map`, `filter`, and `reduce` operations with `numpy` universal functions\n\n## Usage\n### indices\nA sparse boolean array with a set interface.\n\n```python\n\u003e\u003e\u003e from spector import indices\n\u003e\u003e\u003e ind = indices([0, 2])\n\u003e\u003e\u003e ind\nindices([2 0])\n\u003e\u003e\u003e 1 in ind\nFalse\n\u003e\u003e\u003e ind.add(1)\nTrue\n\u003e\u003e\u003e ind.todense()\narray([ True,  True,  True])\n\u003e\u003e\u003e ind.fromdense(_)\nindices([2 1 0])\n```\n\n### vector\nA sparse float array with a mapping interface.\n\n```python\n\u003e\u003e\u003e from spector import vector\n\u003e\u003e\u003e vec = vector({0: 1.0, 2: 2.0, 4: 1.0})\n\u003e\u003e\u003e vec\nvector([4 2 0], [1. 2. 1.])\n\u003e\u003e\u003e vec[2] += 1.0\n\u003e\u003e\u003e vec[2]\n3.0\n\u003e\u003e\u003e vec.todense()\narray([1., 0., 3., 0., 1.])\n\u003e\u003e\u003e vector.fromdense(_)\nvector([4 2 0], [1. 3. 1.])\n\u003e\u003e\u003e vec.sum()\n5.0\n\u003e\u003e\u003e vec + vec\nvector([0 2 4], [2. 6. 2.])\n```\n\nVectors support math operations with scalars, and with vectors if the set method is unambiguous.\n\nvector operation | set method | ufunc\n---------------- | ---------- | -----\n`+` | union | add\n`*` | intersection | multiply\n`-` | | subtract\n`/` | | true_divide\n`**` | | power\n`\\|` | union | max\n`\u0026` | intersection | min\n`^` | symmetric_difference |\n`difference` | difference |\n\n### matrix\nA mapping of keys to vectors.\n\n```python\n\u003e\u003e\u003e from spector import matrix\n\u003e\u003e\u003e mat = matrix({0: {1: 2.0}})\n\u003e\u003e\u003e mat\nmatrix(\u003cclass 'spector.vector.vector'\u003e, {0: vector([1], [2.])})\n\u003e\u003e\u003e mat.row, mat.col, mat.data\n(array([0]), array([1]), array([2.]))\n```\n\n## Installation\n```console\n% pip install spector\n```\n\n## Tests\n100% branch coverage.\n\n```console\n% pytest [--cov]\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoady%2Fspector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoady%2Fspector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoady%2Fspector/lists"}