Re: data types
- From: Walter Roberson <roberson@xxxxxxxxxxxx>
- Date: Tue, 04 Nov 2008 10:36:22 -0600
Jens Koopmann wrote:
I am not sure if that is possible in Matlab, but in a few other languages it is possible to
assign a datatyp to a variable which in turn can accelerate the calculations.
In my case I want some variable to be single, which should run slightly faster than using
them in doube.
I tried to the single() command,
single() does return a value in single precision, and Matlab will know the variable is
single precision and will operate in single precision when doing operations between
single precision (but if you are doing an operation that involves a mix of single
and double precision, the highest precision will be used and then the value will
be rounded into the lowest precision.)
but that made the program run slower.
There are a number of CPU architecture reasons why single precision operations are
not certain to be faster than double precision. I can point to some models in which
single precision was slower at the hardware level than double precision even when
working in pure single precision.
Matlab is able to recognize certain patterns of operations with multiple operators
(e.g., A * B + C can, on most architectures, be processed much more efficiently than
t1 = A * B; t2 = t1 + C;). When it recognizes these patterns, and the matrices are
sufficiently large, it hands the operations over to libraries such as BLAS, which have
been heavily optimized for the specific CPU. However, when you use single precision,
even if the hardware is in theory capable of doing each -individual- operation faster,
if Matlab does not recognize the pattern, or if Matlab does not have a BLAS library
entry for that combination of operations and precisions, then Matlab will fall back to
the "obvious" way of processing the operations -- which could turn out to be much slower
than if you had used double precision and Matlab had a BLAS entry for the double
precision pattern.
--
..signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?
.
- Follow-Ups:
- Re: data types
- From: Jens Koopmann
- Re: data types
- References:
- data types
- From: Jens Koopmann
- data types
- Prev by Date: Re: Read in .DAT files
- Next by Date: matrix of a binary labeled image
- Previous by thread: data types
- Next by thread: Re: data types
- Index(es):
Relevant Pages
|