Hi,
I have a notebook containing four Do
... loops nested into each other In the very inner loop I would like to use a previously defined CompiledFunction
. The data to be used by the CompiledFunction
generated in the second inner loop. So, the structure is something like this:
(* set some variables and constants *)
.....
....
(* First loop *)
Do[
(* Second Loop *)
Do[
(* more variables and constants *)
....
.....
(* Define compiled function *)
cIfs = Compile[{{comp, _Integer}, {day, _Integer}, {pstockf, _Integer}},
Module[{lstockf = pstockf},
......
];
];
(* Third loop *)
Do[
(* set some variable for fourth loop *)
....
(* Fourth Loop *)
Do[
(* Set some variables and do some calculations *)
....
kstockf=stockf[[k]];
(* Call the compiled function *)
stocks[[k]]=cIfs[k,l,kstockf];
...
];
..
];
...
];
..
];
I put the definition of the CompiledFunction
in the second loop, because most of the data needed for it is ready before the inner two loops are started. Of course I would rather see this definition after the main body of the program as a subprogram and I was considering Packages, but I gave up on it, because all the examples I see in the Document do not call for it.
However when I evaluate the notebook I am getting this error
Compile::cptype : List is not supported for type Void; evaluation will use the uncompiled function.
I am passing just three Integer
s in the format as Compile
requires. All variables before the Do
s are global and the variables inside the Do
s are local to their Do
. The innermost Do
's variables see the other variables as globals, etc....
So what am I doing wrong?
What would be the right way to define the CompiledFunction
outside of the loops, but still inside the same notebook?
Thanks ahead,
János