Python からPARI/GPを呼び出したいと思います。ellisdivisible(E; P; n;{&Q})
PARI の関数 を使用する必要があります(このリンクの 441 ページの関数番号 3.15.35 を参照してください:)ため、2 つのベクトルまたは配列 (E = などellinit([0,-1,1,0,0], K);P = [0,0];
) を渡す必要があります。
Python (Thomas Baruchel 提供)から単一の引数/変数の PARI 関数 (C) を呼び出すには、以下のようなものがあります -
import ctypes
# load the library
pari=ctypes.cdll.LoadLibrary("libpari.so")
# set the right return type of the functions
pari.stoi.restype = ctypes.POINTER(ctypes.c_long)
pari.nextprime.restype = ctypes.POINTER(ctypes.c_long)
# initialize the library
pari.pari_init(2**19,0)
def nextprime(v):
g = pari.nextprime(pari.stoi(ctypes.c_long(v))) # nextprime(argument) is a PARI function
return pari.itos(g)
print( nextprime(456) )
たとえば、私が試した -
h=(0,0,0, 4,6)
pari.stoi.restype = ctypes.POINTER(ctypes.c_long*5)
pari.ellinit.restype = ctypes.POINTER(ctypes.c_long)
def ellinit(v):
g = pari.ellinit(pari.stoi(ctypes.c_long(v)*5))
return pari.itos(g)
print(ellinit(h))
以下のエラーが発生しました-
File "C:\Users\miron\Desktop\trash5\x\f.py", line 68, in <module>
print( ellinit(h) )
File "C:\Users\miron\Desktop\trash5\x\f.py", line 62, in ellinit
g = pari.ellinit(pari.stoi(ctypes.c_long(v)*5))
TypeError: an integer is required (got type tuple)
タプル/配列/ベクトルを渡すにはどうすればよいですか? ありがとう。
編集:
取得に失敗しましたellisdivisible(E; P; n;{&Q})
-
from ctypes import *
pari = cdll.LoadLibrary("C:\\Program Files\\Python37\\Pari64-2-11-3\\libpari.dll")
pari.stoi.restype = POINTER(c_long)
pari.cgetg.restype = POINTER(POINTER(c_long))
pari.ellinit.restype = POINTER(POINTER(c_long))
#-------------------------CHANGE 1
pari.ellisdivisible.restype = c_long
Q = pari.stoi(c_long(0))
#-------------------------
(t_VEC, t_COL, t_MAT) = (17, 18, 19) # incomplete
precision = c_long(38)
pari.pari_init(2 ** 19, 0)
def t_vec(numbers):
l = len(numbers) + 1
p1 = pari.cgetg(c_long(l), c_long(t_VEC))
for i in range(1, l):
p1[i] = pari.stoi(c_long(numbers[i - 1]))
return p1
def main():
h = (0, 0, 0, 0, 1)
P=(0,0)
res = pari.ellinit(t_vec(h), pari.stoi(c_long(1)), precision)
#---------------CHANGE 2
# res = pari.ellinit(t_vec(h), pari.stoi(c_long(1)), precision).disc
y = pari.ellisdivisible(res, t_vec(P), pari.stoi(c_long(5)), byref(Q))
print(pari.itos(y))
#---------------
for i in range(1, 13):
print(pari.itos(res[i]))
if __name__ == '__main__':
main()
エラーは -
Traceback (most recent call last):
File "C:\Users\miron\Desktop\trash5\x\ex - Copy (2).py", line 34, in <module>
main()
File "C:\Users\miron\Desktop\trash5\x\ex - Copy (2).py", line 28, in main
print(pari.itos(y))
OSError: exception: access violation reading 0x0000000000000009