All Projects → xtensor-stack → Xtensor Python

xtensor-stack / Xtensor Python

Licence: bsd-3-clause
Python bindings for xtensor

Labels

Projects that are alternatives of or similar to Xtensor Python

Pytorch Wrapper
Provides a systematic and extensible way to build, train, evaluate, and tune deep learning models using PyTorch.
Stars: ✭ 92 (-62.9%)
Mutual labels:  tensor
Tinytpu
Implementation of a Tensor Processing Unit for embedded systems and the IoT.
Stars: ✭ 153 (-38.31%)
Mutual labels:  tensor
Tensor
package tensor provides efficient and generic n-dimensional arrays in Go that are useful for machine learning and deep learning purposes
Stars: ✭ 222 (-10.48%)
Mutual labels:  tensor
Tensorflow Gpu Macosx
Unoffcial NVIDIA CUDA GPU support version of Google Tensorflow for MAC OSX
Stars: ✭ 103 (-58.47%)
Mutual labels:  tensor
Hptt
High-Performance Tensor Transpose library
Stars: ✭ 141 (-43.15%)
Mutual labels:  tensor
Laser
The HPC toolbox: fused matrix multiplication, convolution, data-parallel strided tensor primitives, OpenMP facilities, SIMD, JIT Assembler, CPU detection, state-of-the-art vectorized BLAS for floats and integers
Stars: ✭ 191 (-22.98%)
Mutual labels:  tensor
Hyperlearn
50% faster, 50% less RAM Machine Learning. Numba rewritten Sklearn. SVD, NNMF, PCA, LinearReg, RidgeReg, Randomized, Truncated SVD/PCA, CSR Matrices all 50+% faster
Stars: ✭ 1,204 (+385.48%)
Mutual labels:  tensor
Einops
Deep learning operations reinvented (for pytorch, tensorflow, jax and others)
Stars: ✭ 4,022 (+1521.77%)
Mutual labels:  tensor
Tensorflow Cheatsheet
My personal reference for Tensorflow
Stars: ✭ 147 (-40.73%)
Mutual labels:  tensor
Norse
Deep learning with spiking neural networks (SNNs) in PyTorch.
Stars: ✭ 211 (-14.92%)
Mutual labels:  tensor
Pytorch
Tensors and Dynamic neural networks in Python with strong GPU acceleration
Stars: ✭ 52,811 (+21194.76%)
Mutual labels:  tensor
L2
l2 is a fast, Pytorch-style Tensor+Autograd library written in Rust
Stars: ✭ 126 (-49.19%)
Mutual labels:  tensor
Compute.scala
Scientific computing with N-dimensional arrays
Stars: ✭ 191 (-22.98%)
Mutual labels:  tensor
Deepnet
Deep.Net machine learning framework for F#
Stars: ✭ 99 (-60.08%)
Mutual labels:  tensor
Tensoroperations.jl
Julia package for tensor contractions and related operations
Stars: ✭ 230 (-7.26%)
Mutual labels:  tensor
Pytorch2c
A Python module for compiling PyTorch graphs to C
Stars: ✭ 86 (-65.32%)
Mutual labels:  tensor
Mars
Mars is a tensor-based unified framework for large-scale data computation which scales numpy, pandas, scikit-learn and Python functions.
Stars: ✭ 2,308 (+830.65%)
Mutual labels:  tensor
Nexus
Experimental tensor-typed deep learning
Stars: ✭ 244 (-1.61%)
Mutual labels:  tensor
Tullio.jl
Stars: ✭ 231 (-6.85%)
Mutual labels:  tensor
Tenseal
A library for doing homomorphic encryption operations on tensors
Stars: ✭ 197 (-20.56%)
Mutual labels:  tensor

xtensor-python

Azure Pipelines Appveyor Documentation Join the Gitter Chat

Python bindings for the xtensor C++ multi-dimensional array library.

  • xtensor is a C++ library for multi-dimensional arrays enabling numpy-style broadcasting and lazy computing.

  • xtensor-python enables inplace use of numpy arrays in C++ with all the benefits from xtensor

The Python bindings for xtensor are based on the pybind11 C++ library, which enables seamless interoperability between C++ and Python.

Installation

xtensor-python is a header-only library. We provide a package for the conda package manager.

conda install -c conda-forge xtensor-python

Documentation

To get started with using xtensor-python, check out the full documentation

http://xtensor-python.readthedocs.io/

Usage

xtensor-python offers two container types wrapping numpy arrays inplace to provide an xtensor semantics

  • pytensor
  • pyarray.

