RE: bug with Compile ?
- To: mathgroup at smc.vnet.net
- Subject: [mg26399] RE: [mg26374] bug with Compile ?
- From: "David Park" <djmp at earthlink.net>
- Date: Wed, 20 Dec 2000 00:21:27 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Jean-Marie, Defining your function in two steps seems to work. EuclidianDistance5 = Compile[{{p, _Real, 1}, {q, _Real, 1}}, With[{m = p - q}, Sqrt[m . m]]] CompiledFunction[] EuclidianDistance5a[p_List, q_List] := Check[EuclidianDistance5[p, q], $Failed] EuclidianDistance5a[{2, 3, 4}, {1, 2, 3}] 1.73205 EuclidianDistance5a[{2, 3, 4}, {1, 2, 3, 4}] CompiledFunction::"cflist": "Non-tensor object generated; proceeding with \ uncompiled evaluation." Thread::"tdlen": "Objects of unequal length in \!\(\(\({2, 3, 4}\)\) + \ \(\({\(\(-1\)\), \(\(-2\)\), \(\(-3\)\), \(\(-4\)\)}\)\)\) cannot be \ combined." $Failed Do[EuclidianDistance1[{2, 3, 4}, {1, 2, 3}], {10000}] // Timing {0.87 Second, Null} Do[EuclidianDistance5a[{2, 3, 4}, {1, 2, 3}], {10000}] // Timing {0.22 Second, Null} David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ > From: Jean-Marie THOMAS [mailto:jmt at agat.net] To: mathgroup at smc.vnet.net > $Version : "4.0 for Linux (April 21, 1999)" > > Implementing some basic functions, I get the following discrepancy : > > EuclidianDistance1[p_List, q_List] := > Check[With[{m = p - q}, N at Sqrt[m.m]], $Failed] > > EuclidianDistance3 := > Check[Compile[{{p, _Real, 1}, {q, _Real, 1}}, > With[{m = p - q}, Sqrt[m.m]]], $Failed] > > These two functions are ok, and the compiled form about four > times faster. > The Check prevents obviously inconsistent results to propagate, > like in the > following situation (two points in different dimensions) : > > EuclidianDistance1[{1., 2., 3.}, {1., 2., 3., 4.}] > Thread::"tdlen": "Objects of unequal length in \!\(\(\({1.`, 2.`, > 3.`}\)\) + \ > \(\({\(\(-1.`\)\), \(\(-2.`\)\), \(\(-3.`\)\), > \(\(-4.`\)\)}\)\)\) cannot be \ > combined." > Out[96]= > $Failed > > Which is what expected : the return value is $Failed > > Now : > EuclidianDistance3[{1., 2., 3.}, {1., 2., 3., 4.}] > > CompiledFunction::"cflist": "Non-tensor object generated; > proceeding with \ > uncompiled evaluation." > Thread::"tdlen": "Objects of unequal length in \!\(\(\({1.`, 2.`, > 3.`}\)\) + \ > \(\({\(\(-1.`\)\), \(\(-2.`\)\), \(\(-3.`\)\), > \(\(-4.`\)\)}\)\)\) cannot be \ > combined." > > \!\(\ at \(\(({1.`, 2.`, 3.`} + {\(-1.`\), \(-2.`\), \(-3.`\), > \(-4.`\)})\) . \ > \(({1.`, 2.`, 3.`} + {\(-1.`\), \(-2.`\), \(-3.`\), \(-4.`\)})\)\)\) > > The return value is in this case an unevaluated expression, while > $Failed is > expected. > > Bug ? > >