Mathematica 9 is now available
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

Compile&Which

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66007] Compile&Which
  • From: gregorc <gregor.cernivec at fe.uni-lj.si>
  • Date: Wed, 26 Apr 2006 04:38:23 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

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



  • Prev by Date: Re: Where do I put my own add-on packages?
  • Next by Date: Re: Periodic Rebirth of Hyperbolic Functions by ODE in Mathematica
  • Previous by thread: Re: Illusory Multicore Support in 5.2?
  • Next by thread: Re: Compile&Which