6
$\begingroup$
Outer[Plus, ##] & @@ Array[{1, 2, 6, 24, 120, 720, 5040, 40320, 362880} &, 6]; // AbsoluteTiming
(* {0.979056, Null} *)

Outer[Plus, ##] & @@ Array[Range[9]! &, 6]; // AbsoluteTiming
(* {0.952055, Null} *)

Outer[Plus, ##] & @@ Array[Gamma[Range@9 + 1] &, 6]; // AbsoluteTiming
(* {0.010001, Null} *)

See the elapsed time, I used v9 on Win7 32bit. On v8, both of them are slow. How to explain this? Is it possible to make it faster on v8?

$\endgroup$
0

1 Answer 1

7
$\begingroup$

I actually get the same timing for all three versions (using v7), but this is almost certainly a matter of packing. You can use Developer`ToPackedArray to convert your sub-arrays, as well as Developer`PackedArrayQ to check their status.

In this case on my system:

set = {1, 2, 6, 24, 120, 720, 5040, 40320, 362880};
packed = Developer`ToPackedArray[set];

Outer[Plus, ##] & @@ Table[set, {6}];    // AbsoluteTiming
Outer[Plus, ##] & @@ Table[packed, {6}]; // AbsoluteTiming
{0.2300003, Null}

{0., Null}

Another example:

a = Array[#2! &, {6, 9}];
Developer`PackedArrayQ /@ a
{False, False, False, False, False, False}
b = Developer`ToPackedArray[a];
Developer`PackedArrayQ /@ b
{True, True, True, True, True, True}
Outer[Plus, ##] & @@ a; // AbsoluteTiming
Outer[Plus, ##] & @@ b; // AbsoluteTiming
{0.2400004, Null}

{0., Null}

Note that you will not be able to pack a list or array that contains integers larger than the maximum machine-size integer on your system.

$\endgroup$

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .