Re: Why does Through unpack?
- To: mathgroup at smc.vnet.net
- Subject: [mg125609] Re: Why does Through unpack?
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Wed, 21 Mar 2012 05:47:13 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201203200720.CAA11907@smc.vnet.net>
- Reply-to: drmajorbob at yahoo.com
Your Through syntax is not right for what you seem to want, since operator precedence makes it equivalent to Through /@ ({Min, Max} /@ Transpose[dat]) But this is OK: On["Packing"] dat = RandomInteger[1*^7, {5000000, 2}]; {Min@#, Max@#} & /@ Transpose@dat // AbsoluteTiming // Quiet {0.158896, {{4, 9999996}, {1, 10000000}}} Min /@ Transpose@dat // AbsoluteTiming // Quiet {0.118989, {4, 1}} Max /@ Transpose@dat // AbsoluteTiming // Quiet {0.119237, {9999996, 10000000}} Your syntax gives Through /@ {Min, Max} /@ Transpose[dat] // AbsoluteTiming {1.575901, {{4, 9999996}, {1, 10000000}}} (Correct result, but slow.) Bobby On Tue, 20 Mar 2012 02:20:32 -0500, Szabolcs <szhorvat at gmail.com> wrote: > Consider the following example: > > On["Packing"] > > dat = RandomInteger[1*^7, {5000000, 2}]; > > Max /@ Transpose[dat]; // AsboluteTiming > > Note that the array is only unpacked to level 1, so Max is fast. > > Now let's get both the Min and the Max: > > Through /@ {Min, Max} /@ Transpose[dat]; // AbsoluteTiming > > Now the full array is unpacked, significantly hurting performance. > > Question: > > Why is it necessary to unpack the array when using Through? Here it > doesn't seem to be. Is it a design decision that Through unpacks, or is > it an over sight? Through does not touch the function argument (it only > affects the head), I don't see why it would need to unpack it. > -- DrMajorBob at yahoo.com
- References:
- Why does Through unpack?
- From: Szabolcs <szhorvat@gmail.com>
- Why does Through unpack?