version 1.99, 2004/09/14 07:23:34 |
version 1.103, 2004/09/15 06:06:42 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.98 2004/08/18 00:17:02 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.102 2004/09/15 01:43:33 noro Exp $ */ |
|
|
#include "nd.h" |
#include "nd.h" |
|
|
|
|
ND _nd_free_list; |
ND _nd_free_list; |
ND_pairs _ndp_free_list; |
ND_pairs _ndp_free_list; |
|
|
|
#if 0 |
static int ndv_alloc; |
static int ndv_alloc; |
|
#endif |
#if 1 |
#if 1 |
static int nd_f4_nsp=0x7fffffff; |
static int nd_f4_nsp=0x7fffffff; |
#else |
#else |
|
|
d = ndvtond(0,r); |
d = ndvtond(0,r); |
stat = nd_nf(0,d,nd_ps,0,0,&nf); |
stat = nd_nf(0,d,nd_ps,0,0,&nf); |
if ( !stat ) { |
if ( !stat ) { |
nd_reconstruct(0,0,0); |
nd_reconstruct(0,0); |
goto again; |
goto again; |
} else if ( nf ) return 0; |
} else if ( nf ) return 0; |
if ( DP_Print ) { printf("."); fflush(stdout); } |
if ( DP_Print ) { printf("."); fflush(stdout); } |
|
|
stat = nd_sp(m,0,l,&h); |
stat = nd_sp(m,0,l,&h); |
if ( !stat ) { |
if ( !stat ) { |
NEXT(l) = d; d = l; |
NEXT(l) = d; d = l; |
d = nd_reconstruct(m,0,d); |
d = nd_reconstruct(0,d); |
goto again; |
goto again; |
} |
} |
#if USE_GEOBUCKET |
#if USE_GEOBUCKET |
|
|
#endif |
#endif |
if ( !stat ) { |
if ( !stat ) { |
NEXT(l) = d; d = l; |
NEXT(l) = d; d = l; |
d = nd_reconstruct(m,0,d); |
d = nd_reconstruct(0,d); |
goto again; |
goto again; |
} else if ( nf ) { |
} else if ( nf ) { |
if ( checkonly ) return 0; |
if ( checkonly ) return 0; |
|
|
stat = nd_sp(m,0,l,&h); |
stat = nd_sp(m,0,l,&h); |
if ( !stat ) { |
if ( !stat ) { |
NEXT(l) = d; d = l; |
NEXT(l) = d; d = l; |
d = nd_reconstruct(m,1,d); |
d = nd_reconstruct(1,d); |
goto again; |
goto again; |
} |
} |
#if USE_GEOBUCKET |
#if USE_GEOBUCKET |
|
|
#endif |
#endif |
if ( !stat ) { |
if ( !stat ) { |
NEXT(l) = d; d = l; |
NEXT(l) = d; d = l; |
d = nd_reconstruct(m,1,d); |
d = nd_reconstruct(1,d); |
goto again; |
goto again; |
} else if ( nf ) { |
} else if ( nf ) { |
if ( nd_demand ) { |
if ( nd_demand ) { |
|
|
if ( !nfq ) { |
if ( !nfq ) { |
if ( !nd_sp(0,1,l,&h) || !nd_nf(0,h,nd_ps_trace,!Top,0,&nfq) ) { |
if ( !nd_sp(0,1,l,&h) || !nd_nf(0,h,nd_ps_trace,!Top,0,&nfq) ) { |
NEXT(l) = d; d = l; |
NEXT(l) = d; d = l; |
d = nd_reconstruct(m,1,d); |
d = nd_reconstruct(1,d); |
goto again; |
goto again; |
} |
} |
} |
} |
Line 1790 NODE ndv_reduceall(int m,NODE f) |
|
Line 1792 NODE ndv_reduceall(int m,NODE f) |
|
g = nd_separate_head(g,&head); |
g = nd_separate_head(g,&head); |
stat = nd_nf(m,g,nd_ps,1,&dn,&nf); |
stat = nd_nf(m,g,nd_ps,1,&dn,&nf); |
if ( !stat ) |
if ( !stat ) |
nd_reconstruct(m,0,0); |
nd_reconstruct(0,0); |
else { |
else { |
if ( DP_Print ) { printf("."); fflush(stdout); } |
if ( DP_Print ) { printf("."); fflush(stdout); } |
if ( !m ) { |
if ( !m ) { |
Line 2186 void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe |
|
Line 2188 void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe |
|
if ( !m && Demand ) nd_demand = 1; |
if ( !m && Demand ) nd_demand = 1; |
else nd_demand = 0; |
else nd_demand = 0; |
|
|
|
#if 0 |
ndv_alloc = 0; |
ndv_alloc = 0; |
|
#endif |
get_vars((Obj)f,&fv); pltovl(v,&vv); |
get_vars((Obj)f,&fv); pltovl(v,&vv); |
for ( nvar = 0, tv = vv; tv; tv = NEXT(tv), nvar++ ); |
for ( nvar = 0, tv = vv; tv; tv = NEXT(tv), nvar++ ); |
switch ( ord->id ) { |
switch ( ord->id ) { |
Line 2224 void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe |
|
Line 2228 void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe |
|
} |
} |
if ( r0 ) NEXT(r) = 0; |
if ( r0 ) NEXT(r) = 0; |
MKLIST(*rp,r0); |
MKLIST(*rp,r0); |
|
#if 0 |
fprintf(asir_out,"ndv_alloc=%d\n",ndv_alloc); |
fprintf(asir_out,"ndv_alloc=%d\n",ndv_alloc); |
|
#endif |
} |
} |
|
|
void nd_gr_trace(LIST f,LIST v,int trace,int homo,struct order_spec *ord,LIST *rp) |
void nd_gr_trace(LIST f,LIST v,int trace,int homo,struct order_spec *ord,LIST *rp) |
Line 2789 void nd_setup_parameters(int nvar,int max) { |
|
Line 2795 void nd_setup_parameters(int nvar,int max) { |
|
nd_work_vector = (int *)REALLOC(nd_work_vector,nd_nvar*sizeof(int)); |
nd_work_vector = (int *)REALLOC(nd_work_vector,nd_nvar*sizeof(int)); |
} |
} |
|
|
ND_pairs nd_reconstruct(int mod,int trace,ND_pairs d) |
ND_pairs nd_reconstruct(int trace,ND_pairs d) |
{ |
{ |
int i,obpe,oadv,h; |
int i,obpe,oadv,h; |
static NM prev_nm_free_list; |
static NM prev_nm_free_list; |
Line 3196 ND ndv_mul_nm(int mod,NM m0,NDV p) |
|
Line 3202 ND ndv_mul_nm(int mod,NM m0,NDV p) |
|
} |
} |
} |
} |
|
|
ND nd_quo(ND p,ND d) |
ND nd_quo(int mod,ND p,NDV d) |
{ |
{ |
NM mq0,mq; |
NM mq0,mq; |
|
NMV tm; |
Q q; |
Q q; |
int i,nv,sg; |
int i,nv,sg,c,c1,c2; |
ND t,r; |
ND t,r; |
|
|
if ( !p ) return 0; |
if ( !p ) return 0; |
Line 3208 ND nd_quo(ND p,ND d) |
|
Line 3215 ND nd_quo(ND p,ND d) |
|
nv = NV(p); |
nv = NV(p); |
sg = SG(p); |
sg = SG(p); |
mq0 = 0; |
mq0 = 0; |
|
tm = (NMV)ALLOCA(nmv_adv); |
while ( p ) { |
while ( p ) { |
NEXTNM(mq0,mq); |
NEXTNM(mq0,mq); |
ndl_sub(HDL(p),HDL(d),DL(mq)); |
ndl_sub(HDL(p),HDL(d),DL(mq)); |
divq(HCQ(p),HCQ(d),&q); |
ndl_copy(DL(mq),DL(tm)); |
chsgnq(q,&CQ(mq)); |
if ( mod ) { |
t = nd_mul_nm_trunc(mq,d,HDL(d)); |
c1 = invm(HCM(d),mod); c2 = HCM(p); |
p = nd_add(0,p,t); |
DMAR(c1,c2,0,mod,c); CM(mq) = c; |
|
CM(tm) = mod-c; |
|
} else { |
|
divq(HCQ(p),HCQ(d),&CQ(mq)); |
|
chsgnq(CQ(mq),&CQ(tm)); |
|
} |
|
t = ndv_mul_nmv_trunc(mod,tm,d,HDL(d)); |
|
p = nd_add(mod,p,t); |
} |
} |
NEXT(mq) = 0; |
NEXT(mq) = 0; |
for ( i = 0, mq = mq0; mq; mq = NEXT(mq), i++ ); |
for ( i = 0, mq = mq0; mq; mq = NEXT(mq), i++ ); |
Line 3447 NDV ndtondv(int mod,ND p) |
|
Line 3462 NDV ndtondv(int mod,ND p) |
|
m0 = m = (NMV)GC_malloc_atomic_ignore_off_page(len*nmv_adv); |
m0 = m = (NMV)GC_malloc_atomic_ignore_off_page(len*nmv_adv); |
else |
else |
m0 = m = MALLOC(len*nmv_adv); |
m0 = m = MALLOC(len*nmv_adv); |
|
#if 0 |
ndv_alloc += nmv_adv*len; |
ndv_alloc += nmv_adv*len; |
|
#endif |
for ( t = BDY(p), i = 0; t; t = NEXT(t), i++, NMV_ADV(m) ) { |
for ( t = BDY(p), i = 0; t; t = NEXT(t), i++, NMV_ADV(m) ) { |
ndl_copy(DL(t),DL(m)); |
ndl_copy(DL(t),DL(m)); |
CQ(m) = CQ(t); |
CQ(m) = CQ(t); |
Line 3718 void nd_nf_p(P f,LIST g,LIST v,int m,struct order_spec |
|
Line 3735 void nd_nf_p(P f,LIST g,LIST v,int m,struct order_spec |
|
stat = nd_nf(m,nd,nd_ps,1,0,&nf); |
stat = nd_nf(m,nd,nd_ps,1,0,&nf); |
if ( !stat ) { |
if ( !stat ) { |
nd_psn++; |
nd_psn++; |
nd_reconstruct(m,0,0); |
nd_reconstruct(0,0); |
nd_psn--; |
nd_psn--; |
} else |
} else |
break; |
break; |
Line 3955 NDV vect_to_ndv(UINT *vect,int spcol,int col,int *rhea |
|
Line 3972 NDV vect_to_ndv(UINT *vect,int spcol,int col,int *rhea |
|
if ( !len ) return 0; |
if ( !len ) return 0; |
else { |
else { |
mr0 = (NMV)GC_malloc_atomic_ignore_off_page(nmv_adv*len); |
mr0 = (NMV)GC_malloc_atomic_ignore_off_page(nmv_adv*len); |
|
#if 0 |
ndv_alloc += nmv_adv*len; |
ndv_alloc += nmv_adv*len; |
|
#endif |
mr = mr0; |
mr = mr0; |
p = s0vect; |
p = s0vect; |
for ( j = k = 0; j < col; j++, p += nd_wpd ) |
for ( j = k = 0; j < col; j++, p += nd_wpd ) |
Line 4050 NODE nd_f4(int m) |
|
Line 4069 NODE nd_f4(int m) |
|
|
|
if ( !m ) |
if ( !m ) |
error("nd_f4 : not implemented"); |
error("nd_f4 : not implemented"); |
|
#if 0 |
ndv_alloc = 0; |
ndv_alloc = 0; |
|
#endif |
g = 0; d = 0; |
g = 0; d = 0; |
for ( i = 0; i < nd_psn; i++ ) { |
for ( i = 0; i < nd_psn; i++ ) { |
d = update_pairs(d,g,i); |
d = update_pairs(d,g,i); |
Line 4065 NODE nd_f4(int m) |
|
Line 4086 NODE nd_f4(int m) |
|
if ( !stat ) { |
if ( !stat ) { |
for ( t = l; NEXT(t); t = NEXT(t) ); |
for ( t = l; NEXT(t); t = NEXT(t) ); |
NEXT(t) = d; d = l; |
NEXT(t) = d; d = l; |
d = nd_reconstruct(m,0,d); |
d = nd_reconstruct(0,d); |
continue; |
continue; |
} |
} |
if ( bucket->m < 0 ) continue; |
if ( bucket->m < 0 ) continue; |
Line 4073 NODE nd_f4(int m) |
|
Line 4094 NODE nd_f4(int m) |
|
if ( !col ) { |
if ( !col ) { |
for ( t = l; NEXT(t); t = NEXT(t) ); |
for ( t = l; NEXT(t); t = NEXT(t) ); |
NEXT(t) = d; d = l; |
NEXT(t) = d; d = l; |
d = nd_reconstruct(m,0,d); |
d = nd_reconstruct(0,d); |
continue; |
continue; |
} |
} |
get_eg(&eg1); init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg1); |
get_eg(&eg1); init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg1); |
Line 4094 NODE nd_f4(int m) |
|
Line 4115 NODE nd_f4(int m) |
|
} |
} |
} |
} |
for ( r = g; r; r = NEXT(r) ) BDY(r) = (pointer)nd_ps[(int)BDY(r)]; |
for ( r = g; r; r = NEXT(r) ) BDY(r) = (pointer)nd_ps[(int)BDY(r)]; |
|
#if 0 |
fprintf(asir_out,"ndv_alloc=%d\n",ndv_alloc); |
fprintf(asir_out,"ndv_alloc=%d\n",ndv_alloc); |
|
#endif |
return g; |
return g; |
} |
} |
|
|
Line 4248 NDV nd_recv_ndv() |
|
Line 4271 NDV nd_recv_ndv() |
|
if ( !len ) return 0; |
if ( !len ) return 0; |
else { |
else { |
m0 = m = (NMV)GC_malloc_atomic_ignore_off_page(nmv_adv*len); |
m0 = m = (NMV)GC_malloc_atomic_ignore_off_page(nmv_adv*len); |
|
#if 0 |
ndv_alloc += len*nmv_adv; |
ndv_alloc += len*nmv_adv; |
|
#endif |
for ( i = 0; i < len; i++, NMV_ADV(m) ) { |
for ( i = 0; i < len; i++, NMV_ADV(m) ) { |
CM(m) = nd_recv_int(); |
CM(m) = nd_recv_int(); |
nd_recv_intarray(DL(m),nd_wpd); |
nd_recv_intarray(DL(m),nd_wpd); |
Line 4646 NDV ndv_load(int index) |
|
Line 4671 NDV ndv_load(int index) |
|
return d; |
return d; |
} |
} |
|
|
void nd_det(MAT f,P *rp) |
void nd_det(int mod,MAT f,P *rp) |
{ |
{ |
VL fv,tv; |
VL fv,tv; |
int n,i,j,max,e,nvar,sgn,k0,l0,len0,len,k,l; |
int n,i,j,max,e,nvar,sgn,k0,l0,len0,len,k,l,a; |
pointer **m; |
pointer **m; |
Q mone; |
Q mone; |
ND **dm; |
NDV **dm; |
ND *t,*mi,*mj; |
NDV *t,*mi,*mj; |
ND d,s,mij,mjj,m1,m2,u; |
NDV d,s,mij,mjj; |
NDV dv; |
ND u; |
|
NMV nmv; |
PGeoBucket bucket; |
PGeoBucket bucket; |
NM nm; |
|
struct order_spec *ord; |
struct order_spec *ord; |
|
|
create_order_spec(0,0,&ord); |
create_order_spec(0,0,&ord); |
Line 4675 void nd_det(MAT f,P *rp) |
|
Line 4700 void nd_det(MAT f,P *rp) |
|
max = MAX(e,max); |
max = MAX(e,max); |
} |
} |
nd_setup_parameters(nvar,1024); |
nd_setup_parameters(nvar,1024); |
dm = (ND **)almat_pointer(n,n); |
dm = (NDV **)almat_pointer(n,n); |
for ( i = 0, max = 0; i < n; i++ ) |
for ( i = 0, max = 0; i < n; i++ ) |
for ( j = 0; j < n; j++ ) |
for ( j = 0; j < n; j++ ) { |
dm[i][j] = ptond(CO,fv,m[i][j]); |
dm[i][j] = ptondv(CO,fv,m[i][j]); |
d = ptond(CO,fv,(P)ONE); |
if ( mod ) ndv_mod(mod,dm[i][j]); |
|
if ( dm[i][j] && !LEN(dm[i][j]) ) dm[i][j] = 0; |
|
} |
|
d = ptondv(CO,fv,(P)ONE); |
|
if ( mod ) ndv_mod(mod,d); |
chsgnq(ONE,&mone); |
chsgnq(ONE,&mone); |
for ( j = 0, sgn = 1; j < n; j++ ) { |
for ( j = 0, sgn = 1; j < n; j++ ) { |
for ( i = j; i < n && !dm[i][j]; i++ ); |
for ( i = j; i < n && !dm[i][j]; i++ ); |
Line 4687 void nd_det(MAT f,P *rp) |
|
Line 4716 void nd_det(MAT f,P *rp) |
|
*rp = 0; |
*rp = 0; |
return; |
return; |
} |
} |
k0 = i; l0 = j; len0 = nd_length(dm[k0][l0]); |
k0 = i; l0 = j; len0 = LEN(dm[k0][l0]); |
for ( k = j; k < n; k++ ) |
for ( k = j; k < n; k++ ) |
for ( l = j; l < n; l++ ) |
for ( l = j; l < n; l++ ) |
if ( dm[k][l] && (len = nd_length(dm[k][l])) < len0 ) { |
if ( dm[k][l] && LEN(dm[k][l]) < len0 ) { |
k0 = k; l0 = l; len0 = len; |
k0 = k; l0 = l; len0 = LEN(dm[k][l]); |
} |
} |
if ( k0 != j ) { |
if ( k0 != j ) { |
t = dm[j]; dm[j] = dm[k0]; dm[k0] = t; |
t = dm[j]; dm[j] = dm[k0]; dm[k0] = t; |
Line 4705 void nd_det(MAT f,P *rp) |
|
Line 4734 void nd_det(MAT f,P *rp) |
|
} |
} |
for ( i = j+1, mj = dm[j], mjj = mj[j]; i < n; i++ ) { |
for ( i = j+1, mj = dm[j], mjj = mj[j]; i < n; i++ ) { |
mi = dm[i]; mij = mi[j]; |
mi = dm[i]; mij = mi[j]; |
nd_mul_c_q(mij,mone); |
if ( mod ) |
|
ndv_mul_c(mod,mij,mod-1); |
|
else |
|
ndv_mul_c_q(mij,mone); |
for ( k = j+1; k < n; k++ ) { |
for ( k = j+1; k < n; k++ ) { |
bucket = create_pbucket(); |
bucket = create_pbucket(); |
if ( mi[k] ) |
if ( mi[k] ) |
for ( nm = BDY(mjj); nm; nm = NEXT(nm) ) { |
nmv = BDY(mjj); len = LEN(mjj); |
u = nd_mul_nm_trunc(nm,mi[k],DL(BDY(d))); |
for ( a = 0; a < len; a++, NMV_ADV(nmv) ) { |
add_pbucket(0,bucket,u); |
u = ndv_mul_nmv_trunc(mod,nmv,mi[k],DL(BDY(d))); |
|
add_pbucket(mod,bucket,u); |
} |
} |
if ( mj[k] && mij ) { |
if ( mj[k] && mij ) { |
for ( nm = BDY(mij); nm; nm = NEXT(nm) ) { |
nmv = BDY(mij); len = LEN(mij); |
u = nd_mul_nm_trunc(nm,mj[k],DL(BDY(d))); |
for ( a = 0; a < len; a++, NMV_ADV(nmv) ) { |
add_pbucket(0,bucket,u); |
u = ndv_mul_nmv_trunc(mod,nmv,mj[k],DL(BDY(d))); |
|
add_pbucket(mod,bucket,u); |
} |
} |
} |
} |
s = normalize_pbucket(0,bucket); |
u = normalize_pbucket(mod,bucket); |
mi[k] = nd_quo(s,d); |
u = nd_quo(mod,u,d); |
|
mi[k] = ndtondv(mod,u); |
} |
} |
} |
} |
d = mjj; |
d = mjj; |
} |
} |
dv = ndtondv(0,d); |
if ( sgn < 0 ) |
*rp = ndvtop(0,CO,fv,dv); |
if ( mod ) |
|
ndv_mul_c(mod,d,mod-1); |
|
else |
|
ndv_mul_c_q(d,mone); |
|
*rp = ndvtop(mod,CO,fv,d); |
} |
} |
|
|
ND nd_mul_nm_trunc(NM m0,ND p,UINT *d) |
ND ndv_mul_nmv_trunc(int mod,NMV m0,NDV p,UINT *d) |
{ |
{ |
NM mr,mr0; |
NM mr,mr0; |
NM m,tnm; |
NM tnm; |
|
NMV m; |
UINT *d0,*dt,*dm; |
UINT *d0,*dt,*dm; |
int c,n,td,i,c1,c2,len; |
int c,n,td,i,c1,c2,len; |
Q q; |
Q q; |
Line 4740 ND nd_mul_nm_trunc(NM m0,ND p,UINT *d) |
|
Line 4780 ND nd_mul_nm_trunc(NM m0,ND p,UINT *d) |
|
|
|
if ( !p ) return 0; |
if ( !p ) return 0; |
else { |
else { |
n = NV(p); m = BDY(p); |
n = NV(p); m = BDY(p); len = LEN(p); |
d0 = DL(m0); |
d0 = DL(m0); |
len = LEN(p); |
|
mr0 = 0; |
|
td = TD(d); |
td = TD(d); |
q = CQ(m0); |
mr0 = 0; |
NEWNM(tnm); |
NEWNM(tnm); |
for ( ; m;m = NEXT(m) ) { |
if ( mod ) { |
ndl_add(DL(m),d0,DL(tnm)); |
c = CM(m0); |
if ( ndl_reducible(DL(tnm),d) ) { |
for ( i = 0; i < len; i++, NMV_ADV(m) ) { |
NEXTNM(mr0,mr); |
ndl_add(DL(m),d0,DL(tnm)); |
mulq(CQ(m),q,&CQ(mr)); |
if ( ndl_reducible(DL(tnm),d) ) { |
ndl_add(DL(m),d0,DL(mr)); |
NEXTNM(mr0,mr); |
|
c1 = CM(m); DMAR(c1,c,0,mod,c2); CM(mr) = c2; |
|
ndl_add(DL(m),d0,DL(mr)); |
|
} |
|
} |
|
} else { |
|
q = CQ(m0); |
|
for ( i = 0; i < len; i++, NMV_ADV(m) ) { |
|
ndl_add(DL(m),d0,DL(tnm)); |
|
if ( ndl_reducible(DL(tnm),d) ) { |
|
NEXTNM(mr0,mr); |
|
mulq(CQ(m),q,&CQ(mr)); |
|
ndl_add(DL(m),d0,DL(mr)); |
|
} |
} |
} |
} |
} |
if ( !mr0 ) |
if ( !mr0 ) |