Re: Compile problem: Mathematica 4
- To: mathgroup at smc.vnet.net
- Subject: [mg18792] Re: Compile problem: Mathematica 4
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Thu, 22 Jul 1999 08:19:17 -0400
- Organization: Universitaet Leipzig
- References: <7n13ce$be7@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi Paul, to do this is extem stupid but here is an example that work: f = Compile[{{x, _Real, 1}}, Module[{i, l = x}, i = Round[2.3]; l[[i]]++; Return[l]]] x = Table[i, {i, 4}]; f[x] {1., 3., 3., 4.} a) you need a l-value to make a assigment like x[[i]]. But x gets evaluated to a list and {1,2,4,5}[[i]] can't be assigned. A normal Mathematica function should have the attribute HoldFirst .. b) compile assume the type form the first assigment i. e. f = Compile[{{x, _Real, 1}}, Module[{i = 0.1, l = x}, i = Round[2.3]; l[[i]]++; Return[l]]] will generate an error f = Compile[{{x, _Real, 1}}, Module[{i = 1, l = x}, i = Round[2.3]; l[[i]]++; Return[l]]] works. Hope that helps. Jens Paul Howland wrote: > > Hi. > > What is wrong with the following (simplified) compile statement? It seems > that the Compiler doesn't recognise that Round[] returns an object with a > Head of Integer. Can I explicitly tell the compiler that this is the case? > > Thanks for help/comments in advance. > > Paul > > Code follows: > > In[4]:= > f=Compile[{{x, _Real,1}}, i=Round[2.3]; x[[i]]++;Return[x]] > > Compile::cpintlt: > i at position 2 of x[[i]] should be either a non-zero integer or a > vector of \ > non-zero integers; evaluation will use the uncompiled function." > > Out[4]= > CompiledFunction[{x},i=Round[2.3]; x[[i]]++;Return[x], -CompiledCode-] > > In[5]:= > Round[2.3] //Head > > Out[5]= > Integer