{"id":47231389,"url":"https://github.com/openfheorg/openfhe-numpy","last_synced_at":"2026-03-13T20:27:36.292Z","repository":{"id":269474459,"uuid":"897562455","full_name":"openfheorg/openfhe-numpy","owner":"openfheorg","description":"Numpy-like encrypted matrix arithmetic library based on OpenFHE","archived":false,"fork":false,"pushed_at":"2026-03-12T16:44:36.000Z","size":15087,"stargazers_count":29,"open_issues_count":6,"forks_count":8,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-12T22:50:55.982Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openfheorg.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-12-02T21:01:26.000Z","updated_at":"2026-03-12T19:18:20.000Z","dependencies_parsed_at":"2025-02-21T19:24:07.840Z","dependency_job_id":"c554b561-5988-45ff-b2d4-167a0ef21ca6","html_url":"https://github.com/openfheorg/openfhe-numpy","commit_stats":null,"previous_names":["openfheorg/openfhe-matrix","openfheorg/openfhe-numpy"],"tags_count":38,"template":false,"template_full_name":null,"purl":"pkg:github/openfheorg/openfhe-numpy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openfheorg%2Fopenfhe-numpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openfheorg%2Fopenfhe-numpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openfheorg%2Fopenfhe-numpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openfheorg%2Fopenfhe-numpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openfheorg","download_url":"https://codeload.github.com/openfheorg/openfhe-numpy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openfheorg%2Fopenfhe-numpy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30474875,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-13T17:15:31.527Z","status":"ssl_error","status_checked_at":"2026-03-13T17:15:22.394Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2026-03-13T20:27:35.626Z","updated_at":"2026-03-13T20:27:36.280Z","avatar_url":"https://github.com/openfheorg.png","language":"Python","funding_links":[],"categories":["Products, Frameworks, and Toolchains using OpenFHE"],"sub_categories":[],"readme":"# OpenFHE-NumPy\n\n[![License](https://img.shields.io/badge/License-BSD%202--Clause-blue.svg)](https://opensource.org/licenses/BSD-2-Clause)\n[![Python Versions](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/)\n[![OpenFHE Version](https://img.shields.io/badge/OpenFHE-1.4.2%2B-green)](https://github.com/openfheorg/openfhe-development)\n\nOpenFHE-NumPy is a NumPy-like API for homomorphic encryption operations, built on top of OpenFHE. This library enables data scientists and machine learning practitioners to perform computations on encrypted data using familiar NumPy syntax.\n\n## Table of Contents\n- [OpenFHE-NumPy](#openfhe-numpy)\n  - [Table of Contents](#table-of-contents)\n  - [Project Structure](#project-structure)\n  - [Installation](#installation)\n    - [Prerequisites](#prerequisites)\n    - [Installing from Source](#installing-from-source)\n    - [Installing using pip (for Ubuntu)](#installing-using-pip-for-ubuntu)\n  - [Running Tests](#running-tests)\n  - [Code Examples](#code-examples)\n  - [Available Operations](#available-operations)\n  - [Current Limitations](#current-limitations)\n  - [Documentation](#documentation)\n  - [Examples](#examples)\n  - [Contributing](#contributing)\n  - [License](#license)\n\n## Project Structure\n\nOpenFHE-NumPy is organized as a hybrid C++/Python project with the following structure:\n\n```\nopenfhe-numpy/\n├── config/              # Configuration files\n├── docs/                # Documentation\n├── examples/            # Python examples\n├── openfhe_numpy/       # Main Python package\n│   ├── cpp/             # C++ implementation\n│   ├── operations/      # Matrix operations\n│   ├── tensor/          # Tensor implementations\n│   └── utils/           # Utility functions\n├── tests/               # Test suite\n└── CMakeLists.txt       # Build configuration\n```\n\n## Installation\n\n### Prerequisites\n\n- **C++ compiler**: Supporting C++17 standard\n- **CMake**: Version 3.16 or newer\n- **Python**: Version 3.10 or newer\n- **NumPy**: Any version\n- **OpenFHE**: Any version\n- **OpenFHE Python**: Any version\n\n### Installing from Source\nBefore building, make sure you have the following dependencies installed:\n- [OpenFHE 1.4.2+](https://github.com/openfheorg/openfhe-development) by following the instructions in [OpenFHE Documentation](https://openfhe-development.readthedocs.io/en/latest/sphinx_rsts/intro/installation/installation.html)\n- [OpenFHE Python Bindings](https://github.com/openfheorg/openfhe-python) by following the instructions in [OpenFHE Python Documentation](https://openfheorg.github.io/openfhe-python/html/index.html)\n\nWe recommend following OpenFHE C++ and OpenFHE Python installation instructions first (which covers Linux, Windows and MacOS) and then getting back to this repo. If the some package cannot be found when running a Python example (occurs only for some environments), check the `PYTHONPATH` (OpenFHE Python) environment variable and the `LD_LIBRARY_PATH` (OpenFHE libraries). This ensures that the packages can be correctly located and imported.\n\n```bash\n# Clone the repository\ngit clone https://github.com/openfheorg/openfhe-numpy.git\ncd openfhe-numpy\n\n# Create build directory\nmkdir build \u0026\u0026 cd build\n\n# Configure with CMake\ncmake ..\n\n# Build the package\nmake\n\n# Install\nsudo make install\n```\n\n### Installing using pip (for Ubuntu)\n\n\nOn Ubuntu, openfhe_numpy can be installed using pip.  All available releases are listed at [Python Package Index OpenFHE-Numpy Release History](https://pypi.org/project/openfhe_numpy/#history). Find the release for your version of Ubuntu and run\n\n```\npip install openfhe_numpy==\u003copenfhe_package_version\u003e\n```\n\nOnce installed, any python example at https://github.com/openfheorg/openfhe-numpy/tree/main/examples/python can be executed.\n\nNote that Ubuntu LTS 22.04 and 24.04 are currently supported. `pip uninstall` can be used to uninstall the openfhe package.\n\n\n## Running Tests\nRun tests with [unittest](https://docs.python.org/3/library/unittest.html). See the [testing readme](tests/README.md) for detailed instuctions.\n\n## Code Examples\n\n```python\nimport numpy as np\nimport openfhe_numpy as onp\nfrom openfhe import *\n\n# Initialize CKKS context\nparams = CCParamsCKKSRNS()\nparams.SetMultiplicativeDepth(7)\nparams.SetScalingModSize(59)\nparams.SetFirstModSize(60)\nparams.SetScalingTechnique(FIXEDAUTO)\nparams.SetSecretKeyDist(UNIFORM_TERNARY)\n\ncc = GenCryptoContext(params)\ncc.Enable(PKESchemeFeature.PKE)\ncc.Enable(PKESchemeFeature.LEVELEDSHE)\ncc.Enable(PKESchemeFeature.ADVANCEDSHE)\n\n# Generate keys\nkeys = cc.KeyGen()\ncc.EvalMultKeyGen(keys.secretKey)\ncc.EvalSumKeyGen(keys.secretKey)\n\n# Create matrix and encrypt it\nA = np.array([[1, 2], [3, 4]])\n\nring_dim = cc.GetRingDimension()\ntotal_slots = ring_dim // 2\n\n# Encrypt with OpenFHE-NumPy\ntensor_A = onp.array(\n        cc=cc,\n        data=A,\n        batch_size=batch_size,\n        order=onp.ROW_MAJOR,\n        fhe_type=\"C\",\n        mode=\"zero\",\n        public_key=keys.publicKey,\n    )\n\n\n# Generate keys\nonp.EvalSquareMatMultRotateKeyGen(keys.secretKey, tensor_A.ncols)\n\n# Perform encrypted operations\ntensor_product = tensor_A @ tensor_A  # Matrix multiplication\ntensor_sum = onp.add(tensor_A, tensor_A)  # Element-wise addition\n\n# Decrypt results\ndecrypted_product = tensor_product.decrypt(keys.secretKey, unpack_type=\"original\")\ndecrypted_sum = tensor_sum.decrypt(keys.secretKey, unpack_type=\"original\")\n\nprint(\"Result of A @ A:\")\nprint(decrypted_product)\n\nprint(\"Result of A + A:\")\nprint(decrypted_sum)\n```\n\n## Available Operations\n\nOpenFHE-NumPy currently supports the following operations:\n\n| Operation   | Description                 | Example                         |\n| ----------- | --------------------------- | ------------------------------- |\n| `add`       | Element-wise addition       | `onp.add(a, b)` or `a + b`      |\n| `subtract`  | Element-wise subtraction    | `onp.subtract(a, b)` or `a - b` |\n| `multiply`  | Element-wise multiplication | `onp.multiply(a, b)` or `a * b` |\n| `matmul`    | Matrix multiplication       | `onp.matmul(a, b)` or `a @ b`   |\n| `transpose` | Matrix transposition        | `onp.transpose(a)`              |\n| `cumulative_sum`    | Cumulative sum along axis   | `onp.cumulative_sum(a, axis)`           |\n| `power`     | Element-wise power          | `onp.power(a, exp)`             |\n| `dot`       | Dot product                 | `onp.dot(a, b)`                 |\n| `sum`       | Sum along axis              | `onp.sum(a, axis)`              |\n\n## Current Limitations\nIn the current version, the OpenFHE-NumPy package supports operations on single-ciphertext vectors/matrices, where each encrypted array variable (which has type CTArray or PTArray) contains only a single encoding vector.\n\nFor example, we can consider a matrix:\n```\n1 2 3\n4 5 6\n7 8 9\n```\nAs an encoding vector of the form: ```1 2 3 0 4 5 6 0 7 8 9 0```\n\nThe size of the encoded vector must be smaller than the number of available plaintext slots. Certain operations, such as matrix–vector multiplication, may require the ciphertext vector to be duplicated. In such cases, users should ensure that a sufficient number of slots are available for the function to execute correctly.\nWe plan to release a future version with support for block ciphertexts, which will remove this limitation in the future.\n\n## Documentation\n\nFor detailed documentation on the API, please visit our [documentation site](https://openfheorg.github.io/openfhe-numpy/html/index.html).\n\n## Examples\n\nWe provide several examples showcasing the library's functionality:\n\n- [1D Convolution](https://github.com/openfheorg/openfhe-numpy/blob/main/examples/python/simple_convolution.py)\n- [Matrix Accumulation](https://github.com/openfheorg/openfhe-numpy/blob/main/examples/python/simple_matrix_accumulation.py)\n- [Matrix Addition](https://github.com/openfheorg/openfhe-numpy/blob/main/examples/python/simple_matrix_addition.py)\n- [Matrix Summation](https://github.com/openfheorg/openfhe-numpy/blob/main/examples/python/simple_matrix_sum.py)\n- [Matrix Transpostion](https://github.com/openfheorg/openfhe-numpy/blob/main/examples/python/simple_matrix_transpose.py)\n- [Matrix-Vector Multiplication](https://github.com/openfheorg/openfhe-numpy/blob/main/examples/python/simple_matrix_vector_product.py)\n- [Square Matrix Multiplication](https://github.com/openfheorg/openfhe-numpy/blob/main/examples/python/simple_square_matrix_product.py)\n- [Vector Operations](https://github.com/openfheorg/openfhe-numpy/blob/main/examples/python/simple_vector_operations.py)\n\n\n## Contributing\n[OpenFHE Development - Contributing Guide](https://openfhe-development.readthedocs.io/en/latest/sphinx_rsts/contributing/contributing_workflow.html)\n\n## License\n\nOpenFHE-NumPy is licensed under the BSD 2-Clause License. See the LICENSE file for details.\n\n---\n\nOpenFHE-NumPy is an independent project and is not officially affiliated with NumPy.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenfheorg%2Fopenfhe-numpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenfheorg%2Fopenfhe-numpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenfheorg%2Fopenfhe-numpy/lists"}