Multiply row vector with sparse matrix in tensorflow
Project description
keras-dense-sparse-matmul
This package only contains one utility function dense_sparse_matmul
to multiply a (dense) row vector with sparse matrix in tensorflow.
Installation
The keras-dense-sparse-matmul
git repo is available as PyPi package
pip install keras-dense-sparse-matmul
pip install git+ssh://git@github.com/ulf1/keras-dense-sparse-matmul.git
Usage
import tensorflow as tf
from keras_dense_sparse_matmul import dense_sparse_matmul
# 1x3 row vector
h = tf.constant([1., 2., 3.])
# 3x4 sparse matrix
W = tf.sparse.SparseTensor(
indices=([0, 1], [1, 1], [1, 2], [2, 0], [2, 2], [0, 3], [2, 3]),
values=[1., 2., 3., 4., 5., 6., 7.],
dense_shape=(3, 4))
W = tf.sparse.reorder(W)
# result is a 1x4 row vector
net = dense_sparse_matmul(h, W)
Check the example notebook.
Appendix
Install in a virtual environment
If you want to check the function dense_sparse_matmul
first,
you can use Binder or install a virtual environment on your local computer
python3.6 -m venv .venv
source .venv/bin/activate
pip3 install --upgrade pip
pip3 install -r requirements.txt
(If your git repo is stored in a folder with whitespaces, then don't use the subfolder .venv
. Use an absolute path without whitespaces.)
Python commands
- Activate the virtual env:
source .venv/bin/activate
- Jupyter for the examples:
jupyter lab
- Check syntax:
flake8 --ignore=F401 --exclude=$(grep -v '^#' .gitignore | xargs | sed -e 's/ /,/g')
- Run Unit Tests:
pytest
- Upload to PyPi with twine:
python setup.py sdist && twine upload -r pypi dist/*
Clean up commands
find . -type f -name "*.pyc" | xargs rm
find . -type d -name "__pycache__" | xargs rm -r
rm -r .pytest_cache
rm -r .venv
Support
Please open an issue for support.
Contributing
Please contribute using Github Flow. Create a branch, add commits, and open a pull request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for keras-dense-sparse-matmul-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8735c681ad24aa6203b6bcfc340f0d18fff6f861a20c64702fafa58ee53a6902 |
|
MD5 | 5d6b713cc31a715a8c1c639cd0be7415 |
|
BLAKE2b-256 | 366e6096d84c93a5f8d333f85714f3bdea81ebad92ebc5adcfe765d3a27e9fad |