I've been trying to compile a couple of functions in Mathematica, and I keep coming across an error that I do not know how to resolve. Consider the following function:
FindCircleVerticalLineIntersections =
Compile[{{circlePos, _Real, 1}, {radius}, {xIntercept}},
Module[{points, θ, posRadius, yDist},
(*First, let's initialize points*)
(*This will not work any other way that I have tried*)
points = {{0.0, 0.0}};
(*First things first:
let's see if the vertical line is within the boundaries of the \
circle*)
If[PointIsWithinCircleWidth[circlePos, radius, {xIntercept, 0}],
(*If it is, let's see if it is right on the edge of the circle*)
If[PointIsOnCircleWidth[circlePos, radius, {xIntercept, 0}],
(*If it is,
then the list of all intersection points will have just one \
entry*)
points = {{xIntercept, circlePos[[2]]}};
,
(*Otherwise, let's find both intersections*)
posRadius = Abs[radius];
θ = ArcCos[(xIntercept - circlePos[[1]])/posRadius];
yDist = posRadius*Sin[θ];
points = {{xIntercept, circlePos[[2]] + yDist}, {xIntercept,
circlePos[[2]] - yDist}};
];
,
(*Otherwise, we don't have any intersections,
let's just set points to an empty list*)
points = Delete[points, 1];
];
(*Finally, let's return points*)
points
]
, CompilationTarget -> "C"];
Now, this function works just as expected, and returns results well, but whenever I try to call it from any other compiled function, such as the following function:
f = Compile[{},
FindCircleVerticalLineIntersections[{0.0, 0.0}, 1.0, 0.0]
, CompilationTarget -> "C"];
I get the following undeclared identifier error:
CCompilerDriver`CreateLibrary::cmperr: Compile error: C:\Users\Surge\AppData\Roaming\Mathematica\ApplicationData\CCompilerDriver\BuildFolder\combinatoric-5700\Working-combinatoric-5700-2808-88\compiledFunction87.c(85) : error C2065: 'P1' : undeclared identifier >>
I've looked at the human-readable C form of this program, and I don't even see an identifier called P1
:
No argument
2 Integer registers
2 Real registers
3 Tensor registers
Underflow checking off
Overflow checking off
Integer overflow checking on
RuntimeAttributes -> {}
T(I1)0 = {0, 0}
I1 = 1
I0 = 3
Result = T(R2)1
1 T(R2)1 = MainEvaluate[ Hold[FindCircleVerticalLineIntersections][ \
T(I1)0, I1, I1]]
2 Return
Does anyone know what the problem is?
EDIT
Here are the missing functions, my apologies for the delay:
(*The following function determines wither a point pointPos is within \
a circle of a given radius centered on the origin*)
PointIsWithinCircleWidthOnOrigin =
Compile[{{radius}, {pointPos, _Real, 1}},
Module[{posRad},
(*First,
let's make sure the radius that was passed in is positive*)
posRad = Abs[radius];
(*Next, let's see if the X-
componant of the point is within the boundary of the circle*)
(*This If structure to my knowledge is unnecessary,
but it makes the code look a bit cleaner in my opinion since we \
are explictly passing back a True or a False*)
If[Abs[pointPos[[1]]] <= posRad,
True,
False
]
]
, CompilationTarget -> "C", RuntimeOptions -> "Speed"];
(*The following function determines whether some point pPos is within \
a circle of radius rad centered at cPos*)
PointIsWithinCircleWidth =
Compile[{{cPos, _Real, 1}, {rad}, {pPos, _Real, 1}},
Module[{pos, pRad},
(*First,
let's shift the entire system so that we can be dealing with a \
circle centered at the origin*)
pos = pPos - cPos;
(*Next,
let's call PointIsWithinCircleWidthOnOrigin and return whatever \
that returns*)
PointIsWithinCircleWidthOnOrigin[rad, pos]
]
, CompilationTarget -> "C", RuntimeOptions -> "Speed"];
(*This function determines whether a given point is on the left-most \
or right-most boundary of a circle on the origin given a radius*)
PointIsOnCircleWidthOnOrigin = Compile[{{radius}, {point, _Real, 1}},
Module[{positiveRad, posXComponant},
(*Let's first make sure the radius is positive*)
positiveRad = Abs[radius];
(*Next, let's find the absolute value of the X-componant*)
posXComponant = Abs[point[[1]]];
If[posXComponant == positiveRad,
True,
False
]
]
, CompilationTarget -> "C", RuntimeOptions -> "Speed"];
(*This function determines whether a point is on the left-most or \
right-most boundary of a circle on the origin given a radius*)
PointIsOnCircleWidth =
Compile[{{cPos, _Real, 1}, {radius}, {point, _Real, 1}},
Module[{pos},
pos = point - cPos;
PointIsOnCircleWidthOnOrigin[radius, pos]
]
, CompilationTarget -> "C", RuntimeOptions -> "Speed"];
PointIsWithinCircleWidth
andPointIsOnCircleWidth
given, so please include those in the question as well. Welcome to the site, by the way. It is a rarer thing than you would think for a brand-new user to post a (almost) fully formed and properly formatted question, and it is appreciated. $\endgroup$ – Oleksandr R. Jul 31 '15 at 0:00"InlineCompiledFunctions"
? $\endgroup$ – Michael E2 Jul 31 '15 at 0:42