Giter Site home page Giter Site logo

popcornell / pygf2 Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 4.0 633 KB

Polynomial arithmetic over GF2

License: GNU General Public License v3.0

Python 100.00%
galois-field linear-codes numpy polynomials polynomial-arithmetic coding-theory polynomial-inversion polynomial-division

pygf2's Introduction

pyGF2

Optimized Polynomial arithmetic over GF2[x].

This module supports polynomial addition gf2_add, multiplication gf2_mul division gf2_div and Extended Euclidean Algorithm gf2_xgcd.

Polynomials must be represented as ndarrays of uint8 including zero-valued coefficients. The rightmost array element is assumed to represent the leading coefficient.


For example:

>>>a =np.array([1, 0, 1, 1], dtype="uint8")

It is equivalent to the polynomial x^3+x^2+1. In other words the ordering is the same as the one used in MATLAB. Sympy and numpy.polys instead assume the leftmost array element to be the leading coefficient.

The use of such ordering allows to use numpy.fft to perform multiplication between polynomials.


In general a great effort has been put to speed-up all the operations making this module suitable for handling very large degree (tens of thousands) GF2[x] polynomials such as the ones required in coding theory.

Speed-wise it is orders of magnitude faster for polynomials of large degree when it is compared to both numpy.polys functions and Sympy.galoistools.

For Example:

  • numpy.polymul vs gf2_mul for two random GF2[x] polynomial with 100000 elements: 5.63 s vs 105 ms

  • numpy.polydiv encounters overflow problems when dealing with large polynomials. gf2_div solves that by using only modulo 2 operations.

  • sympy.galoistools.gf_gcdex vs gf2_xgcd for two random GF2[x] polynomial with 11083 elements: 2 m 5 s vs 1.29 s


Requirements : NumPy (tested with NumPy 1.13.3 and Python 3.6.3)


pygf2's People

Contributors

popcornell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pygf2's Issues

SyntaxWarning: "is not" with a literal. Did you mean "!="?

SyntaxWarning: "is not" with a literal. Did you mean "!="?
  if a.dtype is not "uint8":
SyntaxWarning: "is not" with a literal. Did you mean "!="?
  if b.dtype is not "uint8":
For solve the problem, we must change the following:
if a.dtype is not "uint8":
    a = a.astype("uint8")

if b.dtype is not "uint8":
    b = b.astype("uint8")

to:

if a.dtype != "uint8":
    a = a.astype("uint8")

if b.dtype != "uint8":
    b = b.astype("uint8")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.