Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bbergerud/tenops

Creating a common interface for numpy, pytorch, tensorflow, etc.
https://github.com/bbergerud/tenops

numpy pytorch tensorflow

Last synced: 6 days ago
JSON representation

Creating a common interface for numpy, pytorch, tensorflow, etc.

Awesome Lists containing this project

README

        

# Ten(sor) Op(eration)s

The basic idea behind this repository is to allow for seamlessly switching between libraries like numpy, pytorch, and tensorflow by checking the input types and returning the proper function for use in some operation.

## Installation
Installation can be done over pip
```
pip install tenops
```

Note that for the library to work you'll need to have at least one of the following libraries installed:
- numpy
- torch
- tensorflow

## Usage

Functions work like regular functions, one just needs to pass in the object and the function will identify the corresponding module and use the appropriate function:

```
>>> import torch, numpy, tensorflow as tf
>>> from tenops.special import exp
>>> exp(numpy.array([0]))
array([1.])
>>> exp(torch.tensor([0]))
tensor([1.])
>>> exp(tf.constant([0.]))

```

One can also just specify the module using the `default` parameter rather than typecasting directly (note that this requires that the specified library is installed):

```
>>> from tenops.special import exp
>>> exp([0], default="numpy")
array([1.])
>>> exp([0], default="torch")
tensor([1.])
>>> exp([0.], default="tensorflow")

```

## Development

[Poetry](https://python-poetry.org/docs/) is used to manage the build process.