Skip to content

Commit 1009ea1

Browse files
committed
Initial commit
0 parents  commit 1009ea1

File tree

10 files changed

+1375
-0
lines changed

10 files changed

+1375
-0
lines changed

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# level-index-simulator
2+
3+
# `sli` - A custom precision MATLAB symmetric level-index arithmetic simulator.
4+
5+
## About
6+
7+
`sli` is a MATLAB toolbox that provides sli objects and operations on them.
8+
9+
* [sli.m](sli.m) - the main object file.
10+
* [tests](./tests) - various testing scripts that test the accuracy of representation and operations.
11+
* [experiments](./experiments) - scripts to reproduce the experiments with level-index arithmetic in [1].
12+
13+
[![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)
14+
15+
## Quick start
16+
17+
```
18+
x = sli(2,12);
19+
x = x.set_val(pi)
20+
x =
21+
22+
sli with properties:
23+
24+
level_bits: 2
25+
index_bits: 12
26+
sign: 0
27+
reciprocal: 1
28+
level: 2
29+
index: 0.135253906250000
30+
value: 3.141899100868418
31+
```
32+
33+
### Installation
34+
35+
Clone the repository and add the root directory to the MATLAB search path.
36+
37+
## Requirements
38+
39+
The code was developed on MATLAB 2023b. Experiments make use of the [CPFloat](https://github.com/north-numerical-computing/cpfloat) package.
40+
41+
## References
42+
43+
[1] Mantas Mikaitis. [*MATLAB Simulator of Level-Index Arithmetic*](https://). In Prep., Feb. 2024.
44+
45+
## Licence
46+
47+
The code is distributed under the terms of the BSD 2-Clause License;
48+
see [license.txt](license.txt).
49+
BBB

experiments/matvec.m

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
% Compare matrix-vector product accuracy in floating-point and
2+
% level-index arithmetics.
3+
%
4+
% References
5+
%
6+
% M. Mikaitis, MATLAB Simulator of Level Index Arithmetic, In Prep., 2024.
7+
8+
clear all;
9+
10+
nlist = round(logspace(1,4,20));
11+
12+
% Set up cpfloat options
13+
options.format = 'fp16';
14+
options.round = 1;
15+
options.explim = 1;
16+
cpfloat([], options);
17+
k = 0;
18+
19+
for n = nlist
20+
k = k + 1;
21+
fprintf('k = %2d, n = %7d\n',k,n);
22+
A = rand(10,n)*100;
23+
x = rand(n,1);
24+
25+
% Set up SLI vectors
26+
Asli = zeros(10, n, 2, 12, 'sli');
27+
xsli = zeros(n, 1, 2, 12, 'sli');
28+
29+
% Convert vectors to SLI
30+
for j = 1:numel(A)
31+
Asli(j) = Asli(j).set_val(A(j));
32+
end
33+
for j = 1:numel(x)
34+
xsli(j) = xsli(j).set_val(x(j));
35+
end
36+
37+
% Double reference result
38+
ye = A*x;
39+
absAx = abs(A)*abs(x);
40+
41+
% Binary16 result
42+
y1 = mtimesv(A,x,options);
43+
berr1(k) = max(abs(ye-y1)./absAx);
44+
45+
% Level index 2.12
46+
y2 = Asli*xsli;
47+
berr2(k) = max(abs(ye-[y2.value]')./absAx);
48+
end
49+
50+
filename = sprintf('matvec_binary16_1.dat');
51+
fid = fopen(filename, 'w');
52+
for i=1:length(nlist)
53+
fprintf(fid, "%d %f %f\n", nlist(i), berr1(i), berr2(i));
54+
end
55+
fclose(fid);
56+
57+
loglog(nlist, berr1, '-*', ...
58+
nlist, berr2, '-o');
59+
legend('binary16', 'level index 2.12');
60+
61+
function y = mtimesv(A,x,options)
62+
[m,n] = size(A);
63+
y = zeros(m,1);
64+
for i=1:n
65+
y = cpfloat(y + cpfloat(A(:,i)*x(i), options), options);
66+
end
67+
end

license.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
BSD 2-Clause License
2+
3+
Copyright (c) 2024, Mantas Mikaitis
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)