Skip to content
xman edited this page Sep 27, 2018 · 7 revisions

Installation

Install from pip server.

pip install numpy-posit

Install from wheels.

Download a suitable wheel from here to install with pip.

pip install numpy_posit-1.15.2.0.0.1.dev2-cp36-cp36m-manylinux1_x86_64.whl

Install from source.

pip install Cython
git clone https://github.com/xman/numpy-posit.git

cd numpy-posit
git submodule init numpy/core/src/npymath/softposit
git submodule update
python setup.py build -j8
# Default first build fail at the lapack_lite.
# Run build again will get through it.
python setup.py build -j8
python setup.py install

Running numpy with posit

# sample.py 
import numpy
arr1 = numpy.array([1.5,2.4,5.8], dtype=numpy.posit32)
arr2 = numpy.array([-1.2,2.4,0], dtype=numpy.posit32)
print('arr1:', arr1)
print('arr2:', arr2)
print()
print('arr1 + arr2:', arr1+arr2)
print('arr1 - arr2:', arr1-arr2)
print('arr1 * arr2:', arr1*arr2)
print('arr1 / arr2:', arr1/arr2)
print()
print('sqrt(arr1)    :', numpy.sqrt(arr1))
print('dot(arr1,arr2):', numpy.dot(arr1,arr2))
$ python sample.py 
arr1: [1.5        2.40000001 5.80000001]
arr2: [-1.2         2.40000001  0.        ]

arr1 + arr2: [0.3        4.80000001 5.80000001]
arr1 - arr2: [2.7        0.         5.80000001]
arr1 * arr2: [-1.8         5.76000002  0.        ]
arr1 / arr2: [-1.25  1.     NaR]

sqrt(arr1)    : [1.22474487 1.54919334 2.40831892]
dot(arr1,arr2): 3.960000