XLPack API: Python example programs
How to call XLPack from Python
The XLPack Lite Python extension module is included in SDK, so that the calling program can easily call XLPack Lite like built-in functions by declaring “import XLPackLite” (or “import XLPackLite_32” for 32 bit Python).
Numpy ndarray is used to represent the matrix. Either two dimensional or one dimensional array can be used for both coefficient matrix a and right hand matrix b.
Python example program (Example (1))
import numpy as np
from XLPack import *
def TestDgesv():
n = 3
a = np.array([
[0.2, -0.32, -0.8],
[-0.11, 0.81, -0.92],
[-0.93, 0.37, -0.29]])
b = np.array([-0.3727, 0.4319, -1.4247])
ipiv = np.empty(n, dtype=int)
info = dgesv(n, a, ipiv, b)
print(b, info)
TestDgesv()
Result
[0.86 0.64 0.51] 0
Python example program (Example (2))
In Example (2), the integral of f(x) is computed using qk15. qk15 requires the external function defining f(x). It can be coded in Python and qk15 will call it when necessary.
import numpy as np
from XLPack import *
def f(x):
return 1/(1 + x**2)
def TestQk15():
a = 0
b = 4
s, abserr = qk15(f, a, b)
print(s, abserr)
TestQk15()
Result
1.3258176613637855 0.0014827239412162237