deModel
Information about Python package usable for modeling fixed point arithmetic algorithms.
Download
- deModel_tar_gz - Platform-Independent Source
- deModel_win32_exe - Windows Installer
Documentation
Introduction
The Python package deModel provides a fixed point data type for Python, allowing the development of algorithm models in fixed point arithmetic. The basic data type is represented by the class DeFixedInt, which stores data as an integer and keeps information about the binary point. When performing basic arithmetic operations with this data type, the binary point is adjusted based on some fundamental rules of fixed point arithmetic. For further details about those rules we recommend a paper by Randy Yates titled "Fixed Point Arithmetic: An Introduction", available from the Digital Signal Labs page.
Installation
The installation of the package is fairly simple. When using the platform-independent source you can use the tar command to unpack it.
The Python package deModel provides a fixed point data type for Python, allowing the development of algorithm models in fixed point arithmetic. The basic data type is represented by the class DeFixedInt, which stores data as an integer and keeps information about the binary point. When performing basic arithmetic operations with this data type, the binary point is adjusted based on some fundamental rules of fixed point arithmetic. For further details about those rules we recommend a paper by Randy Yates titled "Fixed Point Arithmetic: An Introduction", available from the Digital Signal Labs page.
Installation
The installation of the package is fairly simple. When using the platform-independent source you can use the tar command to unpack it.
~> tar -xvf deModel-0.2.tar.gz
Then change into the newly created directory and run the setup.py script (as superuser):
~> cd deModel-0.2/
~> su
Password:
deModel-0.2 # python setup.py install
If you are using the native Windows installation of Python then just use the provided Windows installer. Executing the installer will guide you through the installation process.
Installed Documentation
See the code documentation, available through pydoc. Under Windows go to:
Start -> All Programs -> Python -> Module Docs
Under Linux enter on the command line:
Installed Documentation
See the code documentation, available through pydoc. Under Windows go to:
Start -> All Programs -> Python -> Module Docs
Under Linux enter on the command line:
> pydoc -g &
Hit the "open browser" button in the opening window, which in turn will open the browser with the Python module documentation. Search for the deModel package.
Examples
Let's look at a simple addition and multiplication example:
Examples
Let's look at a simple addition and multiplication example:
>>> from deModel import DeFixedInt
>>> a = DeFixedInt(8,2, 2.5)
>>> print a
<10 (2.500) A(8,2)>
After importing the class from deModel an instance a is created with the representation A(8,2), meaning 8 bits for the integer width, 2 bits for the fractional width + 1 sign bit. Part of the instantiation is the assignment of the value 2.5. Displaying the value returns the value in form <raw value (float value) fixed point representation>.
>>> b = DeFixedInt(8,2, 3.75)
>>> print b
<15 (3.750) A(8,2)>
>>> c = a + b
>>> print c
<25 (6.250) A(9,2)>
Now a second instance with the same representation is created and the value 3.75 is assigned. After that the two values are added together. From the result it can be seen that the representation changed. Due to the addition the integer width grew by one bit.
Let's now look at a multiplication example:
Let's now look at a multiplication example:
>>> d = a * b
>>> print d
<150 (9.375) A(17,4)>
Again the representation changed. Now the integer and fractional width got adjusted, based on the fixed point multiplication rule.
The next example will be again an addition operation, this time of two numpy arrays:
The next example will be again an addition operation, this time of two numpy arrays:
>>> from deModel import arrayFixedInt
>>> a = arrayFixedInt(8,2, [4.5, 1.25, 3.75, 2.0])
>>> print a
[<18 (4.500) A(8,2)> <5 (1.250) A(8,2)> <15 (3.750) A(8,2)> <8 (2.000) A(8,2)
First a new function arrayFixedInt is imported from deModel, which supports the creation of numpy arrays. The first two parameters, like with DeFixedInt, specify the integer and fractional width. The third parameter can either be an integer value, specifying the length of the to be created array, or as in our case, a list with floating point values. The function will now create an array of the same length, using the floating point values of the list to initialize the array with.
>>> b = arrayFixedInt(8,2, [2.25, 3.0, 1.5, 3.75])
>>> print b
[<9 (2.250) A(8,2)> <12 (3.000) A(8,2)> <6 (1.500) A(8,2)> <15 (3.750) A(8,2)>]
>>> c = a + b
>>> print c
[<27 (6.750) A(9,2)> <17 (4.250) A(9,2)> <21 (5.250) A(9,2)> <23 (5.750) A(9,2)>]
After creating a second array the above code shows how a fixed point addition can be performed by adding the two created arrays.