张量流中的任意精度整数。
tf-big的Python项目详细描述
tf大
tf big增加了对tensorflow的大数支持,允许对任意精度整数执行计算。在内部,它们被表示为GMP值的变量张量,并通过tf_big.Tensor
包装器在python中公开,以方便使用。对于导入和导出,数字通常表示为字符串。
用法
importtensorflowastfimporttf_big# load large values as stringsx=tf_big.constant(["100000000000000000000","200000000000000000000"])# load ordinary TensorFlow tensorsy=tf_big.convert_to_tensor(tf.constant([3,4]))# perform computation as usualz=x*y# use TensorFlow sessions to evalutate the resultswithtf.Session()assess:res=sess.run(z)print(res)
安装
python 3包可从PyPI:
pip install tf-big
有关设置开发环境的进一步说明,请参见下文。
开发
要求
我们建议使用Miniconda或Anaconda来设置和使用python 3.5或3.6环境来执行以下所有指令:
conda create -n tfbig-dev python=3.6
source activate tfbig-dev
ubuntu
ubuntu的唯一要求是拥有docker installed。这是推荐的build custom operations for TensorFlow方法。我们为tf big提供了一个自定义开发容器,其中已经安装了所有依赖项。
Mac操作系统
在macos上建立一个开发环境要复杂一些,因为我们不能使用docker容器。我们需要四样东西:
- Python(>;=3.5)
- Bazel(>;=0.15.0)
- GMP(>;=6.1.2)
- TensorFlow(=1.13.1)
使用Homebrew我们首先确保Bazel和gmp都已安装:
brew tap bazelbuild/tap
brew install bazelbuild/tap/bazel
brew install gmp
brew install mmv
然后,可以使用以下命令安装其余的pypi包:
pip install -r requirements-dev.txt
测试
ubuntu
通过在Docker容器中运行make test
命令在ubuntu上运行测试。现在,DOCKER容器在DOCKER集线器上不存在,所以我们必须首先构建它:
docker build -t tf-encrypted/tf-big:0.1.0 .
然后我们可以运行make test
:
sudo docker run -it \
-v `pwd`:/opt/my-project -w /opt/my-project \
tf-encrypted/tf-big:0.1.0 /bin/bash -c "make test"
Mac操作系统
一旦开发环境设置好,我们就可以简单地运行:
make test
这将安装tensorflow(如果以前没有安装),并生成和运行测试。
构建pip包
Circleci目前正在为我们构建PIP包。如果你需要自己做,你可以运行make build
。对于linux,建议在tensorflow/tensorflow:custom op容器中进行。