@@ -5,8 +5,8 @@ var interp = new Interpreter();
5
5
var sp = interp.importModule(" scipy" );
6
6
var spi = interp.importModule(" scipy.integrate" );
7
7
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 {
10
10
return spi.call(" quad" , f, a, b).call(real , " __getitem__" , 0 );
11
11
}
12
12
@@ -19,8 +19,7 @@ proc integrate(f: owned Function, a: real, b: real): real {
19
19
}
20
20
21
21
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 {
24
23
use CTypes;
25
24
// get a c_ptr to a Chapel proc
26
25
var f_ptr = c_ptrTo(f): c_ptr(void );
@@ -36,13 +35,13 @@ proc integrate(f:proc(_: real):real, a: real, b: real): real {
36
35
// create a LowLevelCallable for scipy usage
37
36
var fPy = sp.call(" LowLevelCallable" , f_ptrPy,
38
37
kwargs= [ " signature" = > " double (double)" ] );
39
-
40
- return spi.call(" quad" , fPy, a, b).call(real , " __getitem__" , 0 );
38
+ return fPy;
41
39
}
42
40
43
41
{
44
42
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);
46
45
writeln (integrate(f, 0.0 , 2.0 ));
47
46
writeln (integrate(f, 0.0 , 4.0 ));
48
47
writeln (integrate(f, 0.0 , 8.0 ));
0 commit comments