Function compile problems

• To: mathgroup at smc.vnet.net
• Subject: [mg26128] Function compile problems
• From: "Krautschik, Chris G" <krautschikc at intel.co.jp>
• Date: Tue, 28 Nov 2000 01:56:16 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

I understand that the compile function can be very tricky as not all
Mathematica commands are supported by the Compile function.  I have the
following code that seems to work fine when not compiled:

n = 4; g[{r_, t_}] := r Cos[n t];
xy = Table[{x, y}, {x, -1, 1, 0.5}, {y, 1, -1, -0.5}];
Map[g[#] &, xy, {2}] // N

The output should look as follows:
{{0.653644, 0.416147, -1., 0.416147, 0.653644}, {0.326822, 0.208073, -0.5,
0.208073, 0.326822}, {0., 0., 0., 0., 0.}, {-0.326822, -0.208073,
0.5, -0.208073, -0.326822}, {-0.653644, -0.416147,
1., -0.416147, -0.653644}}

Now if I compile the same code through the following program:

test1 = Compile[{{n, _Integer}},
g[{r_, t_}] := r Cos[n t];
xy = Table[{x, y}, {x, -1, 1, 0.5}, {y, 1, -1, -0.5}];
Map[g[#] &, xy, {2}]//N
];

test1[4], I get the following error message:

CompiledFunction::"cfte": "Compiled expression  0.6536436208636119
should be a rank 1 tensor of  "machine-size real numbers."

CompiledFunction::"cfex": "External evaluation error at instruction 17;
proceeding with uncompiled evaluation."

{{0.653644, 0.416147, -1., 0.416147, 0.653644}, {0.326822, 0.208073, -0.5,
0.208073, 0.326822}, {0., 0., 0., 0., 0.}, {-0.326822, -0.208073,
0.5, -0.208073, -0.326822}, {-0.653644, -0.416147,
1., -0.416147, -0.653644}}

While the output is correct the program was never excecuted in compiled mode
therefore defeating the whole purpose of compiling in the first place.

Now, if I had used h[x_,y_]:=r Cos[ n t]  instead of g and then
Apply[h[#1,#2]&,xy{2}]//N  (instead of the Map command) then the program
doesn't run at all in compiled form, although, it works fine in uncompiled
form.

Any idea of what's going on here?

Thanks,
Chris

• Prev by Date: Re: Bug: Mathematica 4.0 vs. Win2k on ThinkPad
• Next by Date: How to plot field lines of conformal mapping
• Previous by thread: Re: "up" in 3D animations
• Next by thread: Re:Function compile problems