Both containers enable the numpy-style APIs of xtensor (see the numpy to xtensor cheat sheet).

  • On the one hand, pyarray has a dynamic number of dimensions. Just like numpy arrays, it can be reshaped with a shape of a different length (and the new shape is reflected on the python side).

  • On the other hand pytensor has a compile time number of dimensions, specified with a template parameter. Shapes of pytensor instances are stack allocated, making pytensor a significantly faster expression than pyarray.

Example 1: Use an algorithm of the C++ standard library on a numpy array inplace.

C++ code

#include <numeric>                        // Standard library import for std::accumulate
#include "pybind11/pybind11.h"            // Pybind11 import to define Python bindings
#include "xtensor/xmath.hpp"              // xtensor import for the C++ universal functions
#define FORCE_IMPORT_ARRAY
#include "xtensor-python/pyarray.hpp"     // Numpy bindings

double sum_of_sines(xt::pyarray<double>& m)
{
    auto sines = xt::sin(m);  // sines does not actually hold values.
    return std::accumulate(sines.begin(), sines.end(), 0.0);
}

PYBIND11_MODULE(xtensor_python_test, m)
{
    xt::import_numpy();
    m.doc() = "Test module for xtensor python bindings";

    m.def("sum_of_sines", sum_of_sines, "Sum the sines of the input values");
}

Python Code

import numpy as np
import xtensor_python_test as xt

v = np.arange(15).reshape(3, 5)
s = xt.sum_of_sines(v)
s

Outputs

1.2853996391883833

Example 2: Create a universal function from a C++ scalar function

C++ code

#include "pybind11/pybind11.h"
#define FORCE_IMPORT_ARRAY
#include "xtensor-python/pyvectorize.hpp"
#include <numeric>
#include <cmath>

namespace py = pybind11;

double scalar_func(double i, double j)
{
    return std::sin(i) - std::cos(j);
}

PYBIND11_MODULE(xtensor_python_test, m)
{
    xt::import_numpy();
    m.doc() = "Test module for xtensor python bindings";

    m.def("vectorized_func", xt::pyvectorize(scalar_func), "");
}

Python Code

import numpy as np
import xtensor_python_test as xt

x = np.arange(15).reshape(3, 5)
y = [1, 2, 3, 4, 5]
z = xt.vectorized_func(x, y)
z

Outputs

[[-0.540302,  1.257618,  1.89929 ,  0.794764, -1.040465],
 [-1.499227,  0.136731,  1.646979,  1.643002,  0.128456],
 [-1.084323, -0.583843,  0.45342 ,  1.073811,  0.706945]]

Installation

We provide a package for the conda package manager.

conda install -c conda-forge xtensor-python

This will pull the dependencies to xtensor-python, that is pybind11 and xtensor.

Project cookiecutter

A template for a project making use of xtensor-python is available in the form of a cookiecutter here.

This project is meant to help library authors get started with the xtensor python bindings.

It produces a project following the best practices for the packaging and distribution of Python extensions based on xtensor-python, including a setup.py file and a conda recipe.

Building and Running the Tests

Testing xtensor-python requires pytest

py.test .

To pick up changes in xtensor-python while rebuilding, delete the build/ directory.

Building the HTML Documentation

xtensor-python's documentation is built with three tools

While doxygen must be installed separately, you can install breathe by typing

pip install breathe

Breathe can also be installed with conda

conda install -c conda-forge breathe

Finally, build the documentation with

make html

from the docs subdirectory.

Dependencies on xtensor and pybind11

xtensor-python depends on the xtensor and pybind11 libraries

xtensor-python xtensor pybind11
master ^0.23.0 ~2.4.3
0.25.1 ^0.23.0 ~2.4.3
0.25.0 ^0.23.0 ~2.4.3
0.24.1 ^0.21.2 ~2.4.3
0.24.0 ^0.21.1 ~2.4.3
0.23.2 ^0.20.10 ~2.4.3
0.23.1 ^0.20.6 ~2.2.1
0.23.0 ^0.20.4 ~2.2.1
0.22.x ^0.19.0 ~2.2.1
0.21.x ^0.18.0 ~2.2.1
0.20.x ^0.17.0 ~2.2.1
0.19.x ^0.16.0 ~2.2.1
0.18.x ^0.16.0 ~2.1.0 or ~2.2.1
0.17.x ^0.15.1 ~2.1.0 or ~2.2.1
0.16.x ^0.14.0 ~2.1.0 or ~2.2.1
0.15.x ^0.13.1 ~2.1.0 or ~2.2.1

These dependencies are automatically resolved when using the conda package manager.

License

We use a shared copyright model that enables all contributors to maintain the copyright on their contributions.

This software is licensed under the BSD-3-Clause license. See the LICENSE file for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].