Skip to main content

Python bindings for the Tensor-library

Project description

tensorx-python

Python bindings for the Tensor-library

  • C++20
  • CMake
  • Python3
  • pybind11
  • scikit-build-core
  • cibuildwheel
  • twine

Example

Create virtual environment:

python3 -m venv .venv
. .venv/bin/activate

Install with pip:

pip install tensorxx

Tensor creation and access example:

import tensorxx
print(tensorxx)

import tensorxx._tensorxx
print(tensorxx._tensorxx)

if __name__ == "__main__":
    print("add_ints:", tensorxx.add_ints(2, 3))

    print("make_tensor:")
    tensorxx.make_tensor()

    t0 = tensorxx.Tensor()
    print("t0.rank:", t0.rank, "t0.dims:", t0.dims, "t0.length:", t0.length)
    print("t0:", t0)

    s = tensorxx.scalar(3.14)
    print("s:", s)
    print("s.rank:", s.rank, "s.dims:", s.dims, "s.length:", s.length)
    print("s.get:", s.get())     # 3.14
    s.set(2.71)
    print("s.set(2.71)->s.get:", s.get())     # 2.71

    t1 = tensorxx.Tensor(2, (2, 3))
    print("t1.rank:", t1.rank, "t1.dims:", t1.dims, "t1.length:", t1.length)
    print("t1:", t1)

    t2 = tensorxx.Tensor(2, 3, 4)
    print("t2.rank:", t2.rank, "t2.dims:", t2.dims, "t2.length:", t2.length)
    print("t2:", t2)

    v = tensorxx.from_list([1, 2, 3])
    print("v:", v)

    m = tensorxx.from_list([
        [1,2,3],
        [4,5,6],
        [7,8,9]
    ])
    print("m:", m)
    print("m.rank:", m.rank, "m.dims:", m.dims, "m.length:", m.length)
    print("m.get(1, 1):", m.get(1, 1))

Image processing example:

import tensorxx
from tensorxx.opencv_utils import imshow
import numpy as np
import cv2

if __name__ == "__main__":
    print("Hello, TensorX!")

    path = "./lenna.png"
    t = tensorxx.imread(path)

    print(f"t: rank({t.rank}), size({t.length})")
    print(f"t: dims({t.dims})")

    blurred = tensorxx.gaussian_blur(t, 1)
    sobel = tensorxx.sobel_operator(blurred)
    nms = tensorxx.non_max_suppression(sobel)
    strongweak = tensorxx.double_threshold(nms, 20.0, 80.0)
    chained = tensorxx.hysterisis(nms, 20.0, 80.0)

    imshow("Original", t)
    imshow("Gaussian Blur", blurred)
    imshow("Sobel (norm)", sobel)
    imshow("NMS (norm)", nms)
    imshow("Double Threshold", strongweak)
    imshow("Hysteresis", chained)

Build

Add Tensor-library:

git submodule add -b cxx-mappings git@github.com:alarxx/Tensor-library.git

Install Docker: Root:

apt install docker.io
sudo systemctl enable docker # autostart
sudo systemctl start docker
sudo systemctl status docker
sudo usermod -aG docker $USER

User:

su -c "sudo usermod -aG docker $USER"
newgrp docker
docker version
docker ps

apt install python3 python3-full python3-pip python3-venv
#sudo apt install python3.8
python3 --version

python3 -m venv .venv
. .venv/bin/activate

python -m pip install -U pip build
python -m pip install -U pybind11 cmake ninja
python -m pip install -U twine # upload
python -m pip install -U scikit-build-core # hatchling
python -m pip install -U cibuildwheel # cross-platform build

Build with hatchling vs. scikit_build_core (CMake).

Generating distribution archives from pyproject.toml file with configuration metadata:

python -m build
  • .tar.gz - source distribution
  • .whl - built distribution

Try to install locally:

