version 1.25, 2015/08/17 05:18:36 |
version 1.39, 2018/04/09 04:07:27 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/builtin/parif.c,v 1.24 2015/08/16 03:12:09 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/builtin/parif.c,v 1.38 2018/03/29 01:32:50 noro Exp $ */ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
#include "ox.h" |
#include "ox.h" |
|
|
Q ox_pari_stream; |
Q ox_pari_stream; |
int ox_pari_stream_initialized = 0; |
int ox_pari_stream_initialized = 0; |
|
int ox_get_pari_result = 0; |
|
P ox_pari_starting_function = 0; |
|
|
typedef void (*mpfr_func)(NODE,Obj *); |
typedef void (*mpfr_func)(NODE,Obj *); |
|
|
Line 20 struct mpfr_tab_rec { |
|
Line 22 struct mpfr_tab_rec { |
|
char *name; |
char *name; |
mpfr_func func; |
mpfr_func func; |
} mpfr_tab[] = { |
} mpfr_tab[] = { |
{"ai",Pmpfr_ai}, |
{"ai",Pmpfr_ai}, |
{"zeta",Pmpfr_zeta}, |
{"zeta",Pmpfr_zeta}, |
{"j0",Pmpfr_j0}, |
{"j0",Pmpfr_j0}, |
{"j1",Pmpfr_j1}, |
{"j1",Pmpfr_j1}, |
{"y0",Pmpfr_y0}, |
{"y0",Pmpfr_y0}, |
{"y1",Pmpfr_y1}, |
{"y1",Pmpfr_y1}, |
{"eint",Pmpfr_eint}, |
{"eint",Pmpfr_eint}, |
{"erf",Pmpfr_erf}, |
{"erf",Pmpfr_erf}, |
{"li2",Pmpfr_li2}, |
{"li2",Pmpfr_li2}, |
{"gamma",Pmpfr_gamma}, |
{"gamma",Pmpfr_gamma}, |
{"lngamma",Pmpfr_gamma}, |
{"lngamma",Pmpfr_gamma}, |
{"digamma",Pmpfr_gamma}, |
{"digamma",Pmpfr_gamma}, |
{"floor",Pmpfr_floor}, |
{"floor",Pmpfr_floor}, |
{"ceil",Pmpfr_ceil}, |
{"ceil",Pmpfr_ceil}, |
{"round",Pmpfr_round}, |
{"round",Pmpfr_round}, |
}; |
}; |
|
|
mpfr_func mpfr_search(char *name) |
mpfr_func mpfr_search(char *name) |
Line 48 mpfr_func mpfr_search(char *name) |
|
Line 50 mpfr_func mpfr_search(char *name) |
|
return 0; |
return 0; |
} |
} |
|
|
|
Obj list_to_vect(Obj a) |
|
{ |
|
int len,i; |
|
VECT v; |
|
NODE nd; |
|
|
|
if ( !a || OID(a) != O_LIST ) return a; |
|
len = length(BDY((LIST)a)); |
|
MKVECT(v,len); |
|
for ( i = 0, nd = BDY((LIST)a); nd; nd = NEXT(nd), i++ ) |
|
v->body[i] = (pointer)list_to_vect((Obj)BDY(nd)); |
|
return (Obj)v; |
|
} |
|
|
|
Obj vect_to_mat(VECT v) |
|
{ |
|
MAT m; |
|
int len,col,i,j; |
|
|
|
len = v->len; |
|
if ( v->body[0] && OID((Obj)v->body[0]) == O_VECT ) { |
|
col = ((VECT)v->body[0])->len; |
|
for ( i = 1; i < len; i++ ) |
|
if ( !v->body[i] || OID((Obj)v->body[i]) != O_VECT |
|
|| ((VECT)v->body[i])->len != col ) |
|
break; |
|
if ( i == len ) { |
|
/* convert to a matrix */ |
|
MKMAT(m,len,col); |
|
for ( i = 0; i < len; i++ ) |
|
for ( j = 0; j < col; j++ ) |
|
m->body[i][j] = ((VECT)v->body[i])->body[j]; |
|
return (Obj)m; |
|
} |
|
} |
|
return (Obj)v; |
|
} |
|
|
|
void reset_ox_pari() |
|
{ |
|
NODE nd; |
|
Obj r; |
|
|
|
if ( ox_get_pari_result ) { |
|
nd = mknode(1,ox_pari_stream); |
|
Pox_shutdown(nd,&r); |
|
ox_get_pari_result = 0; |
|
ox_pari_stream_initialized = 0; |
|
} |
|
} |
|
|
pointer evalparif(FUNC f,NODE arg) |
pointer evalparif(FUNC f,NODE arg) |
{ |
{ |
int ac,intarg,opt,prec; |
int ac,intarg,opt,prec; |
Q q,r,narg; |
Q q,r,narg,cmd; |
|
Real sec; |
NODE nd,oxarg,t,t1,n; |
NODE nd,oxarg,t,t1,n; |
STRING name; |
STRING name; |
USINT ui; |
USINT ui; |
|
LIST list; |
Obj ret,dmy; |
Obj ret,dmy; |
mpfr_func mpfr_function; |
mpfr_func mpfr_function; |
|
V v; |
|
|
if ( mpfr_function = mpfr_search(f->name) ) { |
if ( arg && ARG0(arg) && NID((Num)ARG0(arg)) != N_C |
(*mpfr_function)(arg,&ret); |
&& (mpfr_function = mpfr_search(f->name)) ) { |
return (pointer) ret; |
(*mpfr_function)(arg,&ret); |
|
return (pointer) ret; |
} |
} |
|
|
if ( !ox_pari_stream_initialized ) { |
if ( !ox_pari_stream_initialized ) { |
MKSTR(name,"ox_pari"); |
if ( ox_pari_starting_function && OID(ox_pari_starting_function) == O_P ) { |
nd = mknode(2,NULL,name); |
v = VR(ox_pari_starting_function); |
Pox_launch_nox(nd,&r); |
if ( (int)v->attr != V_SR ) { |
ox_pari_stream = r; |
error("pari : no handler."); |
|
} |
|
MKNODE(nd,0,0); |
|
r = (Q)bevalf((FUNC)v->priv,0); |
|
}else { |
|
#if !defined(VISUAL) |
|
MKSTR(name,"ox_pari"); |
|
nd = mknode(2,NULL,name); |
|
Pox_launch_nox(nd,&r); |
|
#else |
|
error("Please load names.rr from latest asir-contrib library before using pari functions."); |
|
#endif |
|
} |
|
ox_pari_stream = r; |
ox_pari_stream_initialized = 1; |
ox_pari_stream_initialized = 1; |
} |
} |
|
|
ac = argc(arg); |
ac = argc(arg); |
/* reverse the arg list */ |
/* reverse the arg list */ |
for ( n = arg, t = 0; n; n = NEXT(n) ) { |
for ( n = arg, t = 0; n; n = NEXT(n) ) { |
MKNODE(t1,BDY(n),t); t = t1; |
MKNODE(t1,BDY(n),t); t = t1; |
Line 85 pointer evalparif(FUNC f,NODE arg) |
|
Line 155 pointer evalparif(FUNC f,NODE arg) |
|
STOQ(ac,narg); |
STOQ(ac,narg); |
oxarg = mknode(3,ox_pari_stream,name,narg); |
oxarg = mknode(3,ox_pari_stream,name,narg); |
Pox_execute_function(oxarg,&dmy); |
Pox_execute_function(oxarg,&dmy); |
|
ox_get_pari_result = 1; |
|
#if defined(VISUAL) || defined(__MINGW32__) |
|
#define SM_popCMO 262 |
|
STOQ(SM_popCMO,cmd); |
|
oxarg = mknode(2,ox_pari_stream,cmd); |
|
Pox_push_cmd(oxarg,&dmy); |
|
nd = mknode(1,ox_pari_stream); |
|
MKLIST(list,nd); |
|
MKReal(1.0/8,sec); |
|
oxarg = mknode(2,list,sec); |
|
ret=0; |
|
do { |
|
check_intr(); |
|
Pox_select(oxarg,&list); |
|
oxarg = mknode(1,list); |
|
Plength(oxarg,&ret); |
|
}while (!ret); |
oxarg = mknode(1,ox_pari_stream); |
oxarg = mknode(1,ox_pari_stream); |
Pox_pop_cmo(oxarg,&r); |
Pox_get(oxarg,&ret); |
return r; |
#else |
|
oxarg = mknode(1,ox_pari_stream); |
|
Pox_pop_cmo(oxarg,&ret); |
|
#endif |
|
ox_get_pari_result = 0; |
|
if ( ret && OID(ret) == O_ERR ) { |
|
char buf[BUFSIZ]; |
|
soutput_init(buf); |
|
sprintexpr(CO,((ERR)ret)->body); |
|
error(buf); |
|
} |
|
if ( ret && OID(ret) == O_LIST ) { |
|
ret = list_to_vect(ret); |
|
ret = vect_to_mat((VECT)ret); |
|
} |
|
return ret; |
} |
} |
|
|
struct pariftab { |
struct pariftab { |
char *name; |
char *name; |
int dmy; |
int dmy; |
int type; |
int type; |
}; |
}; |
|
|
/* |
/* |
* type = 1 => argc = 1, second arg = precision |
* type = 1 => argc = 1, second arg = precision |
* type = 2 => argc = 1, second arg = optional (long int) |
* type = 2 => argc = 1, second arg = (long int)0 |
* |
* |
*/ |
*/ |
/* |
/* |
Line 227 struct pariftab pariftab[] = { |
|
Line 329 struct pariftab pariftab[] = { |
|
|
|
{"allocatemem",0,0}, |
{"allocatemem",0,0}, |
|
|
|
{"factpol",0,2}, |
{"isprime",0,2}, |
{"isprime",0,2}, |
{"factorint",0,2}, |
{"factorint",0,2}, |
{0,0,0}, |
{0,0,0}, |
}; |
}; |
|
|
void parif_init() { |
void parif_init() { |
int i; |
int i; |
|
|
for ( i = 0, parif = 0; pariftab[i].name; i++ ) |
for ( i = 0, parif = 0; pariftab[i].name; i++ ) |
appendparif(&parif,pariftab[i].name, 0,pariftab[i].type); |
appendparif(&parif,pariftab[i].name, 0,pariftab[i].type); |
} |
} |