Consider the following code:
comp1 = Compile[{{acccolumns, _Integer, 2}}, Module[{acccols, ncols},
ncols = Length[acccolumns[[1]]];
acccols = acccolumns;
Do[Do[
Compile`GetElement[acccols, j, i] == RandomInteger[{0, 1}], {i,
1, ncols, 1}], {j, 1, Length[acccols], 1}];
acccols], CompilationTarget -> "C", RuntimeOptions -> "Speed",
RuntimeAttributes -> {Listable}]
It should take some table acccolumns
, replace each of its elements with 0 or 1, and then return the changed table. In reality, it does not work: for
ncols = 4;
acccolumns1 = Table[1, ncols];
acccolumns = Table[acccolumns1, 10];
the evalution
comp1[acccolumns]
returns acccolumns
. Could you please tell me where I made a mistake and how to fix it still being inside the compiled code?
Compile`GetElement
is a getter-function, not a setter-function. SinceCompile`SetElement
does not exist, you have to usePart
as in ordinary Mathematica code. Moreover,Compile
does not allow call by reference, so you cannot modify the input array. (LibraryLink allows this however.) $\endgroup$