Skip to main content

zk_dtypes is a stand-alone implementation of several NumPy dtype extensions used in Zero Knowledge.

Project description

zk_dtypes

CI

zk_dtypes is a stand-alone implementation of several NumPy dtype extensions used in Zero Knowledge libraries inspired by ml_dtypes, including:

  • Narrow integer:

    • int2
    • int4
    • uint2
    • uint4
  • Field:

    • babybear
    • babybear_std
    • goldilocks
    • goldilocks_std
    • koalabear
    • koalabear_std
    • mersenne31
    • mersenne31_std
  • Extension Field:

    • babybear4
    • babybear4_std
    • goldilocks3
    • goldilocks3_std
    • mersenne312
    • mersenne312_std
    • koalabear4
    • koalabear4_std
  • Elliptic curve:

    • bn254_sf
    • bn254_sf_std
    • bn254_g1_affine
    • bn254_g1_affine_std
    • bn254_g1_jacobian
    • bn254_g1_jacobian_std
    • bn254_g1_xyzz
    • bn254_g1_xyzz_std
    • bn254_g2_affine
    • bn254_g2_affine_std
    • bn254_g2_jacobian
    • bn254_g2_jacobian_std
    • bn254_g2_xyzz
    • bn254_g2_xyzz_std

Prerequisite

  1. Follow the bazel installation guide.

Build instructions

  1. Clone the zk_dtypes repo

    git clone https://github.com/fractalyze/zk_dtypes
    
  2. Build zk_dtypes

    bazel build //...
    
  3. Test zk_dtypes

    bazel test //...
    

Installation

The zk_dtypes package is tested with Python versions 3.11-3.13, and can be installed with the following command:

pip install zk_dtypes

To test your installation, you can run the following:

pip install absl-py pytest
pytest zk_dtypes/tests

Installation from source

To build and install the package from source, run:

pip install .

Installation from prebuilt binary

Use USE_BAZEL_OUTPUT=1 for a faster installation that uses pre-built Bazel artifacts. This is the recommended path for development.

  • On Linux / macOS

    # Build the shared library (.so)
    bazel build //zk_dtypes:_zk_dtypes_ext.so
    
    # Install using the Bazel output
    USE_BAZEL_OUTPUT=1 pip install .
    
  • On Windows

    # Build the Python extension (.pyd)
    bazel build //zk_dtypes:_zk_dtypes_ext.pyd
    
    # Install using the Bazel output (PowerShell syntax)
    $env:USE_BAZEL_OUTPUT=1; pip install .
    

Example Usage

>>> from zk_dtypes import babybear
>>> import numpy as np
>>> a = np.array([-1, -3, 2**30, 7], dtype=babybear)
>>> b = np.array([5, 2, 4, 10], dtype=babybear)
>>> a + b
array([4, 2013265920, 1073741828, 17], dtype=babybear)

Importing zk_dtypes also registers the data types with numpy, so that they may be referred to by their string name:

>>> np.dtype('babybear')
dtype(babybear)

See examples/zk_dtypes_examples.ipynb for more examples.

License

The zk_dtypes source code is a modified derivative of the ml_dtypes project and inherits the original Apache 2.0 License (see LICENSE). All subsequent modifications comply with and are released under the same license.

Pre-compiled Wheels Dependencies

Note that pre-compiled wheels utilize the following dependencies:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

zk_dtypes-0.0.2-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (10.2 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

zk_dtypes-0.0.2-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (10.0 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

zk_dtypes-0.0.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (10.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

zk_dtypes-0.0.2-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (9.8 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

zk_dtypes-0.0.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (10.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

zk_dtypes-0.0.2-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (9.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

zk_dtypes-0.0.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (10.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

zk_dtypes-0.0.2-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (9.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

zk_dtypes-0.0.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (10.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

zk_dtypes-0.0.2-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (9.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

zk_dtypes-0.0.2-cp311-cp311-macosx_15_0_arm64.whl (680.8 kB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

File details

Details for the file zk_dtypes-0.0.2-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.2-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ecfa3dd3d25fbb74cc382adb5ce4f2805b4078d56303e013da340bb52ed39ad1
MD5 766da58c386d6d740f6e655f18421982
BLAKE2b-256 8f5f07b7d4c9d572e3dc86204a268eacce9bbc3e17fd219012d1af24ea70c99f

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.2-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.2-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 758951119245e468b7f34afc8a363d6543deba3d65f8202f4eb268e7291a638a
MD5 e97e1bd4b13c2f6766f61a195ce635f7
BLAKE2b-256 78bc83581ff4fbfe927524871cb8748ddbcc8f7a6389c53888999af9807a5ece

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 960795dccf7ab01ca281004c02499daea3dbebc52beed4f26239e17d20ee1517
MD5 ad855da11efb07168e14171b6f80779e
BLAKE2b-256 8071cd9331a51707b00a72132615df580266db1d9791b5e9c01ac6f6475cc8de

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.2-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.2-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9002135bb613add5252d84be365748382b9384033eb18c2a6e061f9aad827ed6
MD5 cfefbb7eb90cc99c2b51cbf6bf9cd906
BLAKE2b-256 33f522e7a188fa7049a3b93d4ffefce3eef3bfaf6d6ac09ff466022ea9087913

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a237e2bf653f1c1ee4440238bb5931c2d3ff15bf808d97852fe7e22a674cc77c
MD5 b00119baf688d6b12844c93f7afd35d5
BLAKE2b-256 af236279fc575a235bed399e436b0ce9584a34a6aeb48d3433af62815aa9adc6

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.2-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.2-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6640d4d42e609657f1e2eea3705a6816015db6d5953d5b57425a9102fef906c0
MD5 f2110ec7288cbd99d9bae4d3eb4c6d9b
BLAKE2b-256 12912e220c9b0eb89419122a945f398e7071bad4fb09d65ac9abeba2683f8fdf

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 70c3895125561cbdb5ea3921e9e9ac69d711ab275cd8e937440296ba6f3d1065
MD5 316516a0630aab3c6016a5436654638c
BLAKE2b-256 6a53743a75e209811ffc6c4f7046b12b70fe7db83c288d2457f37e31aa0daecf

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.2-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.2-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4139d1cc0e1d52a9328b0280b656153eaa98c0e4f760956e5fb1423a9865d03c
MD5 f258134e706011e47b26dc1839036024
BLAKE2b-256 34bfddc7c385b87c73df441b776583366a7b14b80a38ce4363c83b7d4e5048ff

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a919d7fa4c3dbb87e9d80dc5e0d01d4f2774ffd6ea852abcaade3091268fb24b
MD5 844d41f16eb365a69a3aacb0c9034d35
BLAKE2b-256 8d33b8c7779d6fd2760ad026bd8c7bf7d26e1ab0f7b53520565303d9d36f0311

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.2-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.2-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5cc35380072c80b7443bc6b6255c4075aeb397eeb3af71eece1b91916228898e
MD5 b6b6c3402c5ddc3c4b6cccc841bf90f5
BLAKE2b-256 640bca9ed9bae0afe2e8e1f28524a2a9b7518f9d884293e1cf35474cfa5fd5b5

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.2-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.2-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 5cea32a49b1f1c1a37969ef8e6b4215434cdd120f6472fed387e86757898ce5c
MD5 d8b7e78f4e52266154195e7be65c4af6
BLAKE2b-256 4c869e21e8811d71e0a5c3331288d548c9bac02dd89c54cda6d162ebae1488a4

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