Extensive Improvements in Speed and Efficiency in Numerical Calculation
Packed Array Technology
Perhaps the single most important breakthrough in Mathematica 4 is the
introduction of packed array technology. Packed arrays represent a fast and efficient
method for storing and performing repetitive operations on large lists, matrices, and
tensors of numerical values--integer, real, or complex--when Mathematica
determines it is feasible to do so. (The primary constraint is that the numbers be
machine-sized--that is, of a size that can be operated on directly by the computer's
floating-point hardware, as is the case of the vast majority of calculations in, say,
statistical analysis or mechanical engineering.)
Packed array technology is transparent to the user. Mathematica will choose when
to use packed arrays internally, without the need for the user to specify it. Of course,
the user also has the ability to override these choices using the functions ToPackedArray
and FromPackedArray, available in the Developer`
context.
What are the chief benefits of packed array technology? Memory efficiency and speed. We
can demonstrate this by comparing the performance of Mathematica 4 with Mathematica
3 attacking the same calculations.
Here are the results of some large calculations using Mathematica 3. First, a
400 × 400 array of random real numbers is created, requiring over three million bytes of
memory. Then Mathematica adds a scalar 1 to all 4002 = 160000 elements
of the matrix, and then raises that matrix to the thousandth power. Finally, Mathematica
creates a list of one million random real numbers, and then sorts the list.
In this case, the matrix calculation took Mathematica 3 several seconds, and
sorting one million random real numbers took over half a minute. Compare the results of
the same tests on the same machine using Mathematica 4 packed arrays.
The sort is nearly six times faster, and the matrix exponentiation takes less
than one-twentieth of the time. Additionally, Mathematica 4 needed less than half
the memory to store the large matrix. Note also that the user didn't need to specify the
use of packed arrays; Mathematica simply knew that it should.
The twin benefits of packed array technology--faster numeric results and the ability
to treat larger calculations--greatly expands Mathematica's usefulness as a tool
for engineering design and data analysis.
|