SoftPosit Python Package
pip install softposit==0.3.4.4
This is the python wrapper (using SWIG) of SoftPosit
Support only on Linux, OS-X and Windows systems with gcc. Please note that you will need to have gcc installed on your system.
Currently we support only 64-bit systems:
For all other versions, you will have to compile the source as a part of pip installation. Consequently for windows and OS-X users, please install Visual Studio Build Tools and Xcode respectively.
Tested on Windows (cl.exe and Mingw-w64) Mac-OSX (CLANG) and Linux SuSE (GNU).
First install the prerequisite:
pip install requests
To install using pip (might require root priviledges):
pip install softposit
To install using pip in user space:
pip install softposit --user
To force it to install the latest version in user space:
pip install --no-cache-dir softposit --user
To install via source (might require root priviledges)::
python setup.py install
To install via source in user space:
python setup.py install --user
To install from source in a specific directory:
python setup.py install --prefix=YOUR_PREFERRED_DIRECTORY
The easiest way is to use ipython
from softposit import * #Initialise to zero pA = posit32() #Initialise the bits pB = posit16(bits=0x98FA) #Initialise based on real values pC = posit8(0.1875) #To view the bits (formatted) -> works only in ipython pC.toBinaryFormatted() #To view the bits without formatting pB.ToBinary() #To view real value print(pB)
import softposit as sp #Initialise a 16-bit posit a = sp.posit16(2.6) b = a + 2.1 a *= 2 c = b/a # fused-multiply-add => c + (0.2* 2.3) c.fma(0.2, 2.3) result = c.sqrt() # convert a 16-bit posit to 8-bit posit p8 = c.toPosit8() #quire - initialise to zero when declared q = sp.quire16() #fused multiply subtract -> q + (6.2*1.2) q.qms(6.2, 1.2) #convert quire to posit c = q.toPosit() #to clear quire to zero q.clr() #print print(a)
Special thanks to Shin Yee for his support. If not for his help, this port might take forever!