Given
lyapexp[n_] := (Hold[Compile[{{kMin, _Integer}, tol, r, u0, u1},
Module[{
relErr, ohs,
res = {0., 0.},
hs = Table[.0, {n}],
k = 0,
nzs = Table[.0, {n}],
ss = Table[.0, {n}],
ws = IdentityMatrix[n]/2,
zs = IdentityMatrix[n]/2,
success = 1.0,
uPrev = u0,
uCurr = u1
},
While[True,
k++;
zs = Dnn[r, uCurr, uPrev].ws;
Do[
(Module[{nzi},
Do[(
zi -= zi.zj/Norm[zj, 2] zj) /. zj :> zs[[1 ;; n, j]]
, {j, i - 1}];
nzi = Norm[zi];
nzs[[i]] = nzi;
ws[[1 ;; n, i]] = zi/nzi]) /. zi :> zs[[1 ;; n, i]]
, {i, n}];
ohs = hs;
ss += Log[nzs];
hs = ss/k;
relErr = Norm && relErr < tol,
res = {hs, 1.0};
Break[];
];
{uCurr, uPrev, success} = nn[r, uCurr, uPrev, success];
If[success == 0,
res = {0., 0.};
Break[];
];
];
res
], CompilationOptions -> {"InlineExternalDefinitions" -> True},
RuntimeOptions -> "Speed",
CompilationTarget -> "C"]] //. {Pattern[p, _IdentityMatrix] :>
Block[{}, p /; True],
HoldPattern[e_ /. (p_ :> r_)] :>
Block[{}, (Hold[e] /. p :> r) /; True]}) //.
HoldPattern[Hold[expr_]] :> expr
why is MainEvaluate
used in CompilePrint[lyapexp[2]]
?
EDIT
Now (after SetSystemOptions["CompileOptions" -> "CompileReportExternal" -> True]
) it's
lyapexp[n_] := (Hold[Compile[{{kMin, _Integer}, tol, r, u0, u1},
Module[{
relErr, ohs,
res = {0., 0.},
hs = Table[.0, {n}],
k = 0,
nzs = Table[.0, {n}],
ss = Table[.0, {n}],
ws = {{1., 0.}, {0., 1.}},
zs,
success = 1.0,
uPrev = u0,
uCurr = u1
},
While[True,
k++;
zs = Dnn[r, uCurr, uPrev].ws;
Do[
(Module[{nzi},
Do[(
zi -= zi.zj/Norm[zj, 2] zj) /. zj :> zs[[1 ;; n, j]]
, {j, i - 1}];
nzi = Norm[zi];
nzs[[i]] = nzi;
ws[[1 ;; n, i]] = zi/nzi]) /. zi :> zs[[1 ;; n, i]]
, {i, n}];
ohs = hs;
ss += Log[nzs];
hs = ss/k;
relErr = Norm[1 - ohs/hs, 2];
If[k >= kMin && relErr < tol,
res = Prepend[hs, 1.0];
Break[];
];
{uCurr, uPrev, success} = nn[r, uCurr, uPrev, success];
If[success == 0,
res = Prepend[Table[0., {n}], 0.];
Break[];
];
];
res
], CompilationOptions -> {"InlineExternalDefinitions" -> True},
RuntimeOptions -> "Speed",
CompilationTarget -> "C"]] //. {Pattern[p, _IdentityMatrix] :>
Block[{}, p /; True],
HoldPattern[e_ /. (p_ :> r_)] :>
Block[{}, (Hold[e] /. p :> r) /; True]}) //.
HoldPattern[Hold[expr_]] :> expr
So, how do I do replacements in my Compile
'd code correctly?
SetSystemOptions["CompileOptions" -> "CompileReportExternal" -> True]
$\endgroup$