1
$\begingroup$

Considering mathematica code

range = Range[4 10^6];
Position[Mod[10^5 NestList[Mod[ 10^6 #, 1355297] &, 10^6,Length[#] - 1] - (54 # + 46), 1355297], 0] &[range]
(* {{2331259}, {3776127}} *)

which works as expected I intend (performance issue)to compile the code. All the functions involved are compilable as

Compile`CompilerFunctions[] // Sort

shows but the approach

fu = Compile[{{range, _Integer, 1}},Position[Mod[10^5 NestList[Mod[ 10^6    range, 1355297] &, 10^6,Length[range] - 1] - (54 range + 46), 1355297], 0]]
(*Compile::cset: Variable Compile`Variable$630 of type 
{_Integer,0}    encountered in assignment of type {_Integer,1}. *)

doesn't work. Checking the compiled code

Needs["CompiledFunctionTools`"]
CompilePrint[fu]

I recognize, that NestList doesn't appear!!

My questions: Is NestList compilable ? Is there a workaround to make the compile-code run? Thanks

$\endgroup$

1 Answer 1

5
$\begingroup$

Don't you want this?:

fu = Compile[{{range, _Integer, 1}}, 
  Position[Mod[
    10^5 NestList[
       Mod[10^6 #, 1355297] &,  (* N.B. range -> # *)
       10^6, 
       Length[range] - 1] - (54 range + 46), 1355297], 0]]
$\endgroup$
1
  • $\begingroup$ Yes , thank you! Silly mistake... $\endgroup$ Commented Feb 13, 2018 at 14:52

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.