All Projects → higham → chop

higham / chop

Licence: BSD-2-Clause License
Round matrix elements to lower precision in MATLAB

Programming Languages

matlab
3953 projects

Projects that are alternatives of or similar to chop

caffe-android-opencl-fp16
Optimised Caffe with OpenCL supporting for less powerful devices such as mobile phones
Stars: ✭ 17 (-19.05%)
Mutual labels:  half-precision, fp16
Surge
A Swift library that uses the Accelerate framework to provide high-performance functions for matrix math, digital signal processing, and image manipulation.
Stars: ✭ 4,945 (+23447.62%)
Mutual labels:  matrix, arithmetic
Tensor
A library and extension that provides objects for scientific computing in PHP.
Stars: ✭ 146 (+595.24%)
Mutual labels:  matrix, arithmetic
go
A Golang Matrix framework.
Stars: ✭ 192 (+814.29%)
Mutual labels:  matrix
botdarr
Slack/Discord/Telegram/Matrix bot for accessing radarr, sonarr, and lidarr
Stars: ✭ 76 (+261.9%)
Mutual labels:  matrix
DashGL-Library
Basic Matrix Manipulation Library For OpenGL Written in C
Stars: ✭ 20 (-4.76%)
Mutual labels:  matrix
canvas-cast
Cast any <canvas> element to an LED Matrix over WebSockets with an Arduino/ESP8266.
Stars: ✭ 39 (+85.71%)
Mutual labels:  matrix
geeks-for-geeks-solutions
✅ My own Amazon, Microsoft and Google SDE Coding challenge Solutions (offered by GeeksForGeeks).
Stars: ✭ 246 (+1071.43%)
Mutual labels:  matrix
monolish
monolish: MONOlithic LInear equation Solvers for Highly-parallel architecture
Stars: ✭ 166 (+690.48%)
Mutual labels:  matrix
first-neural-network
Simple neural network implemented from scratch in C++.
Stars: ✭ 17 (-19.05%)
Mutual labels:  matrix
addon-matrix
Matrix - Home Assistant Community Add-ons
Stars: ✭ 39 (+85.71%)
Mutual labels:  matrix
hlml
vectorized high-level math library
Stars: ✭ 42 (+100%)
Mutual labels:  matrix
EventBus
💢 Nepxion EventBus is a generic event dispatching component based on Google Guava with Spring framework AOP, support synchronous and asynchronous mode 基于Google Guava通用事件派发机制的事件总线组件,注解式发布订阅
Stars: ✭ 65 (+209.52%)
Mutual labels:  matrix
TP Arduino DigitalRain Anim
A library that represents Digital Rain Animation on color displays that support TFT_eSPI
Stars: ✭ 80 (+280.95%)
Mutual labels:  matrix
Alchemy
CV DL
Stars: ✭ 59 (+180.95%)
Mutual labels:  matrix
telematrix
Bridge between Telegram and Matrix
Stars: ✭ 95 (+352.38%)
Mutual labels:  matrix
mxpp
Bot for bridging Matrix and XMPP
Stars: ✭ 23 (+9.52%)
Mutual labels:  matrix
matrix-tag-manager
A web interface for supporting power users and their Matrix room tags.
Stars: ✭ 22 (+4.76%)
Mutual labels:  matrix
zombi-addons
No description or website provided.
Stars: ✭ 15 (-28.57%)
Mutual labels:  matrix
mtxclient
Client API library for Matrix, built on top of Boost.Asio
Stars: ✭ 21 (+0%)
Mutual labels:  matrix

Chop - MATLAB code for rounding matrix elements to lower precision

About

chop is a MATLAB function for rounding the elements of a matrix to a lower precision arithmetic with one of several forms of rounding. Its intended use is for simulating arithmetic of different precisions (less than double) with various rounding modes. The input to chop should be single precision or double precision and the output will have the same type: the lower precision numbers are stored within a higher precision type.

The arithmetic formats supported are

  • 'b', 'bfloat16' - bfloat16,
  • 'h', 'half', 'fp16' - IEEE half precision (the default),
  • 's', 'single', 'fp32' - IEEE single precision,
  • 'd', 'double', 'fp64' - IEEE double precision,
  • 'c', 'custom' - custom format.

Subnormal numbers can be supported or not, and in the latter case they are flushed to zero.

Several rounding modes are supported:

  • Round to nearest using round to even last bit to break ties (the default).
  • Round towards plus infinity (round up).
  • Round towards minus infinity (round down).
  • Round towards zero.
  • Stochastic rounding - round to the next larger or next smaller floating-point number with probability proportional to the distance to those floating-point numbers.
  • Stochastic rounding - round to the next larger or next smaller floating-point number with equal probability.

Optionally, each element of the rounded result has, with a specified probability defaulting to 0.5, a randomly chosen bit in its significand flipped. This option is useful for simulating soft errors

A further option causes the exponent limit for the specified arithmetic to be ignored, so overflow, underflow, or subnormal numbers will be produced only if necessary for the data type of the input. This option is useful for exploring low precisions indepdent of range limitations.

Demonstration function:

  • demo-harmonic computes the harmonic series in several arithmetic formats using all the supported rounding modes.

Other M-file:

  • roundit is a function for rounding a matrix to have integer entries. It is used by chop and is not intended to be called directly.

Test functions:

  • test_chop is a test function for chop.
  • test_roundit is a test function for roundit.

Each test function should print "All tests successful!".

The function chop is a successor to a function of the same name in the The Matrix Computation Toolbox (also available on File Exchange).

The test function test_chop needs the function float_paramsfrom the repository float_params. That function is included in this repository for convenience, but may not be the latest version.

Usage

There are two main usages of chop. First, one can pass options with every call:

options.format = 's'; options.round = 5; options.subnormal = 1; 
...
A(i,j) = chop(A(i,j) - chop(A(i,k) * A(k,j),options),options);

Here, options.format = 's' specifies that the precision is single, options.round = 5 specifies stochastic rounding, mode 1 and options.subnormal = 1 specifies that subnormal numbers are not flushed to zero. For full details of the options see the help lines in chop.m.

The above usage is rather tedious and produces cluttered code. Instead we can set up the arithmetic parameters on a call of the form chop([],options) and exploit the fact that subsequent calls with just one input argument will reuse the previously specified options:

options.format = 's'; options.round = 5; options.subnormal = 1; 
chop([],options)
...
A(i,j) = chop(A(i,j) - chop(A(i,k)*A(k,j))); 

The current value of options is stored inside the function (in a persistent variable, whose value is retained during the session until the function is cleared with clear chop and can be obtained with

[~,options] = chop

Requirements

The code was developed in MATLAB R2018b to R2020a and works with versions at least back to R2016a.

Reference

Nicholas J. Higham and Srikara Pranesh, Simulating Low Precision Floating-Point Arithmetic, SIAM J. Sci. Comput., 41(4):A2536-A2551, 2019.

Acknowledgements

The code was written by Nick Higham and Sri Pranesh. Max Fasi and Mantas Mikaitis have contributed improvements.

License

See license.txt for licensing information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].