Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: Re: Compile&Which

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66066] Re: [mg66015] Re: Compile&Which
  • From: gregorc <gregor.cernivec at fe.uni-lj.si>
  • Date: Fri, 28 Apr 2006 06:33:07 -0400 (EDT)
  • References: <e2ne3s$3b7$1@smc.vnet.net> <200604270625.CAA29166@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Jens-Peer Kuska wrote:

>Hi,
>
>Compile[] don't know what Which[] returns and
>r = Compile[{{x, _Real, 1}},
>
>      Block[{l1 = {0.}},
>        Which[x[[1]] == x[[2]], l1 = f[x] + g[x],
>              x[[1]] < x[[2]], l1 = f[x] - g[x]];
>
>        l1], {{f[_], _Real, 1}, {g[_], _Real, 1}}]
>
>work fine.
>
>Regards
>
> Jens
>
>
>
>"gregorc" <gregor.cernivec at fe.uni-lj.si> schrieb 
>im Newsbeitrag news:e2ne3s$3b7$1 at smc.vnet.net...
>| Hello,
>|
>| I have trouble to understand how does the 
>Compile function handle the
>| Which statement. Following  there are two 
>examples (just as
>| ilustration), both are compiled OK, but the 
>second one does not evaluate
>| as a compiled expression. Can someone explain 
>the evaluation error? It
>| is probably because the Which statement, but I 
>do not know how to do
>| this correctly. Much thanks!
>|
>| 1st example:
>|
>| f = Compile[{{x, _Real, 1}}, {x[[1]]}];
>| g = Compile[{{x, _Real, 1}}, {x[[2]]}];
>| r = Compile[{{x, _Real, 1}}, f[x] + g[x], 
>{{f[x], _Real, 1}, {g[x],
>| _Real, 1}}]
>| CompiledFunction[{x}, f[x] + 
>g[x], -CompiledCode-]
>| r[{3, 4}]
>| {7.}
>|
>| 2nd example:
>|
>| f = Compile[{{x, _Real, 1}}, {x[[1]]}];
>| g = Compile[{{x, _Real, 1}}, {x[[2]]}];
>| r = Compile[{{x, _Real, 1}}, Which[x[[1]] ? 
>x[[2]], f[x] +g[x], x[[1]] <
>| x[[2]], f[x] -g[x]], {{f[x], _Real, 1}, {g[x], 
>_Real, 1}}]
>| CompiledFunction[{x}, Which[x?1? ? x?2?, f[x] + 
>g[x], x?1? < x?2?, f[x]
>| - g[x]], -CompiledCode-]
>| r[{3, 4}]
>| CompiledFunction::cfse: Compiled expression 
>{-1.} should be a
>| machine-size \real number.
>| CompiledFunction::cfex: External evaluation 
>error at instruction 2;
>| \proceeding with uncompiled evaluation.
>| {-1.}
>|
>| Thanks,
>|
>| Cernivec Gregor
>|
>| 
>
>
>
>__________ NOD32 1.1509 (20060427) Information __________
>
>This message was checked by NOD32 antivirus system.
>http://www.eset.com
>
>
>
>  
>
Thank you very much. It realy works ok!

With best regards,

gregor


  • References:
  • Prev by Date: Re: DiscreteMath question : ToAdjacencyMatrix and FromAdjacencyMatrix
  • Next by Date: Displaying Branch Cuts with ContourPlot
  • Previous by thread: Re: Compile&Which
  • Next by thread: Re: Compile&Which