Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Inconsistent Compile Behavior in 4.0.1.0' topicStudent Support Forum > General > "Inconsistent Compile Behavior in 4.0.1.0"

Next Comment >Help | Reply To Topic
Author Comment/Response
Robert Young
07/12/00 08:40am

I'm using Compile to speed the operation of some calculations in Mathematica 4.0.1.0 for Windows, but one of my compiled functions behaves strangely.
This is my function:
simsignum =
Compile[{{mat, _Integer, 2}, {sigs, _Integer, 3}, {perms, _Integer, 3}},
Flatten[Map[{FromDigits[Flatten[Transpose[#]] + 1, 3],
FromDigits[Flatten[#] + 1, 3], FromDigits[Flatten[-#] + 1, 3],
FromDigits[Flatten[-Transpose[#]] + 1, 3]} &,
Flatten[Map[Function[ma, Map[Dot[Transpose[#1], ma, #1] &, sigs]],
Map[Dot[Transpose[#1], mat, #1] &, perms]], 1]],
1], {{_FromDigits, _Integer}}];
If left uncompiled, it's:
simsignum2[mat_, sigs_, perms_] :=
Flatten[Map[{FromDigits[Flatten[Transpose[#]] + 1, 3],
FromDigits[Flatten[#] + 1, 3], FromDigits[Flatten[-#] + 1, 3],
FromDigits[Flatten[-Transpose[#]] + 1, 3]} &,
Flatten[Map[Function[ma, Map[Dot[Transpose[#1], ma, #1] &, sigs]],
Map[Dot[Transpose[#1], mat, #1] &, perms]], 1]], 1];
It compiles without giving any warnings, but evaluating the two on the same arguments gives different results:
In[179]:=
simsignum[{{-1, -1, -1, -1}, {-1, 0, 0, 1}, {0, 0, -1, 1}, {1, 0, 0,
1}}, {IdentityMatrix[4]}, {IdentityMatrix[4]}]

Out[179]=
{2743334, 95000, 42951720, 40301157}

In[180]:=
simsignum2[{{-1, -1, -1, -1}, {-1, 0, 0, 1}, {0, 0, -1, 1}, {1, 0, 0,
1}}, {IdentityMatrix[4]}, {IdentityMatrix[4]}]

Out[180]=
{2743334, 95000, 42951720, 40303386}

Moreover, making minor changes to the function, like changing
FromDigits[Flatten[-Transpose[#]] + 1, 3]
to
FromDigits[Flatten[Transpose[-#]] + 1, 3]
seems to eliminate the error.
What's going on?

URL: ,

Subject (listing for 'Inconsistent Compile Behavior in 4.0.1.0')
Author Date Posted
Inconsistent Compile Behavior in 4.0.1.0 Robert Young 07/12/00 08:40am
Re: Inconsistent Compile Behavior in 4.0.1.0 Forum Modera... 07/12/00 08:48am
Re: Inconsistent Compile Behavior in 4.0.1.0 Forum Modera... 07/18/00 09:12am
Next Comment >Help | Reply To Topic