Ver 6.0 Subsets and Packed Array Question

• To: mathgroup at smc.vnet.net
• Subject: [mg82405] Ver 6.0 Subsets and Packed Array Question
• From: "Dana DeLouis" <dana.del at gmail.com>
• Date: Fri, 19 Oct 2007 05:05:02 -0400 (EDT)

```Hello.  Does anyone know why the built in function Subsets "apparently" does
not generate a Packed Array for a large table?  Do you think it should?  The
reason I ask is that the Combinatorica Package function "KSubsets"
apparently does return a packed array.
I was having memory troubles with Subsets, and I traced the problem back to
this.

Set up (Ver 6.0)...

Needs["Combinatorica`"];
TPA[m_] := Developer`ToPackedArray[m];
PAQ[m_] := Developer`PackedArrayQ[m];

n = Binomial[20, 6]
38760

Here are 3 tables w/ the same dimension:

m1 = RandomInteger[{1, 49}, {n, 6}];
m2 = KSubsets[Range[20], 6];
m3 = Subsets[Range[20], {6}];

Dimensions /@ {m1, m2, m3}

{{38760, 6}, {38760, 6}, {38760, 6}}

The first two are Packed Arrays, but the built-in function "Subsets" is not:

PAQ /@ {m1, m2, m3}

{True, True, False}

The ByteCount of the built-in function is much larger:

ByteCount /@ {m1, m2, m3}

{930320, 930320, 5736512}

We could make it a Packed Array and get the same ByteCount:

ByteCount[TPA[m3]]
930320

This makes a big difference on my 2 Gig Memory computer.  Don't know how I
even got an answer here.  I can't do anything else after this point without
shutting down the Kernel.

ByteCount[KSubsets[Range[49], 6]]  (* ok *)

335,611,664

ByteCount[Subsets[Range[49], {6}]]  (* This is tough!! *)

2,069,604,800

Thanks for any insight:
Dana

```

• Prev by Date: Re: ListLinePlot[] inside a loop
• Next by Date: Re: Setting up external functions to be called from Mathematica
• Previous by thread: Controlling StepLeftButton and StepRightButton in Animator
• Next by thread: Re: Ver 6.0 Subsets and Packed Array Question