MathGroup Archive 2014

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

Search the Archive

Re: Mapping tag-value lists to a third

  • To: mathgroup at smc.vnet.net
  • Subject: [mg132460] Re: Mapping tag-value lists to a third
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Sat, 22 Mar 2014 00:06:01 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net

----- carlos felippa%colorado edu <carlos.felippa%colorado.edu at gtempaccount.com> wrote:
> 
> Thanks to all who replied.  For now I have implemented it as
> 
> tagval=If [$VersionNumber>=5.1,Pick[val,tag,1],val*tag/. 0:>Sequence[]];
> 
> For big lists, Pick is slightly faster. Eg, for 10^7 length, on a MacPro:
> 
>      Pick 1.45 sec    Sequence: 1.72 sec
> 
> The reason for $VersionNumber is that Pick appeared in 5.1. Some
> users of my Mathematica codes are colleagues living overseas who run
> version 4 on old computers.  

For v4 users,  

  val*tag/. 0:> Sequence[]  

requires that val have no zeros. However,

  val[[ tag*Range@Length@tag/. 0:>Sequence[] ]]

has no such condition and may be faster when val is real.

For v5+ users,

  val[[ SparseArray[tag] /. 
  SparseArray[_,_,_,d_] :> Flatten@d[[2,2]] ]]

may be faster than Pick[val,tag,1].



  • Prev by Date: Re: EventHandler in Graphics
  • Next by Date: Problems with Solve
  • Previous by thread: Re: Mapping tag-value lists to a third
  • Next by thread: Re: Mapping tag-value lists to a third