Re: Compile&Which
- To: mathgroup at smc.vnet.net
- Subject: [mg66015] Re: Compile&Which
- From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
- Date: Thu, 27 Apr 2006 02:25:58 -0400 (EDT)
- Organization: Uni Leipzig
- References: <e2ne3s$3b7$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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 | |
- Follow-Ups:
- Re: Re: Compile&Which
- From: gregorc <gregor.cernivec@fe.uni-lj.si>
- Re: Re: Compile&Which