version 1.7, 2020/01/09 01:47:40 |
version 1.8, 2020/10/06 06:31:19 |
|
|
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* |
* |
* $OpenXM: OpenXM_contrib2/asir2018/builtin/array.c,v 1.6 2019/12/13 14:40:49 fujimoto Exp $ |
* $OpenXM: OpenXM_contrib2/asir2018/builtin/array.c,v 1.7 2020/01/09 01:47:40 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "base.h" |
#include "base.h" |
Line 1543 void lu_dec_cr(MAT mat,MAT lu,Q *dn,int **perm) |
|
Line 1543 void lu_dec_cr(MAT mat,MAT lu,Q *dn,int **perm) |
|
|
|
int f4_nocheck; |
int f4_nocheck; |
|
|
#define ONE_STEP1 if ( zzz = *s ) { DMAR(zzz,hc,*tj,md,*tj) } tj++; s++; |
#define ONE_STEP1 if ( ( zzz = *s ) != 0 ) { DMAR(zzz,hc,*tj,md,*tj) } tj++; s++; |
|
|
void reduce_reducers_mod(int **mat,int row,int col,int md) |
void reduce_reducers_mod(int **mat,int row,int col,int md) |
{ |
{ |
Line 1559 void reduce_reducers_mod(int **mat,int row,int col,int |
|
Line 1559 void reduce_reducers_mod(int **mat,int row,int col,int |
|
ind[i] = j; |
ind[i] = j; |
for ( l = i-1; l >= 0; l-- ) { |
for ( l = i-1; l >= 0; l-- ) { |
/* reduce mat[i] by mat[l] */ |
/* reduce mat[i] by mat[l] */ |
if ( hc = t[ind[l]] ) { |
if ( ( hc = t[ind[l]] ) != 0 ) { |
/* mat[i] = mat[i]-hc*mat[l] */ |
/* mat[i] = mat[i]-hc*mat[l] */ |
j = ind[l]; |
j = ind[l]; |
s = mat[l]+j; |
s = mat[l]+j; |
Line 1585 void reduce_reducers_mod(int **mat,int row,int col,int |
|
Line 1585 void reduce_reducers_mod(int **mat,int row,int col,int |
|
ONE_STEP1 ONE_STEP1 ONE_STEP1 ONE_STEP1 |
ONE_STEP1 ONE_STEP1 ONE_STEP1 ONE_STEP1 |
} |
} |
for ( ; k > 0; k-- ) { |
for ( ; k > 0; k-- ) { |
if ( zzz = *s ) { DMAR(zzz,hc,*tj,md,*tj) } tj++; s++; |
if ( ( zzz = *s ) != 0 ) { DMAR(zzz,hc,*tj,md,*tj) } tj++; s++; |
} |
} |
} |
} |
} |
} |
Line 1620 void pre_reduce_mod(int **mat,int row,int col,int nred |
|
Line 1620 void pre_reduce_mod(int **mat,int row,int col,int nred |
|
DMAR(t[k],inv,0,md,t[k]) |
DMAR(t[k],inv,0,md,t[k]) |
for ( l = i-1; l >= 0; l-- ) { |
for ( l = i-1; l >= 0; l-- ) { |
/* reduce mat[i] by mat[l] */ |
/* reduce mat[i] by mat[l] */ |
if ( hc = t[ind[l]] ) { |
if ( ( hc = t[ind[l]] ) != 0 ) { |
/* mat[i] = mat[i]-hc*mat[l] */ |
/* mat[i] = mat[i]-hc*mat[l] */ |
for ( k = ind[l], hc = md-hc, s = mat[l]+k, tk = t+k; |
for ( k = ind[l], hc = md-hc, s = mat[l]+k, tk = t+k; |
k < col; k++, tk++, s++ ) |
k < col; k++, tk++, s++ ) |
Line 1634 void pre_reduce_mod(int **mat,int row,int col,int nred |
|
Line 1634 void pre_reduce_mod(int **mat,int row,int col,int nred |
|
t = mat[i]; |
t = mat[i]; |
for ( l = nred-1; l >= 0; l-- ) { |
for ( l = nred-1; l >= 0; l-- ) { |
/* reduce mat[i] by mat[l] */ |
/* reduce mat[i] by mat[l] */ |
if ( hc = t[ind[l]] ) { |
if ( ( hc = t[ind[l]] ) != 0 ) { |
/* mat[i] = mat[i]-hc*mat[l] */ |
/* mat[i] = mat[i]-hc*mat[l] */ |
for ( k = ind[l], hc = md-hc, s = mat[l]+k, tk = t+k; |
for ( k = ind[l], hc = md-hc, s = mat[l]+k, tk = t+k; |
k < col; k++, tk++, s++ ) |
k < col; k++, tk++, s++ ) |
Line 1658 void reduce_sp_by_red_mod(int *sp,int **redmat,int *in |
|
Line 1658 void reduce_sp_by_red_mod(int *sp,int **redmat,int *in |
|
/* reduce the spolys by redmat */ |
/* reduce the spolys by redmat */ |
for ( i = nred-1; i >= 0; i-- ) { |
for ( i = nred-1; i >= 0; i-- ) { |
/* reduce sp by redmat[i] */ |
/* reduce sp by redmat[i] */ |
if ( hc = sp[ind[i]] ) { |
if ( ( hc = sp[ind[i]] ) != 0 ) { |
/* sp = sp-hc*redmat[i] */ |
/* sp = sp-hc*redmat[i] */ |
j = ind[i]; |
j = ind[i]; |
hc = md-hc; |
hc = md-hc; |
s = redmat[i]+j; |
s = redmat[i]+j; |
tj = sp+j; |
tj = sp+j; |
for ( k = col-j; k > 0; k-- ) { |
for ( k = col-j; k > 0; k-- ) { |
if ( zzz = *s ) { DMAR(zzz,hc,*tj,md,*tj) } tj++; s++; |
if ( ( zzz = *s ) != 0 ) { DMAR(zzz,hc,*tj,md,*tj) } tj++; s++; |
} |
} |
} |
} |
} |
} |
Line 1763 int generic_gauss_elim_mod64(mp_limb_t **mat,int row,i |
|
Line 1763 int generic_gauss_elim_mod64(mp_limb_t **mat,int row,i |
|
*pk = mulmod64(*pk,inv,md); |
*pk = mulmod64(*pk,inv,md); |
for ( i = rank+1; i < row; i++ ) { |
for ( i = rank+1; i < row; i++ ) { |
t = mat[i]; |
t = mat[i]; |
if ( a = t[j] ) |
if ( ( a = t[j] ) != 0 ) |
red_by_vect64mod(md,t+j,pivot+j,md-a,col-j); |
red_by_vect64mod(md,t+j,pivot+j,md-a,col-j); |
} |
} |
rank++; |
rank++; |
Line 1773 int generic_gauss_elim_mod64(mp_limb_t **mat,int row,i |
|
Line 1773 int generic_gauss_elim_mod64(mp_limb_t **mat,int row,i |
|
pivot = mat[l]; |
pivot = mat[l]; |
for ( i = 0; i < l; i++ ) { |
for ( i = 0; i < l; i++ ) { |
t = mat[i]; |
t = mat[i]; |
if ( a = t[j] ) |
if ( ( a = t[j] ) != 0 ) |
red_by_vect64mod(md,t+j,pivot+j,md-a,col-j); |
red_by_vect64mod(md,t+j,pivot+j,md-a,col-j); |
} |
} |
l--; |
l--; |
Line 1944 void reduce_sp_by_red_mod_compress (int *sp,CDP *redma |
|
Line 1944 void reduce_sp_by_red_mod_compress (int *sp,CDP *redma |
|
for ( i = nred-1; i >= 0; i-- ) { |
for ( i = nred-1; i >= 0; i-- ) { |
/* reduce sp by redmat[i] */ |
/* reduce sp by redmat[i] */ |
usp[ind[i]] %= md; |
usp[ind[i]] %= md; |
if ( hc = usp[ind[i]] ) { |
if ( ( hc = usp[ind[i]] ) != 0 ) { |
/* sp = sp-hc*redmat[i] */ |
/* sp = sp-hc*redmat[i] */ |
hc = md-hc; |
hc = md-hc; |
ri = redmat[i]; |
ri = redmat[i]; |
Line 1990 int generic_gauss_elim_mod(int **mat0,int row,int col, |
|
Line 1990 int generic_gauss_elim_mod(int **mat0,int row,int col, |
|
} |
} |
for ( i = rank+1; i < row; i++ ) { |
for ( i = rank+1; i < row; i++ ) { |
t = mat[i]; |
t = mat[i]; |
if ( a = t[j] ) |
if ( ( a = t[j] ) != 0 ) |
red_by_vect(md,t+j,pivot+j,md-a,col-j); |
red_by_vect(md,t+j,pivot+j,md-a,col-j); |
} |
} |
rank++; |
rank++; |
Line 2001 int generic_gauss_elim_mod(int **mat0,int row,int col, |
|
Line 2001 int generic_gauss_elim_mod(int **mat0,int row,int col, |
|
for ( i = 0; i < l; i++ ) { |
for ( i = 0; i < l; i++ ) { |
t = mat[i]; |
t = mat[i]; |
t[j] %= md; |
t[j] %= md; |
if ( a = t[j] ) |
if ( ( a = t[j] ) != 0 ) |
red_by_vect(md,t+j,pivot+j,md-a,col-j); |
red_by_vect(md,t+j,pivot+j,md-a,col-j); |
} |
} |
l--; |
l--; |
Line 2050 int generic_gauss_elim_mod2(int **mat0,int row,int col |
|
Line 2050 int generic_gauss_elim_mod2(int **mat0,int row,int col |
|
} |
} |
for ( i = rank+1; i < row; i++ ) { |
for ( i = rank+1; i < row; i++ ) { |
t = mat[i]; |
t = mat[i]; |
if ( a = t[j] ) |
if ( ( a = t[j] ) != 0 ) |
red_by_vect(md,t+j,pivot+j,md-a,col-j); |
red_by_vect(md,t+j,pivot+j,md-a,col-j); |
} |
} |
rank++; |
rank++; |
Line 2061 int generic_gauss_elim_mod2(int **mat0,int row,int col |
|
Line 2061 int generic_gauss_elim_mod2(int **mat0,int row,int col |
|
for ( i = 0; i < l; i++ ) { |
for ( i = 0; i < l; i++ ) { |
t = mat[i]; |
t = mat[i]; |
t[j] %= md; |
t[j] %= md; |
if ( a = t[j] ) |
if ( ( a = t[j] ) != 0 ) |
red_by_vect(md,t+j,pivot+j,md-a,col-j); |
red_by_vect(md,t+j,pivot+j,md-a,col-j); |
} |
} |
l--; |
l--; |
Line 2106 int indep_rows_mod(int **mat0,int row,int col,int md,i |
|
Line 2106 int indep_rows_mod(int **mat0,int row,int col,int md,i |
|
} |
} |
for ( i = rank+1; i < row; i++ ) { |
for ( i = rank+1; i < row; i++ ) { |
t = mat[i]; |
t = mat[i]; |
if ( a = t[j] ) |
if ( ( a = t[j] ) != 0 ) |
red_by_vect(md,t+j,pivot+j,md-a,col-j); |
red_by_vect(md,t+j,pivot+j,md-a,col-j); |
} |
} |
rank++; |
rank++; |
Line 2140 int generic_gauss_elim_sf(int **mat0,int row,int col,i |
|
Line 2140 int generic_gauss_elim_sf(int **mat0,int row,int col,i |
|
*pk = _mulsf(*pk,inv); |
*pk = _mulsf(*pk,inv); |
for ( i = rank+1; i < row; i++ ) { |
for ( i = rank+1; i < row; i++ ) { |
t = mat[i]; |
t = mat[i]; |
if ( a = t[j] ) |
if ( ( a = t[j] ) != 0 ) |
red_by_vect_sf(md,t+j,pivot+j,_chsgnsf(a),col-j); |
red_by_vect_sf(md,t+j,pivot+j,_chsgnsf(a),col-j); |
} |
} |
rank++; |
rank++; |
Line 2150 int generic_gauss_elim_sf(int **mat0,int row,int col,i |
|
Line 2150 int generic_gauss_elim_sf(int **mat0,int row,int col,i |
|
pivot = mat[l]; |
pivot = mat[l]; |
for ( i = 0; i < l; i++ ) { |
for ( i = 0; i < l; i++ ) { |
t = mat[i]; |
t = mat[i]; |
if ( a = t[j] ) |
if ( ( a = t[j] ) != 0 ) |
red_by_vect_sf(md,t+j,pivot+j,_chsgnsf(a),col-j); |
red_by_vect_sf(md,t+j,pivot+j,_chsgnsf(a),col-j); |
} |
} |
l--; |
l--; |
Line 2186 int lu_gfmmat(GFMMAT mat,unsigned int md,int *perm) |
|
Line 2186 int lu_gfmmat(GFMMAT mat,unsigned int md,int *perm) |
|
pivot[k] = inv = invm(pivot[k],md); |
pivot[k] = inv = invm(pivot[k],md); |
for ( i = k+1; i < row; i++ ) { |
for ( i = k+1; i < row; i++ ) { |
t = a[i]; |
t = a[i]; |
if ( m = t[k] ) { |
if ( ( m = t[k] ) != 0 ) { |
DMAR(inv,m,0,md,t[k]) |
DMAR(inv,m,0,md,t[k]) |
for ( j = k+1, m = md - t[k]; j < col; j++ ) |
for ( j = k+1, m = md - t[k]; j < col; j++ ) |
if ( pivot[j] ) { |
if ( pivot[j] ) { |
Line 2242 int find_lhs_and_lu_mod(unsigned int **a,int row,int c |
|
Line 2242 int find_lhs_and_lu_mod(unsigned int **a,int row,int c |
|
pivot[k] = inv = invm(pivot[k],md); |
pivot[k] = inv = invm(pivot[k],md); |
for ( i = d+1; i < row; i++ ) { |
for ( i = d+1; i < row; i++ ) { |
t = a[i]; |
t = a[i]; |
if ( m = t[k] ) { |
if ( ( m = t[k] ) != 0 ) { |
DMAR(inv,m,0,md,t[k]) |
DMAR(inv,m,0,md,t[k]) |
for ( j = k+1, m = md - t[k]; j < col; j++ ) |
for ( j = k+1, m = md - t[k]; j < col; j++ ) |
if ( pivot[j] ) { |
if ( pivot[j] ) { |
Line 2277 int lu_mod(unsigned int **a,int n,unsigned int md,int |
|
Line 2277 int lu_mod(unsigned int **a,int n,unsigned int md,int |
|
inv = invm(pivot[k],md); |
inv = invm(pivot[k],md); |
for ( i = k+1; i < n; i++ ) { |
for ( i = k+1; i < n; i++ ) { |
t = a[i]; |
t = a[i]; |
if ( m = t[k] ) { |
if ( ( m = t[k] ) != 0 ) { |
DMAR(inv,m,0,md,t[k]) |
DMAR(inv,m,0,md,t[k]) |
for ( j = k+1, m = md - t[k]; j < n; j++ ) |
for ( j = k+1, m = md - t[k]; j < n; j++ ) |
if ( pivot[j] ) { |
if ( pivot[j] ) { |
Line 2306 void solve_by_lu_mod(int **a,int n,int md,int **b,int |
|
Line 2306 void solve_by_lu_mod(int **a,int n,int md,int **b,int |
|
int i,j,k; |
int i,j,k; |
unsigned int t,m,m2; |
unsigned int t,m,m2; |
|
|
y = (int *)MALLOC_ATOMIC(n*sizeof(int)); |
y = (unsigned int *)MALLOC_ATOMIC(n*sizeof(int)); |
c = (int *)MALLOC_ATOMIC(n*sizeof(int)); |
c = (unsigned int *)MALLOC_ATOMIC(n*sizeof(int)); |
m2 = md>>1; |
m2 = md>>1; |
for ( k = 0; k < l; k++ ) { |
for ( k = 0; k < l; k++ ) { |
/* copy b[.][k] to c */ |
/* copy b[.][k] to c */ |
Line 2467 int gauss_elim_geninv_mod(unsigned int **mat,int row,i |
|
Line 2467 int gauss_elim_geninv_mod(unsigned int **mat,int row,i |
|
pivot[k] = dmar(pivot[k],inv,0,md); |
pivot[k] = dmar(pivot[k],inv,0,md); |
for ( i = j+1; i < row; i++ ) { |
for ( i = j+1; i < row; i++ ) { |
t = mat[i]; |
t = mat[i]; |
if ( a = t[j] ) |
if ( ( a = t[j] ) != 0 ) |
for ( k = j, a = md - a; k < m; k++ ) |
for ( k = j, a = md - a; k < m; k++ ) |
t[k] = dmar(pivot[k],a,t[k],md); |
t[k] = dmar(pivot[k],a,t[k],md); |
} |
} |
Line 2476 int gauss_elim_geninv_mod(unsigned int **mat,int row,i |
|
Line 2476 int gauss_elim_geninv_mod(unsigned int **mat,int row,i |
|
pivot = mat[j]; |
pivot = mat[j]; |
for ( i = j-1; i >= 0; i-- ) { |
for ( i = j-1; i >= 0; i-- ) { |
t = mat[i]; |
t = mat[i]; |
if ( a = t[j] ) |
if ( ( a = t[j] ) != 0 ) |
for ( k = j, a = md - a; k < m; k++ ) |
for ( k = j, a = md - a; k < m; k++ ) |
t[k] = dmar(pivot[k],a,t[k],md); |
t[k] = dmar(pivot[k],a,t[k],md); |
} |
} |
Line 2694 int gauss_elim_geninv_mod_swap(unsigned int **mat,int |
|
Line 2694 int gauss_elim_geninv_mod_swap(unsigned int **mat,int |
|
pivot[k] = (unsigned int)dmar(pivot[k],inv,0,md); |
pivot[k] = (unsigned int)dmar(pivot[k],inv,0,md); |
for ( i = j+1; i < row; i++ ) { |
for ( i = j+1; i < row; i++ ) { |
t = mat[i]; |
t = mat[i]; |
if ( a = t[j] ) |
if ( ( a = t[j] ) != 0 ) |
for ( k = j, a = md - a; k < m; k++ ) |
for ( k = j, a = md - a; k < m; k++ ) |
if ( pivot[k] ) |
if ( pivot[k] ) |
t[k] = dmar(pivot[k],a,t[k],md); |
t[k] = dmar(pivot[k],a,t[k],md); |
Line 2704 int gauss_elim_geninv_mod_swap(unsigned int **mat,int |
|
Line 2704 int gauss_elim_geninv_mod_swap(unsigned int **mat,int |
|
pivot = mat[j]; |
pivot = mat[j]; |
for ( i = j-1; i >= 0; i-- ) { |
for ( i = j-1; i >= 0; i-- ) { |
t = mat[i]; |
t = mat[i]; |
if ( a = t[j] ) |
if ( ( a = t[j] ) != 0 ) |
for ( k = j, a = md - a; k < m; k++ ) |
for ( k = j, a = md - a; k < m; k++ ) |
if ( pivot[k] ) |
if ( pivot[k] ) |
t[k] = dmar(pivot[k],a,t[k],md); |
t[k] = dmar(pivot[k],a,t[k],md); |
Line 2740 void Pgeninv_sf_swap(NODE arg,LIST *rp) |
|
Line 2740 void Pgeninv_sf_swap(NODE arg,LIST *rp) |
|
for ( i = 0; i < row; i++ ) { |
for ( i = 0; i < row; i++ ) { |
bzero((char *)wmat[i],(col+row)*sizeof(int)); |
bzero((char *)wmat[i],(col+row)*sizeof(int)); |
for ( j = 0; j < col; j++ ) |
for ( j = 0; j < col; j++ ) |
if ( q = (GFS)mat[i][j] ) |
if ( ( q = (GFS)mat[i][j] ) != 0 ) |
wmat[i][j] = FTOIF(CONT(q)); |
wmat[i][j] = FTOIF(CONT(q)); |
wmat[i][col+i] = _onesf(); |
wmat[i][col+i] = _onesf(); |
} |
} |
Line 2751 void Pgeninv_sf_swap(NODE arg,LIST *rp) |
|
Line 2751 void Pgeninv_sf_swap(NODE arg,LIST *rp) |
|
MKMAT(mat1,col,col); |
MKMAT(mat1,col,col); |
for ( i = 0, tmat = (GFS **)mat1->body; i < col; i++ ) |
for ( i = 0, tmat = (GFS **)mat1->body; i < col; i++ ) |
for ( j = 0; j < col; j++ ) |
for ( j = 0; j < col; j++ ) |
if ( t = invmat[i][j] ) { |
if ( ( t = invmat[i][j] ) != 0 ) { |
MKGFS(IFTOF(t),tmat[i][j]); |
MKGFS(IFTOF(t),tmat[i][j]); |
} |
} |
MKVECT(vect1,row); |
MKVECT(vect1,row); |
Line 2788 int gauss_elim_geninv_sf_swap(int **mat,int row,int co |
|
Line 2788 int gauss_elim_geninv_sf_swap(int **mat,int row,int co |
|
pivot[k] = _mulsf(pivot[k],inv); |
pivot[k] = _mulsf(pivot[k],inv); |
for ( i = j+1; i < row; i++ ) { |
for ( i = j+1; i < row; i++ ) { |
t = mat[i]; |
t = mat[i]; |
if ( a = t[j] ) |
if ( ( a = t[j] ) != 0 ) |
for ( k = j, a = _chsgnsf(a); k < m; k++ ) |
for ( k = j, a = _chsgnsf(a); k < m; k++ ) |
if ( pivot[k] ) { |
if ( pivot[k] ) { |
u = _mulsf(pivot[k],a); |
u = _mulsf(pivot[k],a); |
Line 2800 int gauss_elim_geninv_sf_swap(int **mat,int row,int co |
|
Line 2800 int gauss_elim_geninv_sf_swap(int **mat,int row,int co |
|
pivot = mat[j]; |
pivot = mat[j]; |
for ( i = j-1; i >= 0; i-- ) { |
for ( i = j-1; i >= 0; i-- ) { |
t = mat[i]; |
t = mat[i]; |
if ( a = t[j] ) |
if ( ( a = t[j] ) != 0 ) |
for ( k = j, a = _chsgnsf(a); k < m; k++ ) |
for ( k = j, a = _chsgnsf(a); k < m; k++ ) |
if ( pivot[k] ) { |
if ( pivot[k] ) { |
u = _mulsf(pivot[k],a); |
u = _mulsf(pivot[k],a); |
Line 2973 int generate_ONB_polynomial(UP2 *rp,int m,int type) |
|
Line 2973 int generate_ONB_polynomial(UP2 *rp,int m,int type) |
|
for ( i = 0; i < w; i++ ) |
for ( i = 0; i < w; i++ ) |
f->b[i] = 0xffffffff; |
f->b[i] = 0xffffffff; |
/* mask the top word if necessary */ |
/* mask the top word if necessary */ |
if ( r = (m+1)&31 ) |
if ( ( r = (m+1)&31 ) != 0 ) |
f->b[w-1] &= (1<<r)-1; |
f->b[w-1] &= (1<<r)-1; |
return 0; |
return 0; |
break; |
break; |