I'm trying to optimize code that uses Position MANY times.
The following toy code works:
list1 = RandomInteger[{1, 10000}, 500000];
list2 = RandomInteger[{1, 10000}, {3, 500}];
test = ParallelTable[
Flatten[
Map[
Position[list1, #] &, list2[[i]]
]
], {i, 1, Length[list2]}];
My trouble begins because I have so much data to process. When I use my actual data in the code above, Mathematica takes 34 minutes to complete the computation. This is just too long to be practical, so I began exploring Compile.
When I try this:
test2 =
Compile[{{list1, _Integer, 1}, {list2, _Integer, 2}},
Table[
Flatten[
Map[
Position[list1, #] &, list2[[i]]
]
], {i, 1, Length[list2]}]];
wow = test2[list1, list2]
CompiledFunction::cflist: Nontensor object generated; proceeding with uncompiled evaluation.
You can see that Mathematica complains.
My questions are:
How can I debug what the problem is in the Compiled statement above? I really don't know how to start figuring out the problem.
Is there an obvious alternative to using Position that itself would be faster than Position?
I am not new to Mathematica, but I admit to being completely new to compiling code.
Any thoughts?


