7 void MtxuntDouble( double **mtx, int n )
10 for( i=0; i<n; i++ ) for( j=0; j<n; j++ ) mtx[i][j] = 0.0;
11 for( i=0; i<n; i++ ) mtx[i][i] = 1.0;
14 void MtxmltDouble( double **mtx1, double **mtx2, int n )
19 tmp = (double *)calloc( n, sizeof( double ) );
22 for( k=0; k<n; k++ ) tmp[k] = mtx1[i][k];
26 for( k=0; k<n; k++ ) s += tmp[k] * mtx2[k][j];
33 char *AllocateCharVec( int l1 )
37 cvec = (char *)calloc( l1, sizeof( char ) );
40 fprintf( stderr, "Cannot allocate %d character vector.\n", l1 );
47 void ReallocateCharMtx( char **mtx, int l1, int l2 )
50 char *bk = (char *)malloc( l2+1 ); // hontou ha iranai
53 fprintf( stderr, "Cannot allocate bk in ReallocateCharMtx\n" );
60 mtx[i] = (char *)realloc( mtx[i], (l2+1) * sizeof( char ) );
63 fprintf( stderr, "Cannot reallocate %d x %d character matrix.\n", l1, l2 );
65 if( strcmp( bk, mtx[i] ) ) // hontou ha iranai
67 fprintf( stderr, "changed!! \n%s\n \nto\n%s\n in realloc..\n", bk, mtx[i] );
73 mtx[i] = (char *)calloc( (l2+1), sizeof( char ) );
77 free( bk ); // hontou ha iranai
80 void ReallocateCharMtx( char **mtx, int l1, int l2 )
85 mtx[i] = (char *)realloc( mtx[i], (l2+1) * sizeof( char ) );
88 fprintf( stderr, "Cannot reallocate %d x %d character matrix.\n", l1, l2 );
94 char **AllocateCharMtx( int l1, int l2 )
99 cmtx = (char **)calloc( l1+1, sizeof( char * ) );
102 fprintf( stderr, "Cannot allocate %d x %d character matrix.\n", l1, l2 );
107 for( i=0; i<l1; i++ )
109 cmtx[i] = AllocateCharVec( l2 );
116 void FreeCharMtx( char **mtx )
121 while( *x != NULL ) free( *x++ );
125 for( i=0; mtx[i]; i++ )
132 float *AllocateFloatVec( int l1 )
136 vec = (float *)calloc( (unsigned int)l1, sizeof( float ) );
139 fprintf( stderr, "Allocation error ( %d fload vec )\n", l1 );
145 void FreeFloatVec( float *vec )
150 float **AllocateFloatHalfMtx( int ll1 )
155 mtx = (float **)calloc( (unsigned int)ll1+1, sizeof( float * ) );
158 fprintf( stderr, "Allocation error ( %d fload halfmtx )\n", ll1 );
161 for( i=0; i<ll1; i++ )
163 mtx[i] = (float *)calloc( ll1-i, sizeof( float ) );
166 fprintf( stderr, "Allocation error( %d floathalfmtx )\n", ll1 );
174 float **AllocateFloatMtx( int ll1, int ll2 )
179 mtx = (float **)calloc( (unsigned int)ll1+1, sizeof( float * ) );
182 fprintf( stderr, "Allocation error ( %d x %d fload mtx )\n", ll1, ll2 );
187 for( i=0; i<ll1; i++ )
189 mtx[i] = (float *)calloc( ll2, sizeof( float ) );
192 fprintf( stderr, "Allocation error( %d x %d floatmtx )\n", ll1, ll2 );
201 void FreeFloatHalfMtx( float **mtx, int n )
207 if( mtx[i] ) FreeFloatVec( mtx[i] );
211 void FreeFloatMtx( float **mtx )
215 for( i=0; mtx[i]; i++ )
217 FreeFloatVec( mtx[i] );
222 int *AllocateIntVec( int ll1 )
226 vec = (int *)calloc( ll1, sizeof( int ) );
229 fprintf( stderr, "Allocation error( %d int vec )\n", ll1 );
235 void FreeIntVec( int *vec )
240 float **AllocateFloatTri( int ll1 )
245 tri = (float **)calloc( (unsigned int)ll1+1, sizeof( float * ) );
248 fprintf( stderr, "Allocation error ( float tri )\n" );
251 for( i=0; i<ll1; i++ )
253 tri[i] = AllocateFloatVec( i+3 );
260 void FreeFloatTri( float **tri )
265 while( *tri != NULL ) free( *tri++ );
269 for( i=0; tri[i]; i++ )
274 int **AllocateIntMtx( int ll1, int ll2 )
279 mtx = (int **)calloc( ll1+1, sizeof( int * ) );
282 fprintf( stderr, "Allocation error( %d x %d int mtx )\n", ll1, ll2 );
287 for( i=0; i<ll1; i++ )
289 mtx[i] = AllocateIntVec( ll2 );
297 void FreeIntMtx( int **mtx )
302 while( !*mtx ) free( *mtx++ );
306 for( i=0; mtx[i] != NULL; i++ )
307 free( (char *)mtx[i] );
312 char ***AllocateCharCub( int ll1, int ll2, int ll3 )
317 cub = (char ***)calloc( ll1+1, sizeof( char ** ) );
320 fprintf( stderr, "Allocation error( %d x %d x %d char cube\n", ll1, ll2, ll3 );
325 for( i=0; i<ll1; i++ )
327 cub[i] = AllocateCharMtx( ll2, ll3 );
334 void FreeCharCub( char ***cub )
338 for( i=0; cub[i]; i++ )
340 FreeCharMtx( cub[i] );
345 void freeintmtx( int **mtx, int ll1, int ll2 )
349 for( i=0; i<ll1; i++ )
350 free( (char *)mtx[i] );
354 void FreeIntMtx( int **mtx )
358 for( i=0; mtx[i]; i++ )
359 free( (char *)mtx[i] );
363 char ****AllocateCharHcu( int ll1, int ll2, int ll3, int ll4 )
368 hcu = (char ****)calloc( ll1+1, sizeof( char *** ) );
369 if( hcu == NULL ) exit( 1 );
370 for( i=0; i<ll1; i++ )
371 hcu[i] = AllocateCharCub( ll2, ll3, ll4 );
376 void FreeCharHcu( char ****hcu )
379 for( i=0; hcu[i]; i++ )
381 FreeCharCub( hcu[i] );
383 free ( (char *)hcu );
386 double *AllocateDoubleVec( int ll1 )
390 vec = (double *)calloc( ll1, sizeof( double ) );
394 void FreeDoubleVec( double *vec )
399 int ***AllocateIntCub( int ll1, int ll2, int ll3 )
404 cub = (int ***)calloc( ll1+1, sizeof( int ** ) );
407 fprintf( stderr, "cannot allocate IntCub\n" );
410 for( i=0; i<ll1; i++ )
411 cub[i] = AllocateIntMtx( ll2, ll3 );
417 void FreeIntCub( int ***cub )
420 for( i=0; cub[i]; i++ )
422 FreeIntMtx( cub[i] );
427 double **AllocateDoubleMtx( int ll1, int ll2 )
431 mtx = (double **)calloc( ll1+1, sizeof( double * ) );
434 fprintf( stderr, "cannot allocate DoubleMtx\n" );
439 for( i=0; i<ll1; i++ )
440 mtx[i] = AllocateDoubleVec( ll2 );
447 void FreeDoubleMtx( double **mtx )
450 for( i=0; mtx[i]; i++ )
451 FreeDoubleVec( mtx[i] );
455 float ***AllocateFloatCub( int ll1, int ll2, int ll3 )
460 cub = (float ***)calloc( ll1+1, sizeof( float ** ) );
463 fprintf( stderr, "cannot allocate float cube.\n" );
466 for( i=0; i<ll1; i++ )
468 cub[i] = AllocateFloatMtx( ll2, ll3 );
474 void FreeFloatCub( float ***cub )
478 for( i=0; cub[i]; i++ )
480 FreeFloatMtx( cub[i] );
485 double ***AllocateDoubleCub( int ll1, int ll2, int ll3 )
490 cub = (double ***)calloc( ll1+1, sizeof( double ** ) );
493 fprintf( stderr, "cannot allocate double cube.\n" );
496 for( i=0; i<ll1; i++ )
498 cub[i] = AllocateDoubleMtx( ll2, ll3 );
504 void FreeDoubleCub( double ***cub )
508 for( i=0; cub[i]; i++ )
510 FreeDoubleMtx( cub[i] );
516 short *AllocateShortVec( int ll1 )
520 vec = (short *)calloc( ll1, sizeof( short ) );
523 fprintf( stderr, "Allocation error( %d short vec )\n", ll1 );
529 void FreeShortVec( short *vec )
534 short **AllocateShortMtx( int ll1, int ll2 )
540 mtx = (short **)calloc( ll1+1, sizeof( short * ) );
543 fprintf( stderr, "Allocation error( %d x %d short mtx ) \n", ll1, ll2 );
546 for( i=0; i<ll1; i++ )
548 mtx[i] = AllocateShortVec( ll2 );
554 void FreeShortMtx( short **mtx )
558 for( i=0; mtx[i]; i++ )
559 free( (char *)mtx[i] );