-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1009ea1
Showing
10 changed files
with
1,375 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# level-index-simulator | ||
|
||
# `sli` - A custom precision MATLAB symmetric level-index arithmetic simulator. | ||
|
||
## About | ||
|
||
`sli` is a MATLAB toolbox that provides sli objects and operations on them. | ||
|
||
* [sli.m](sli.m) - the main object file. | ||
* [tests](./tests) - various testing scripts that test the accuracy of representation and operations. | ||
* [experiments](./experiments) - scripts to reproduce the experiments with level-index arithmetic in [1]. | ||
|
||
[![Open in MATLAB Online](https://www.mathworks.com/images/responsive/global/open-in-matlab-online.svg)](https://matlab.mathworks.com/open/github/v1?repo=north-numerical-computing/level-index-simulator) | ||
|
||
## Quick start | ||
|
||
``` | ||
x = sli(2,12); | ||
x = x.set_val(pi) | ||
x = | ||
sli with properties: | ||
level_bits: 2 | ||
index_bits: 12 | ||
sign: 0 | ||
reciprocal: 1 | ||
level: 2 | ||
index: 0.135253906250000 | ||
value: 3.141899100868418 | ||
``` | ||
|
||
### Installation | ||
|
||
Clone the repository and add the root directory to the MATLAB search path. | ||
|
||
## Requirements | ||
|
||
The code was developed on MATLAB 2023b. Experiments make use of the [CPFloat](https://github.com/north-numerical-computing/cpfloat) package. | ||
|
||
## References | ||
|
||
[1] Mantas Mikaitis. [*MATLAB Simulator of Level-Index Arithmetic*](https://). In Prep., Feb. 2024. | ||
|
||
## Licence | ||
|
||
The code is distributed under the terms of the BSD 2-Clause License; | ||
see [license.txt](license.txt). | ||
BBB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
% Compare matrix-vector product accuracy in floating-point and | ||
% level-index arithmetics. | ||
% | ||
% References | ||
% | ||
% M. Mikaitis, MATLAB Simulator of Level Index Arithmetic, In Prep., 2024. | ||
|
||
clear all; | ||
|
||
nlist = round(logspace(1,4,20)); | ||
|
||
% Set up cpfloat options | ||
options.format = 'fp16'; | ||
options.round = 1; | ||
options.explim = 1; | ||
cpfloat([], options); | ||
k = 0; | ||
|
||
for n = nlist | ||
k = k + 1; | ||
fprintf('k = %2d, n = %7d\n',k,n); | ||
A = rand(10,n)*100; | ||
x = rand(n,1); | ||
|
||
% Set up SLI vectors | ||
Asli = zeros(10, n, 2, 12, 'sli'); | ||
xsli = zeros(n, 1, 2, 12, 'sli'); | ||
|
||
% Convert vectors to SLI | ||
for j = 1:numel(A) | ||
Asli(j) = Asli(j).set_val(A(j)); | ||
end | ||
for j = 1:numel(x) | ||
xsli(j) = xsli(j).set_val(x(j)); | ||
end | ||
|
||
% Double reference result | ||
ye = A*x; | ||
absAx = abs(A)*abs(x); | ||
|
||
% Binary16 result | ||
y1 = mtimesv(A,x,options); | ||
berr1(k) = max(abs(ye-y1)./absAx); | ||
|
||
% Level index 2.12 | ||
y2 = Asli*xsli; | ||
berr2(k) = max(abs(ye-[y2.value]')./absAx); | ||
end | ||
|
||
filename = sprintf('matvec_binary16_1.dat'); | ||
fid = fopen(filename, 'w'); | ||
for i=1:length(nlist) | ||
fprintf(fid, "%d %f %f\n", nlist(i), berr1(i), berr2(i)); | ||
end | ||
fclose(fid); | ||
|
||
loglog(nlist, berr1, '-*', ... | ||
nlist, berr2, '-o'); | ||
legend('binary16', 'level index 2.12'); | ||
|
||
function y = mtimesv(A,x,options) | ||
[m,n] = size(A); | ||
y = zeros(m,1); | ||
for i=1:n | ||
y = cpfloat(y + cpfloat(A(:,i)*x(i), options), options); | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
BSD 2-Clause License | ||
|
||
Copyright (c) 2024, Mantas Mikaitis | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Oops, something went wrong.