python -m pip install --force-reinstall dist/*.whl
  • --force-reinstall - if version didn't change

Uninstall local tensorxx:

python -m pip uninstall tensorxx

Inside tensorxx/ should be shared libraries (.so)

unzip -l dist/*.whl

Cross-platform build:

cibuildwheel --output-dir dist

Upload to PyPI:

python -m twine upload dist/*

Разобраться с manylinux:

export CIBW_REPAIR_WHEEL_COMMAND_LINUX='LD_LIBRARY_PATH=/opt/opencv/lib64 auditwheel repair -w {dest_dir} {wheel}'


export CIBW_BEFORE_BUILD_LINUX='set -eux; find /opt/opencv -maxdepth 3 -type f -name "libopencv_core.so*" -o -name "libopencv_imgproc.so*" -o -name "libopencv_imgcodecs.so*" -o -name "libopencv_highgui.so*" || true; find /opt/opencv -maxdepth 3 -type d -print;'

export CIBW_SKIP="*-musllinux_*"

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.

tensorxx-0.0.2-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (6.8 MB view details)

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

tensorxx-0.0.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (6.8 MB view details)

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

tensorxx-0.0.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (6.8 MB view details)

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

tensorxx-0.0.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (6.8 MB view details)

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

tensorxx-0.0.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (6.8 MB view details)

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

tensorxx-0.0.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (6.8 MB view details)

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

tensorxx-0.0.2-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (6.8 MB view details)

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

File details

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

File metadata

File hashes

Hashes for tensorxx-0.0.2-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 aeb2f7ee349f3ab999b0123c33b2d96a51daff6b4a9c2eeb6663105e250ac67d
MD5 e0793c0ca2d6b45a09e3592d4199ed71
BLAKE2b-256 cd2bf13ccaefa3617edd20f27f933d00064f5340008a5e263a4a8bfc17311e88

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorxx-0.0.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0293997ff4879bab54d4ff25e4b74e6585dadaacdfd6bb10be2175d57b83f3d6
MD5 7e50c6c2904e7f498d2095718fe32da6
BLAKE2b-256 a40332b4ba6397b257aac1bb6058b589f745b829e745e304bcc8d7549345be7e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorxx-0.0.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 662ad2b7a294a201910491e3af97065daa5156a500b4d6e1379a3ed30218e6f5
MD5 3ffbf1889759b067f09450d67e85c715
BLAKE2b-256 cfcee5fb717e588366910174cbe09a50513992c492126db1dace294f5ddb33d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorxx-0.0.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 487ae42b03db7501e8b82baed67160d0c3c5115109a3acae0154fcc05848b769
MD5 639743c1ac654ce9e94d113ef818bc9d
BLAKE2b-256 9ad824bc8a67eefa86fb34ad636fed1959a286d152201501972c26ef685bac38

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorxx-0.0.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ad10638c7aec547eb0410c783ffad3c0cf957fa761615e4f83fb61fd0ef92211
MD5 3cb68ce172a20093fb5866d7478ce0ef
BLAKE2b-256 6459ccd16c3856dd148b87d0e5724c3863f7facc9d64999f8a3aeb9361df5742

See more details on using hashes here.

File details

Details for the file tensorxx-0.0.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tensorxx-0.0.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6bbef5a4b5775c19ba7f3bfc0b866f063422e224c8cec7945657011249020655
MD5 2490f6874e759329b96b8885b48e28e9
BLAKE2b-256 865d8f7b6ac1ac7928f52d95fdee374b59d357f209d01e267e24d644518f5f22

See more details on using hashes here.

File details

Details for the file tensorxx-0.0.2-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tensorxx-0.0.2-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8c18a800f6063d7041cd95fe8c2bc5dcaddc9115002fcfd9c4b8b9bcba4cb356
MD5 01c80535e7ace763af76a2c05b242d1b
BLAKE2b-256 2f1e78a8ea1baeffa8aa016974d9aa38d1f20217f8f5ae4fd0306bce1167f532

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