Coder Social home page Coder Social logo

max-ilse / pytorch-binary-converter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from karenullrich/pytorch-binary-converter

0.0 0.0 0.0 30 KB

Turning float tensors to binary tensors according to IEEE-754 standard.

License: GNU General Public License v3.0

Python 100.00%

pytorch-binary-converter's Introduction

Binary Converter

This is a tool to turn pytorch's floats into binary tensors and back. This code converts tensors of floats or bits into the respective other. We use the IEEE-754 guideline [1] to convert. The default for conversion are based on 32 bit / single precision floats: 8 exponent bits and 23 mantissa bits. Other common formats are

num total bits precision exponent bits mantissa bits bias
64 bits double 11 52 1023
32 bits single 8 23 127
16 bits half 5 10 15

Usage

To turn a float tensor into a binary one

from binary_converter import float2bit
binary_tensor = float2bit(float_tensor, num_e_bits=8, num_m_bits=23, bias=127.)

To turn a binary tensor into a float one

from binary_converter import bit2float
float_tensor = bit2float(binary_tensor, num_e_bits=8, num_m_bits=23, bias=127.)

Requirements

This code has been tested with

  • python 3.6
  • pytorch 1.1.0

Maintenance

Please be warned that this repository is not going to be maintained regularly.

References

[1] IEEE Computer Society (2008-08-29). IEEE Standard for Floating-Point Arithmetic. IEEE Std 754-2008. IEEE. pp. 1โ€“70. doi:10.1109/IEEESTD.2008.4610935. ISBN 978-0-7381-5753-5. IEEE Std 754-2008

pytorch-binary-converter's People

Contributors

karenullrich avatar

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.