MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

ReplacePart and Compile

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88110] ReplacePart and Compile
  • From: Michael Weyrauch <michael.weyrauch at gmx.de>
  • Date: Fri, 25 Apr 2008 05:27:38 -0400 (EDT)
  • Reply-to: michael.weyrauch at gmx.de

Hello,

   in Mathematica 6.0 the syntax of the function ReplacePart[]
changed significantly as compared to earlier versions. While the "old"
syntax is not documented any more, it still seems to work in V6.0.2.1:

New syntax:

ReplacePart[{1, 2, 3}, 3 -> 1]

{1, 2, 1}

Old, now undocumented syntax:

ReplacePart[{1, 2, 3}, 1, 3]

{1, 2, 1}

Unfortunately, in compiled functions the new syntax does not seem
to work

Compile[{}, ReplacePart[{1, 2, 3}, 3 -> 1]] // InputForm

During evaluation of In[14]:= ReplacePart::argrx: ReplacePart called \
with 2 arguments; 3 arguments are expected. >>

CompiledFunction[{}, {{2, 1, 1}}, {0, 3, 0, 0, 2}, {{1, 5}, {45, {1, 2, 
3}, 2, 3, 0}, {54, Function[{}, 3 -> 1],2,0, 2}, {55, ReplacePart, 2, 1, 
0, 2, 0, 2, 2, 1, 1}, {2}}, Function[{}, ReplacePart[{1, 2, 3}, 3 -> 
1]], Evaluate]

while the old syntax produces nicely compiled code:

InputForm[Compile[{}, ReplacePart[{1, 2, 3}, 1, 3]]]

CompiledFunction[{}, {{2, 1, 0}}, {0, 2, 0, 0, 1}, {{1, 5}, {45, {1, 2, 
3}, 2, 3, 0}, {7, 3, 0}, {7, 1, 1}, {71, 0, 0, 0, 0, 1}, {2}}, 
Function[{}, ReplacePart[{1, 2, 3}, 1, 3]], Evaluate]

This situation is somewhat confusing (the error message seems to be 
clearly wrong) and either a bug or a misconception on my side?

Is it intended that the "new" ReplacePart cannot be compiled any more?
Is the documentation of ReplacePart in V6 incomplete, and should also
mention the old syntax?

(More generally: Could it be annotated in the documentation, which 
functions can be compiled and which functions cannot be compiled. For me
it is always an adventure to figure out a compiled version of a routine 
I need, because of this lack of basic information.)

Michael Weyrauch


  • Prev by Date: Re: Print[Plot] vs Print[text,Plot]?
  • Next by Date: Re: Wolfram User Interface Research?
  • Previous by thread: Re: HighlightedEdgeColors with Combinatoric`ShowGraph and AnimateGraph
  • Next by thread: Re: ReplacePart and Compile