void evaluateTwoLayerPerceptron(void) { double hiddenInput[numberofHiddenUnits]; double hiddenOutput[numberofHiddenUnits]; double finalInput[outputDimension]; matrixmul(hiddenWeights,inputVector,hiddenInput,numberofHiddenUnits,inputDimension,1); activationfunction(hiddenInput,hiddenOutput,numberofHiddenUnits); matrixmul(outputWeights,hiddenOutput,finalInput,outputDimension,numberofHiddenUnits,1); activationfunction(finalInput,outputVector,outputDimension); }
void matrixpower(long long int a[2][2],int n,int m) { if(n==0 || n==1) return; long long int x[2][2]={{1,1},{1,0}}; matrixpower(a,n/2,m); matrixmul(a,a,m); if(n%2==1) matrixmul(a,x,m); return; }
/* Used to create the rotation matrix. Matrix could be taken from for example .DXF files directly (3D Studio animations include matrix for each frame! */ void creatematrix(matrix dest, matrix imatrix, signed long frame) { matrix tmatrix; // create xy-axis rotation matrix matrix_make(tmatrix,imatrix); tmatrix[0]=cosi[frame]; // y-angle tmatrix[2]=-sini[frame]; // ya tmatrix[4]=sini[frame]*sini[frame] >> 8; // ya*xa tmatrix[5]=cosi[frame]; // xa tmatrix[6]=sini[frame]*cosi[frame] >> 8; //sx*cy tmatrix[8]=cosi[frame]*sini[frame] >> 8; // cx*sy tmatrix[9]=-sini[frame]; // -sx tmatrix[10]=cosi[frame]*cosi[frame] >> 8; //cx*cy matrixmul(dest,imatrix,tmatrix); dest[14]=140; }
int main() { int test,i; ans =malloc(2*sizeof(unsigned long int*)); for(i=0;i<2;i++) { ans[i]=malloc(2*sizeof(unsigned long int)); } ans[0][0]=2; ans[0][1]=1; ans[1][0]=3; ans[1][1]=0; temp=malloc(2*sizeof(unsigned long int*)); for(i=0;i<2;i++) { temp[i]=malloc(2*sizeof(unsigned long int)); } temp[0][0]=24; temp[0][1]=12; temp[1][0]=12; temp[1][1]=0; /*temp=power(10); printf("%lu ",temp[0][0]); printf("%lu ",temp[0][1]); printf("%lu ",temp[1][0]); printf("%lu ",temp[1][1]);*/ unsigned long int n; scanf("%d",&test); for(i=0;i<test;i++) { scanf("%lu",&n); if(n==2) printf("12\n"); else if(n==3) printf("24\n"); else{ ans=power(n-3); matrixmul(temp,ans); printf("%lu\n",(t[0][0]%(1000000000+7))); } } return 0; }
int main(int argc, char *argv[]) { int workers = 1; int dqsize = 100000; int verify = 0; char c; while ((c=getopt(argc, argv, "w:q:h:c")) != -1) { switch (c) { case 'w': workers = atoi(optarg); break; case 'q': dqsize = atoi(optarg); break; case 'c': verify = 1; break; case 'h': usage(argv[0]); break; default: abort(); } } if (optind == argc) { usage(argv[0]); exit(1); } int n = atoi(argv[optind]); lace_init(workers, dqsize); lace_startup(0, 0, 0); REAL *A, *B, *C1, *C2; if ((n & (n - 1)) != 0 || (n % 16) != 0) { printf("%d: matrix size must be a power of 2" " and a multiple of %d\n", n, 16); return 1; } A = alloc_matrix(n); B = alloc_matrix(n); C1 = alloc_matrix(n); C2 = alloc_matrix(n); init_matrix(n, A, n); init_matrix(n, B, n); LACE_ME; double t1=wctime(); CALL(OptimizedStrassenMultiply, C2, A, B, n, n, n, n); double t2=wctime(); if (verify) { matrixmul(n, A, n, B, n, C1, n); verify = compare_matrix(n, C1, n, C2, n); } if (verify) printf("WRONG RESULT!\n"); else { printf("Time: %f\n", t2-t1); } lace_exit(); return 0; }
int linearprogram(double a[],double b[],double c[],int m,int n,double x[]) { int i,k,j,*js; double s,z,dd,y,*p,*d; RM ma={m,m+n,a},mp,md; js=malloc(m*sizeof(int)); p=malloc(m*m*sizeof(double)); d=malloc(m*(m+n)*sizeof(double)); mp.row=mp.col=m;mp.data=p; md.data=d; for(i=0;i<m;i++) { js[i]=n+i; } s=0.0; while(1) { for(i=0;i<m;i++) for(j=0;j<m;j++) p[i*m+j]=a[i*(m+n)+js[j]]; if(matrix_inverse(&mp)!=0) { x[n]=s; free(js);free(p);free(d); return 0; } matrixmul(&mp,&ma,&md); for(i=0;i<m+n;i++) { x[i]=0.0; } for(i=0;i<m;i++) { for(j=0,s=0.0;j<m;j++) s+=p[i*m+j]*b[j]; x[js[i]]=s; } k=-1;dd=1.0e-35; for(j=0;j<m+n;j++) { for(i=0,z=0.0;i<m;i++) z+=c[js[i]]*d[i*(m+n)+j]; z-=c[j]; if(z>dd){dd=z;k=j;} } if(k==-1) { for(j=0,s=0.0;j<n;j++) s+=c[j]*x[j]; x[n]=s; free(js);free(p);free(d); return 1; } j=-1; dd=1.0e+20; for(i=0;i<m;i++) if(d[i*(m+n)+k]>=1.0e-20) { y=x[js[i]]/d[i*(m+n)+k]; if(y<dd){dd=y;j=i;} } if(j==-1) { x[n]=s; free(js);free(p);free(d); return 0; } js[j]=k; } }