MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Ver 6.0 Subsets and Packed Array Question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82448] Re: Ver 6.0 Subsets and Packed Array Question
  • From: "Dana DeLouis" <dana.del at gmail.com>
  • Date: Sat, 20 Oct 2007 05:57:55 -0400 (EDT)

Just to add, I came accross the "PackedArrayOptions" listed below.
I guess the question is why does Subsets start out packed, and then UnPacks?
Seems to me it could stay packed ??
I wonder how KSubsets keeps it packed?
Suppose one is working with Subsets[Range[49], {6}];

What I observe now is that KSubsets is slow, but stays Packed so it fits in
memory.
Subsets is very fast, but Unpacks, and takes all the memory.
Hmmm.
What I'm thinking is that Subsets makes the "assumption" that all elements
are not of the same type ??


TPA[m_] := Developer`ToPackedArray[m]

PAQ[m_] := Developer`PackedArrayQ[m]

SetSystemOptions["PackedArrayOptions" -> {"UnpackMessage" -> True}]; 

ss = Subsets[Range[5], {3}]

Developer`FromPackedArray::punpack1:Unpacking array to level 1.

{{1, 2, 3}, {1, 2, 4}, ...etc {3, 4, 5}}

So, it was packed, but for some reason, Mathematica decided to UnPack   it
despite that all elements are small integers.

PAQ[ss]
False

ByteCount[ss]
864

But it could have stayed packed??

ByteCount[TPA[ss]]
200

Thanks for any insight.
-- 
Dana DeLouis
Windows XP & Mathematica 6.0


"Dana DeLouis" <dana.del at gmail.com> wrote in message
news:ff9t7l$6e6$1 at smc.vnet.net...
> 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: Hankel transform question
  • Next by Date: Re: Help with NMinimize
  • Previous by thread: Re: Ver 6.0 Subsets and Packed Array Question
  • Next by thread: Creating a popup menubox in a specified notebook