Skip to content

Commit 4b27a9a

Browse files
committed
refactor code
Signed-off-by: Jade Abraham <[email protected]>
1 parent da97cc6 commit 4b27a9a

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

test/library/packages/Python/examples/scipy/integrateQuad.chpl

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ var interp = new Interpreter();
55
var sp = interp.importModule("scipy");
66
var spi = interp.importModule("scipy.integrate");
77

8-
// integrate a Python Function using scipy.integrate.quad
9-
proc integrate(f: owned Function, a: real, b: real): real {
8+
// integrate a function using scipy.integrate.quad
9+
proc integrate(f: borrowed Value, a: real, b: real): real {
1010
return spi.call("quad", f, a, b).call(real, "__getitem__", 0);
1111
}
1212

@@ -19,8 +19,7 @@ proc integrate(f: owned Function, a: real, b: real): real {
1919
}
2020

2121

22-
// integrate a Chapel Function using scipy.integrate.quad
23-
proc integrate(f:proc(_: real):real, a: real, b: real): real {
22+
proc chapelProcToPython(f:proc(_: real):real): owned Value {
2423
use CTypes;
2524
// get a c_ptr to a Chapel proc
2625
var f_ptr = c_ptrTo(f):c_ptr(void);
@@ -36,13 +35,13 @@ proc integrate(f:proc(_: real):real, a: real, b: real): real {
3635
// create a LowLevelCallable for scipy usage
3736
var fPy = sp.call("LowLevelCallable", f_ptrPy,
3837
kwargs=["signature"=>"double (double)"]);
39-
40-
return spi.call("quad", fPy, a, b).call(real, "__getitem__", 0);
38+
return fPy;
4139
}
4240

4341
{
4442
writeln("Integrating x**3, defined in Chapel");
45-
export proc f(x: real): real do return x;
43+
proc chplFunc(x: real): real do return x;
44+
var f = chapelProcToPython(cChplFunc);
4645
writeln(integrate(f, 0.0, 2.0));
4746
writeln(integrate(f, 0.0, 4.0));
4847
writeln(integrate(f, 0.0, 8.0));

0 commit comments

Comments
 (0)