g = RandomGraph[{1000, 6000}];
NumberOfVertices = VertexCount @ g;
A = AdjacencyMatrix @ g;
ele = Flatten[A];
cnt = Length /@ A;
dsp = FoldList[Plus, 1, cnt];
fun = Compile[{{ele, _Integer, 1}, {cnt, _Integer, 1}, {dsp, _Integer,
1}, {n, _Integer}, {ccc, _Integer, 1}},
NestWhile[
Function[{cc},
Fold[Function[{c, v},
ReplacePart[c,
Module[{i,
com = Complement[Range[n],
c[[Take[ele, {dsp[[v]], dsp[[v]] + cnt[[v]] - 1}]]]]},
RandomChoice[Append[com, c[[v]]]]], v]], cc,
RandomSample[Range[NumberOfVertices], NumberOfVertices]]], ccc,
Max[#] > n &]];
fun[ele, cnt, dsp, 100, Range[NumberOfVertices]]
Its giving me the following warnings:
Compile::extscalar: Function[{cc},Fold[Function[{c,v},ReplacePart[c,Module[{i,com=Complement[<<2>>]},RandomChoice[Append[com,Part[<<2>>]]]],v]],cc,RandomSample[Range[NumberOfVertices],NumberOfVertices]]] cannot be compiled and will be evaluated externally. The result is assumed to be of type Real. >>
Compile::extscalar: Max[#1]>n& cannot be compiled and will be evaluated externally. The result is assumed to be of type Real. >>
NumberOfVerticesnot defined in your code? – J. M.♦ Nov 11 '12 at 3:10Compileis just not very effective for functional-style code, especially with nested scoping constructs. Essentially, the style that's most easily understood by the compiler is the polar opposite of what's needed for top-level code. You'll probably have more success if you rewrite in a more procedural style. – Oleksandr R. Nov 11 '12 at 10:03eleis a sparse array and is not among the supported types for compile.NestWhileisn't amongst the results forCompilerFunctions[]and I'm not certain butcccmight also be causing problems, perhaps to the function withccas it's parameter. – image_doctor Nov 11 '12 at 11:26