When Do You Get Packed Arrays?
When trying to write efficient programs, this is a very important question. There are three important situations that commonly produce packed arrays.
1. Listable and structural operations with packed array input (where the output can be a packed array).
By listable operations, I mean those with the attribute
Listable. All of the elementary functions of this type will produce packed arrays given packed array arguments. These are operations such as
Cos, and so on.
By structural operations, I mean commands like
Transpose, etc., which act on the structure of an expression.
2. Functions which use an internal array format for machine numbers.
Fourier is a good example of a function that uses an internal array format for machine numbers.
Whether the input is a packed array or not, if
Fourier does its computation with machine numbers, it internally uses arrays already, so it is natural to give the output in terms of a packed array.
3. Functions which can quickly determine from simple input that the output could be a packed array.
I have already used one example in this class,
Range, it is pretty easy to see before generating any numbers that the result can be represented as a packed array.
For something like the following it is a little more difficult to determine.
Commands like this are handled by auto-compilation. However, since trying the compiler does take some time, there is a (user modifiable) threshold length which must be exceeded before compilation is attempted.
Converted by Mathematica
May 1, 2000
[Prev Page][Next Page]