Single precision floating point numbers reduce memory consumption by 50% compared to the default double precision numbers. In addition, the processing time is reduced by up to 50%. Single precision numbers are a primitive data type in MATLAB. Array indexing and permutation, sorting and comparisons are supported as for any primitive data type. However, MATLAB 6.x has no built-in math support. This package contains a collection of the most basic math operations enabling to calculate with single precision numbers in MATLAB 6.x.
Unpack the archive in a folder that is part of the MATLAB path.
The subfolder '@double' contains libraries that directly overload some built-in functions.
single returns an empty single array if called without any input argument, which is needed for accessing single precision constants. The other functions are constants used with the fast Fourier transform kernel. Please look at
sfftw for detailed information.
The subfolder '@single' contains libraries supporting single precision math operations. All elementary math operations as well as the matrix product are provided. However, other matrix operations are currently delegated to the built-in double precision operations.
Do not rename the subfolders for making sure that the functions are called for the correct data type. If not needed, the functions do not check the data type of passed arguments.
The results of the single precision functions slightly differ from the built-in functions. On one hand, the accuracy of complex elementary functions benefits from the floating-point registers with a 64bit mantissa on Intel processors. Intermediate values are kept in floating-point registers such that rounding takes place mostly once. On the other hand, the rounding error is larger due to the 24bit mantissa of single precision numbers.
In general, a statement of
value with a relative error of less than 1.0E-5. The roundoff error of about 1.2E-8 leads to relatively important deviations in exponentiation. Note also that in particular addition/subtraction in the argument of a logarithm are critical operations due to a relative amplification of the rounding error. The logarithm itself works accurate over the full complex plane R x iR. For the sake of performance, the inverse transcendental functions are currently not implemented in that way. See also the summary about complex functions.
The class provides access to single precision constants. For a built-in function, MATLAB calls always the double precision function whenever no input argument is given. To get an
single constant, use:
||uniformly distributed random number|
||normally distributed random number|
For periodic transcendental functions, the constant 2pi is truncated to a 24bit mantissa. This guarantees that a statement of the form
sin(x) with real
x always produces the expected value
sin(rem(x,2*pi)) at the same accuracy. The reminder is always computed explicitly and prescaled to a 64bit mantissa.
x=pow2(pi,0:256); plot(x,builtin('sin',x),'r',x,sin(x),'b'); set(gca,'XScale','log');
The matrix product was manually implemented instead of using the ATLAS package. The performance is higher on small matrices, comparable on medium sized matrices and about 10% slower on very large matrices. The main advantage of the manual implementation is its small size of 23kBytes instead of at least 500kBytes with ATLAS.
These routines are published as freeware. The author reserves the right to modify any of the contained files.
You are allowed to distribute this package as long as you deliver the entire, original package for free.
Any warranty is strictly refused. Don't rely on any financial or technical support in case of malfunction or damage.
Comments are welcome. I will try to track reported problems and fix bugs.
Optimized routine for calculating the exponential according to Agner Fog, "Optimizing subroutines in assembly language," at Copenhagen University College of Engineering.
Downloading these files, you accept the copyright terms.
MATLAB is a registered trademark of The MathWorks, Inc. Pentium II is a registered trademark of Intel Corporation. Other product or brand names are trademarks or registered trademarks of their respective holders.
© 2011 École Polytechnique Fédérale de Lausanne